/**
  * Returns the method's calculator instance
  *
  * @param ShippingMethodInterface $shippingMethod
  *
  * @return \WellCommerce\AppBundle\Calculator\ShippingMethodCalculatorInterface
  */
 protected function getCalculator(ShippingMethodInterface $shippingMethod)
 {
     $calculator = $shippingMethod->getCalculator();
     if (!$this->shippingMethodCalculatorCollection->has($calculator)) {
         throw new CalculatorNotFoundException($calculator);
     }
     return $this->shippingMethodCalculatorCollection->get($calculator);
 }
예제 #2
0
 /**
  * {@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;
 }