public function addItem(Mage_Sales_Model_Quote_Address_Item $item) { $item->setAddress($this)->setParentId($this->getId()); if (!$item->getId()) { $this->getItemsCollection()->addItem($item); } return $this; }
/** * @return $this */ public function collectRates() { $allowed_carriers = $this->getAllowedCarriers(); $this->_rates = array(); $ter = $this->getConfig()->getShippingTerritory($this->getStoreId()); if (empty($ter)) { return $this; } $only_minimum = $this->getConfig()->getConfigVar('only_minimum', $this->getStoreId(), 'shipping'); $only_free_shipping = $this->getConfig()->getConfigVar('only_free_shipping', $this->getStoreId(), 'shipping'); if (!empty($allowed_carriers)) { foreach ($ter as $country_id => $regions) { if (is_array($regions) && count($regions) > 0) { foreach ($regions as $region_id => $region_code) { $result = array(); $quote = clone $this->_getQuoteModel(); $address = clone $this->_getAddressModel(); $address->setQuote($quote); $this->_item->setAddress($address); $this->_item->calcRowTotal(); $request = $this->setRequest($this->_item, $allowed_carriers, $address, $country_id, $region_id); $shipping = clone $this->_getShippingModel(); $shipping->collectRates($request); $result = $shipping->getResult(); if ($only_minimum) { $result->sortRatesByPrice(); } $result = $result->asArray(); if (empty($result)) { continue; } if ($only_minimum && is_array($result)) { reset($result); $result = array(key($result) => current($result)); } if ($only_free_shipping) { $result = $this->filterFreeShipping($result); } $this->_rates[$country_id][$region_code] = $result; } } else { $result = array(); $quote = clone $this->_getQuoteModel(); $address = clone $this->_getAddressModel(); $address->setQuote($quote); $this->_item->setAddress($address); $this->_item->calcRowTotal(); $request = $this->setRequest($this->_item, $allowed_carriers, $address, $country_id, null); $shipping = clone $this->_getShippingModel(); $shipping->collectRates($request); $result = $shipping->getResult(); if ($only_minimum) { $result->sortRatesByPrice(); } $result = $result->asArray(); if (empty($result)) { continue; } if ($only_minimum && is_array($result)) { reset($result); $result = array(key($result) => current($result)); } if ($only_free_shipping) { $result = $this->filterFreeShipping($result); } $this->_rates[$country_id]["*"] = $result; } } } return $this; }