/**
  * @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);
         }
     }
 }
Exemple #2
0
 /**
  * @internal
  * @param BasketItem $basketItem
  * @param $moduleId
  * @param $productId
  * @param array $properties
  *
  * @return BasketItem|bool
  */
 public static function getExistsItemInBundle(BasketItem $basketItem, $moduleId, $productId, array $properties = array())
 {
     if (!$basketItem->isBundleParent()) {
         return null;
     }
     if (($bundleList = $basketItem->getBundleCollection()) && count($bundleList) > 0) {
         /** @var BasketItem $bundleBasketItem */
         foreach ($basketItem->getBundleCollection() as $bundleBasketItem) {
             if ($bundleBasketItem->getField('PRODUCT_ID') != $productId || $bundleBasketItem->getField('MODULE') != $moduleId) {
                 continue;
             }
             if (!empty($properties) && is_array($properties)) {
                 /** @var BasketPropertiesCollection $basketPropertyCollection */
                 $basketPropertyCollection = $bundleBasketItem->getPropertyCollection();
                 if ($basketPropertyCollection->isPropertyAlreadyExists($properties)) {
                     return $bundleBasketItem;
                 }
             } else {
                 return $bundleBasketItem;
             }
         }
     }
     return null;
 }
Exemple #3
0
 protected static function setProviderTrustData(BasketItem $item, Order $order, array $data)
 {
     if (empty($data)) {
         return false;
     }
     Provider::setTrustData($order->getSiteId(), 'sale', $item->getProductId(), $data);
     if ($item->isBundleParent()) {
         if ($bundle = $item->getBundleCollection()) {
             /** @var \Bitrix\Sale\BasketItem $bundleItem */
             foreach ($bundle as $bundleItem) {
                 $bundleItemData = $bundleItem->getFields()->getValues();
                 Provider::setTrustData($order->getSiteId(), 'sale', $bundleItem->getProductId(), $bundleItemData);
             }
         }
     }
     return true;
 }