/** * @param Cart $cart * @param $areaId * @return |null */ protected function getSlicePostage(Cart $cart, Country $country) { $config = self::getConfig(); $currency = $cart->getCurrency(); $areaId = $country->getAreaId(); $query = CustomDeliverySliceQuery::create()->filterByAreaId($areaId); if ($config['method'] != CustomDelivery::METHOD_PRICE) { $query->filterByWeightMax($cart->getWeight(), Criteria::GREATER_THAN); $query->orderByWeightMax(Criteria::ASC); } if ($config['method'] != CustomDelivery::METHOD_WEIGHT) { $total = $cart->getTotalAmount(); // convert amount to the default currency if (0 == $currency->getByDefault()) { $total = $total / $currency->getRate(); } $query->filterByPriceMax($total, Criteria::GREATER_THAN); $query->orderByPriceMax(Criteria::ASC); } $slice = $query->findOne(); $postage = null; if (null !== $slice) { $postage = new OrderPostage(); if (0 == $currency->getByDefault()) { $price = $slice->getPrice() * $currency->getRate(); } else { $price = $slice->getPrice(); } $price = round($price, 2); $postage->setAmount($price); $postage->setAmountTax(0); // taxed amount if (0 !== $config['tax']) { $taxRuleI18N = I18n::forceI18nRetrieving($this->getRequest()->getSession()->getLang()->getLocale(), 'TaxRule', $config['tax']); $taxRule = TaxRuleQuery::create()->findPk($config['tax']); if (null !== $taxRule) { $taxCalculator = new Calculator(); $taxCalculator->loadTaxRuleWithoutProduct($taxRule, $country); $postage->setAmount(round($taxCalculator->getTaxedPrice($price), 2)); $postage->setAmountTax($postage->getAmount() - $price); $postage->setTaxRuleTitle($taxRuleI18N->getTitle()); } } } return $postage; }