Ejemplo n.º 1
0
 /**
  * @param BasketItem $basketItem
  * @throws Main\ArgumentOutOfRangeException
  */
 private function addBundleToCollection(BasketItem $basketItem)
 {
     /** @var Basket $bundleCollection */
     $bundleCollection = $basketItem->getBundleCollection();
     if ($bundleCollection->getOrder() === null) {
         /** @var Basket $basketCollection */
         if ($basketCollection = $basketItem->getCollection()) {
             if ($order = $basketCollection->getOrder()) {
                 $bundleCollection->setOrder($order);
             }
         }
     }
     /** @var Shipment $shipment */
     $shipment = $this->getShipment();
     $bundleBaseQuantity = $basketItem->getBundleBaseQuantity();
     /** @var BasketItem $bundleBasketItem */
     foreach ($bundleCollection as $bundleBasketItem) {
         if ($this->isExistsBasketItem($bundleBasketItem)) {
             continue;
         }
         $bundleProductId = $bundleBasketItem->getProductId();
         if (!isset($bundleBaseQuantity[$bundleProductId])) {
             throw new Main\ArgumentOutOfRangeException("bundle product id");
         }
         $quantity = $bundleBaseQuantity[$bundleProductId] * $basketItem->getQuantity();
         if ($quantity == 0) {
             continue;
         }
         $shipmentItemBundle = ShipmentItem::create($this, $bundleBasketItem);
         $this->addItem($shipmentItemBundle);
         if ($shipment->isSystem()) {
             $shipmentItemBundle->setFieldNoDemand('QUANTITY', $quantity);
         } else {
             $shipmentItemBundle->setQuantity($quantity);
         }
     }
 }