function it_throws_exception_if_unable_to_calculate_shipping_cost(AddressInterface $origin, AddressInterface $destination, ShippableInterface $shippable) { $shippable->getShippingWidth()->shouldBeCalled()->willReturn(5); $shippable->getShippingHeight()->shouldBeCalled()->willReturn(200); $shippable->getShippingDepth()->shouldBeCalled()->willReturn(10); $this->shouldThrow('MediaLab\\Shipping\\Calculator\\CalculatorException')->duringCalculate($origin, $destination, $shippable); }
public function calculate(AddressInterface $origin, AddressInterface $destination, ShippableInterface $shippable) { $estimations = []; foreach ($this->client->getRates($this->getRegionCode($origin), $this->getRegionCode($destination), $shippable->getShippingWeight(), $shippable->getShippingWidth() * $shippable->getShippingHeight() * $shippable->getShippingDepth()) as $rate) { $estimations[] = (new Estimation())->setCarrier('S.F. Express')->setServiceName($this->getServiceName($rate))->setServiceCode($rate['limitTypeName'] . ' ' . $rate['cargoTypeCode'])->setDeliveryDate(null === $rate['deliverTime'] ? null : new DateTime($rate['deliverTime']))->setCost((new Cost())->setCurrency($rate['currencyName'])->setAmount($rate['freight'])); } return $estimations; }
/** * @todo Check units. */ public function calculate(AddressInterface $origin, AddressInterface $destination, ShippableInterface $shippable) { $estimatedSize = $shippable->getShippingWidth() + $shippable->getShippingHeight() + $shippable->getShippingDepth(); foreach ($this->rates as $size => $rate) { if ($estimatedSize <= $size) { return [(new Estimation())->setCarrier('Yamato')->setServiceName('Yamato')->setServiceCode('YAMATO')->setCost((new Cost())->setCurrency('HKD')->setAmount($rate))]; } } throw new CalculatorException(sprintf('Unable to estimate rate for shippable of size %d. Maximal shippable size supported is %d.', $estimatedSize, $size)); }
public static function createDimensions(ShippableInterface $shippable) { return (new Dimensions())->setWidth($shippable->getShippingWidth())->setHeight($shippable->getShippingHeight())->setLength($shippable->getShippingDepth())->setUnits(new LinearUnits(LinearUnits::_CM)); }