예제 #1
0
 /**
  * {@inheritdoc}
  */
 public function applyShippingCharges(OrderInterface $order)
 {
     $order->removeShippingAdjustments();
     // Remove all shipping adjustments, we recalculate everything from scratch.
     foreach ($order->getShipments() as $shipment) {
         $shippingCharge = $this->calculator->calculate($shipment);
         $adjustment = $this->adjustmentRepository->createNew();
         $adjustment->setLabel(OrderInterface::SHIPPING_ADJUSTMENT);
         $adjustment->setAmount($shippingCharge);
         $adjustment->setDescription($shipment->getMethod()->getName());
         $order->addAdjustment($adjustment);
     }
     $order->calculateTotal();
 }
 function it_applies_calculated_shipping_charge_for_each_shipment_associated_with_the_order($adjustmentRepository, $calculator, AdjustmentInterface $adjustment, OrderInterface $order, ShipmentInterface $shipment, ShippingMethodInterface $shippingMethod)
 {
     $adjustmentRepository->createNew()->willReturn($adjustment);
     $order->getShipments()->willReturn(array($shipment));
     $calculator->calculate($shipment)->willReturn(450);
     $shipment->getMethod()->willReturn($shippingMethod);
     $shippingMethod->getName()->willReturn('FedEx');
     $adjustment->setAmount(450)->shouldBeCalled();
     $adjustment->setLabel(Order::SHIPPING_ADJUSTMENT)->shouldBeCalled();
     $adjustment->setDescription('FedEx')->shouldBeCalled();
     $order->removeShippingAdjustments()->shouldBeCalled();
     $order->addAdjustment($adjustment)->shouldBeCalled();
     $order->calculateTotal()->shouldBeCalled();
     $this->applyShippingCharges($order);
 }