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);
 }
 function it_denies_category_requirement_if_categories_dont_match(ShippingSubjectInterface $subject, ShippingMethodInterface $shippingMethod, ShippingCategoryInterface $shippingCategory, ShippingCategoryInterface $shippingCategory2, ShippableInterface $shippable)
 {
     $shippingMethod->getCategory()->shouldBeCalled()->willReturn($shippingCategory);
     $shippingMethod->getCategoryRequirement()->shouldBeCalled()->willReturn(ShippingMethodInterface::CATEGORY_REQUIREMENT_MATCH_ANY);
     $shippable->getShippingCategory()->shouldBeCalled()->willReturn($shippingCategory2);
     $subject->getShippables()->shouldBeCalled()->willReturn([$shippable]);
     $this->isCategoryEligible($subject, $shippingMethod)->shouldReturn(false);
 }
 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));
 }
Exemple #5
0
 public static function createDimensions(ShippableInterface $shippable)
 {
     return (new Dimensions())->setWidth($shippable->getShippingWidth())->setHeight($shippable->getShippingHeight())->setLength($shippable->getShippingDepth())->setUnits(new LinearUnits(LinearUnits::_CM));
 }