Example #1
0
 public function createShipmentForCart(Cart $cart, ShipmentOption $shipmentOption, $name = null, $street = null, $city = null, $zip = null)
 {
     if ($shipmentOption instanceof ShipmentPersonalPoint) {
         $shipment = new ShipmentPersonal($cart, $shipmentOption);
     } elseif ($shipmentOption instanceof ShipmentTransportCompany) {
         $shipment = new ShipmentByTransportCompany($cart, $shipmentOption, $name, $street, $city, $zip);
     } elseif ($shipmentOption instanceof ShipmentCollectionPoint) {
         $shipment = new ShipmentToCollectionPoint($cart, $shipmentOption);
     } else {
         throw new \LogicException();
     }
     if ($cart->hasShipment()) {
         if ($cart->getShipment()->equals($shipment)) {
             return;
         }
         $this->removeEntity($cart->getShipment());
     }
     $cart->setShipment($shipment);
     $this->createEntity($shipment);
 }