private function getCalculator(ShippingMethodInterface $shippingMethod) : ShippingCalculatorInterface { $calculator = $shippingMethod->getCalculator(); if (false === $this->calculators->containsKey($calculator)) { throw new CalculatorNotFoundException($calculator); } return $this->calculators->get($calculator); }
/** * Returns the method's calculator instance * * @param ShippingMethodInterface $shippingMethod * * @return \WellCommerce\Bundle\ShippingBundle\Calculator\ShippingMethodCalculatorInterface */ protected function getCalculator(ShippingMethodInterface $shippingMethod) { $calculator = $shippingMethod->getCalculator(); if (!$this->shippingMethodCalculatorCollection->has($calculator)) { throw new CalculatorNotFoundException($calculator); } return $this->shippingMethodCalculatorCollection->get($calculator); }
public function calculate(ShippingMethodInterface $shippingMethod, ShippingSubjectInterface $subject) : Collection { $ranges = $shippingMethod->getCosts(); $baseCurrency = $subject->getCurrency(); $targetCurrency = $shippingMethod->getCurrency()->getCode(); $grossAmount = $this->currencyConverter->convert($subject->getGrossPrice(), $baseCurrency, $targetCurrency); return $this->filterRanges($ranges, $grossAmount); }
public function calculate(ShippingMethodInterface $shippingMethod, ShippingSubjectInterface $subject) : Collection { $ranges = $shippingMethod->getCosts(); $baseCurrency = $subject->getCurrency(); $targetCurrency = $shippingMethod->getCurrency()->getCode(); $grossAmount = $this->currencyConverter->convert($subject->getGrossPrice(), $baseCurrency, $targetCurrency); return $ranges->filter(function (ShippingMethodCostInterface $cost) use($grossAmount) { return $cost->getRangeFrom() <= $grossAmount && $cost->getRangeTo() >= $grossAmount; }); }
/** * @param ShippingMethodInterface $shippingMethod * @param CartInterface $cart * * @return bool|mixed */ public function calculateCart(ShippingMethodInterface $shippingMethod, CartInterface $cart) { $targetCurrency = $shippingMethod->getCurrency()->getCode(); $totalGrossAmount = $this->cartTotalsCollector->collectTotalGrossAmount($cart, $targetCurrency); $ranges = $shippingMethod->getCosts(); $supportedRanges = $ranges->filter(function (ShippingMethodCostInterface $cost) use($totalGrossAmount) { return $cost->getRangeFrom() <= $totalGrossAmount && $cost->getRangeTo() >= $totalGrossAmount; }); if ($supportedRanges->count()) { return $supportedRanges->first(); } return null; }
/** * {@inheritdoc} */ public function calculate(ShippingMethodInterface $shippingMethod, ShippingCalculatorSubjectInterface $subject) { $ranges = $shippingMethod->getCosts(); $baseCurrency = $subject->getShippingCostCurrency(); $targetCurrency = $shippingMethod->getCurrency()->getCode(); $grossAmount = $this->currencyHelper->convert($subject->getShippingCostGrossPrice(), $baseCurrency, $targetCurrency); $supportedRanges = $ranges->filter(function (ShippingMethodCostInterface $cost) use($grossAmount) { return $cost->getRangeFrom() <= $grossAmount && $cost->getRangeTo() >= $grossAmount; }); if ($supportedRanges->count()) { return $supportedRanges->first(); } return null; }
private function getOptionsProvider(ShippingMethodInterface $method) { $provider = $method->getOptionsProvider(); $collection = $this->get('shipping_method.options_provider.collection'); if ($collection->containsKey($provider)) { return $collection->get($provider); } return null; }