/** * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(-1)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); // ============ Apply shipping on order minimum value after discount specific to coupon code only ================= if (!Mage::app()->getStore()->isAdmin()) { foreach ($shippingRates as $i => $r) { if ($r->getMethod() == 'freeshipping') { unset($shippingRates[$i]); } } } $isfree = true; $minimum_purchange_amount = Mage::getStoreConfig('sales/minimum_order_custom/minimum_purchange_amount'); $minimum_purchange_amount_status = Mage::getStoreConfig('sales/minimum_order_custom/minimum_purchange_amount_status'); if ($minimum_purchange_amount_status == '1' && $minimum_purchange_amount > 0) { $minPurchaseAmt = Mage::helper('common')->checkMinPurchageAmount($minimum_purchange_amount); if ($minPurchaseAmt) { foreach ($shippingRates as $i => $r) { if ($r->getMethod() == 'standard') { $shippingRates[$i]->setPrice(0); $shippingRates[$i]->setCost(0); $isfree = true; } } } } // ========================================================================================== foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { if ($item) { $item->setBaseShippingAmount($rate->getPrice()); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($rate->getPrice()); } $found = true; } } } return $found; }
/** * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { //Mage::log("requestShippingRates"); /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(-1)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $result = Mage::getModel('shipping/shipping')->collectRatesWithAddress($request, $this)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { if ($item) { $item->setBaseShippingAmount($rate->getPrice()); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($rate->getPrice()); } $found = true; } } } return $found; }
/** * WE NEEDED TO OVERRIDE THIS METHOD CALL TO UPDATE THE SHIPPING RATES AS * SOON AS WE RECEIVED THEM * * * * * Request shipping rates for entire address or specified address item * Returns true if current selected shipping method code corresponds to one of the found rates * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return bool */ public function requestShippingRates(Mage_Sales_Model_Quote_Item_Abstract $item = null) { /** * CUSTOMIZED THIS FUNCTION BY ADDING THIS EVENT CALL */ if (!$this->getQuote()->getShippingAddress()->getResidentialIndicator()) { Mage::dispatchEvent('widgetized_validate_address', array($this->_eventObject => $this, 'order' => $this->getQuote())); } /** @var $request Mage_Shipping_Model_Rate_Request */ $request = Mage::getModel('shipping/rate_request'); $request->setQuote($this->getQuote()); $request->setAllItems($item ? array($item) : $this->getAllItems()); $request->setDestCountryId($this->getCountryId()); $request->setDestRegionId($this->getRegionId()); $request->setDestRegionCode($this->getRegionCode()); /** * need to call getStreet with -1 * to get data in string instead of array */ $request->setDestStreet($this->getStreet(self::DEFAULT_DEST_STREET)); $request->setDestCity($this->getCity()); $request->setDestPostcode($this->getPostcode()); $request->setPackageValue($item ? $item->getBaseRowTotal() : $this->getBaseSubtotal()); $packageValueWithDiscount = $item ? $item->getBaseRowTotal() - $item->getBaseDiscountAmount() : $this->getBaseSubtotalWithDiscount(); $request->setPackageValueWithDiscount($packageValueWithDiscount); $request->setPackageWeight($item ? $item->getRowWeight() : $this->getWeight()); $request->setPackageQty($item ? $item->getQty() : $this->getItemQty()); /** * Need for shipping methods that use insurance based on price of physical products */ $packagePhysicalValue = $item ? $item->getBaseRowTotal() : $this->getBaseSubtotal() - $this->getBaseVirtualAmount(); $request->setPackagePhysicalValue($packagePhysicalValue); $request->setFreeMethodWeight($item ? 0 : $this->getFreeMethodWeight()); /** * Store and website identifiers need specify from quote */ /*$request->setStoreId(Mage::app()->getStore()->getId()); $request->setWebsiteId(Mage::app()->getStore()->getWebsiteId());*/ $request->setStoreId($this->getQuote()->getStore()->getId()); $request->setWebsiteId($this->getQuote()->getStore()->getWebsiteId()); $request->setFreeShipping($this->getFreeShipping()); /** * Currencies need to convert in free shipping */ $request->setBaseCurrency($this->getQuote()->getStore()->getBaseCurrency()); $request->setPackageCurrency($this->getQuote()->getStore()->getCurrentCurrency()); $request->setLimitCarrier($this->getLimitCarrier()); $request->setBaseSubtotalInclTax($this->getBaseSubtotalInclTax() + $this->getBaseExtraTaxAmount()); $result = Mage::getModel('shipping/shipping')->collectRates($request)->getResult(); $found = false; if ($result) { $shippingRates = $result->getAllRates(); // var_dump($shippingRates);die; /** * CUSTOMIZED THIS FUNCTION BY ADDING THIS EVENT CALL */ Mage::dispatchEvent($this->_eventPrefix . '_update_shipping_rates', array($this->_eventObject => $this, 'shipping_rates' => $shippingRates)); foreach ($shippingRates as $shippingRate) { $rate = Mage::getModel('sales/quote_address_rate')->importShippingRate($shippingRate); /** * COST is Cheaper than the PRICE * * We don't want to use the price, we want to give shipping * to users at cost. */ if (!$item) { $this->addShippingRate($rate); } if ($this->getShippingMethod() == $rate->getCode()) { $price = $rate->getCost(); if (!$price) { $price = $rate->getPrice(); } if ($item) { $item->setBaseShippingAmount($price); } else { /** * possible bug: this should be setBaseShippingAmount(), * see Mage_Sales_Model_Quote_Address_Total_Shipping::collect() * where this value is set again from the current specified rate price * (looks like a workaround for this bug) */ $this->setShippingAmount($price); } $found = true; } } } return $found; }