/**
  * {@inheritdoc}
  */
 public function applyShippingCharges(OrderInterface $order)
 {
     // Remove all shipping adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);
     foreach ($order->getShipments() as $shipment) {
         $shippingCharge = $this->calculator->calculate($shipment);
         $adjustment = $this->adjustmentFactory->createNew();
         $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
         $adjustment->setAmount($shippingCharge);
         $adjustment->setDescription($shipment->getMethod()->getName());
         $order->addAdjustment($adjustment);
     }
 }
 function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order(FactoryInterface $adjustmentFactory, DelegatingCalculatorInterface $calculator, AdjustmentInterface $adjustment, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod)
 {
     $adjustmentFactory->createNew()->willReturn($adjustment);
     $order->getShipments()->willReturn([$shipment]);
     $calculator->calculate($shipment)->willReturn(450);
     $shipment->getMethod()->willReturn($shippingMethod);
     $shippingMethod->getName()->willReturn('FedEx');
     $adjustment->setAmount(450)->shouldBeCalled();
     $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setLabel('FedEx')->shouldBeCalled();
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT)->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $this->process($order);
 }
 /**
  * {@inheritdoc}
  */
 public function process(OrderInterface $order)
 {
     // Remove all shipping adjustments, we recalculate everything from scratch.
     $order->removeAdjustments(AdjustmentInterface::SHIPPING_ADJUSTMENT);
     foreach ($order->getShipments() as $shipment) {
         try {
             $shippingCharge = $this->shippingChargesCalculator->calculate($shipment);
             $adjustment = $this->adjustmentFactory->createNew();
             $adjustment->setType(AdjustmentInterface::SHIPPING_ADJUSTMENT);
             $adjustment->setAmount($shippingCharge);
             $adjustment->setLabel($shipment->getMethod()->getName());
             $order->addAdjustment($adjustment);
         } catch (UndefinedShippingMethodException $exception) {
         }
     }
 }
 private function calculate(ShipmentInterface $shipment, OrderInterface $order)
 {
     $amount = $this->shippingCalculator->calculate($shipment);
     $adjustment = $this->getShippingAdjustment($order);
     $adjustment->setAmount($amount);
 }