_configPath . $key); } protected function _getDefaultCurrencyCode() { return 'UAH'; } public function collectRates(Mage_Shipping_Model_Rate_Request $request) { if (!$this->getConfigFlag('active')) { return false; } $result = Mage::getModel('shipping/rate_result'); if ('UA' !== $request->getDestCountryId()) { $helper = Mage::helper('orange35_shipping'); $cartPrice = 0; foreach (Mage::getModel('checkout/cart')->getItems() as $item) { $cartPrice += $item->getPrice() * $item->getQty(); } /** @var Orange35_Shipping_Model_Country $countryData */ $countryData = $helper->getCountryPrices($request->getDestCountryId()); if (null === $countryData->getAdditionPrice()) { $countryData->setAdditionPrice($helper->getDefaultAdditionPrice()); } if (null === $countryData->getPercent()) { $countryData->setPercent($helper->getDefaultAdditionPercent()); } $additionPrice = $countryData->getData('addition_price'); $finalPrice = $additionPrice + $cartPrice * (int) trim($countryData->getData('percent')) / 100; file_put_contents('test.dat', $additionPrice . ' ' . $cartPrice . ' ' . $finalPrice); $title = Mage::getStoreConfig('carriers/orange35_shipping/title'); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setMethod('orange35_shipping_country'); $method->setMethodTitle($title); $method->setPrice($finalPrice); $method->setCost($finalPrice); $result->append($method); } else if ($this->_getConfig('active')) { $quote = Mage::helper('checkout/cart')->getQuote(); $totals = $quote->getTotals(); $freeFromTotal = Mage::helper('directory')->currencyConvert( (int) $this->_getConfig('free-from-price'), $this->_getDefaultCurrencyCode(), Mage::app()->getStore()->getCurrentCurrencyCode() ); $isFree = $freeFromTotal <= $totals['subtotal']->getValue(); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setMethod('orange35_shipping_new_post'); $method->setMethodTitle($this->_getConfig('title-new-post')); $cartPrice = $isFree ? 0 : (int) $this->_getConfig('price-new-post'); $method->setCost($cartPrice); $method->setPrice($cartPrice); $result->append($method); $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setMethod('orange35_shipping_ukr_post'); $method->setMethodTitle($this->_getConfig('title-ukr-post')); $cartPrice = $isFree ? 0 : (int) $this->_getConfig('price-ukr-post'); $method->setCost($cartPrice); $method->setPrice($cartPrice); $result->append($method); } $method = Mage::getModel('shipping/rate_result_method'); $method->setCarrier($this->_code); $method->setMethod('orange35_shipping_by_appointment'); $method->setMethodTitle($this->_getConfig('title-by-appointment')); $method->setCost(0); $method->setPrice(0); $result->append($method); return $result; } public function getAllowedMethods() { return array('orange35_shipping' => $this->getConfigData('name')); } }