Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
 public static function createWeight(ShippableInterface $shippable)
 {
     return (new Weight())->setUnits(new WeightUnits(WeightUnits::_KG))->setValue($shippable->getShippingWeight());
 }