/**
  * @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);
         }
     }
 }
Пример #2
0
 /**
  * @internal
  * @param Sale\BasketItem $basketItem
  *
  * @return array
  * @throws Main\ObjectNotFoundException
  */
 public static function convertBasketItemToArray(Sale\BasketItem $basketItem)
 {
     $fields = $basketItem->getFieldValues();
     /** @var Sale\Basket $basket */
     if (!($basket = $basketItem->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "Basket" not found');
     }
     if (empty($fields['LID'])) {
         $fields['LID'] = $basket->getSiteId();
     }
     if (empty($fields['LID'])) {
         if ($order = $basket->getOrder()) {
             $fields['LID'] = $order->getField('LID');
         }
         //$order->getField('LID')
     }
     if (empty($fields['FUSER_ID'])) {
         $fields['FUSER_ID'] = $basket->getFUserId(true);
     }
     /** @var Sale\BasketPropertiesCollection $basketPropertyCollection */
     if ($basketPropertyCollection = $basketItem->getPropertyCollection()) {
         /** @var Sale\BasketPropertyItem $basketPropertyItem */
         foreach ($basketPropertyCollection as $basketPropertyItem) {
             $propValues = $basketPropertyItem->getFieldValues();
             $propData = array("NAME" => $propValues['NAME'], "CODE" => $propValues['CODE'], "VALUE" => $propValues['VALUE'], "SORT" => $propValues['SORT']);
             if (isset($propValues['ID']) && intval($propValues['ID']) > 0) {
                 $propData['ID'] = $propValues['ID'];
             }
             $fields['PROPS'][] = $propData;
         }
     }
     return $fields;
 }
Пример #3
0
 protected static function getProductPoolQuantityByBasketItem(\Bitrix\Sale\BasketItem $basketItem)
 {
     /** @var \Bitrix\Sale\Basket $basket */
     if (!($basket = $basketItem->getCollection())) {
         return false;
     }
     /** @var \Bitrix\Sale\Order $order */
     if (!($order = $basket->getOrder())) {
         return false;
     }
     return \Bitrix\Sale\Provider::getReservationPoolItem($order->getInternalId(), $basketItem);
 }
Пример #4
0
 /**
  * @internal
  * @param Sale\BasketItem $basketItem
  *
  * @return array
  * @throws Main\ObjectNotFoundException
  */
 public static function convertBasketItemToArray(Sale\BasketItem $basketItem)
 {
     $fields = $basketItem->getFieldValues();
     /** @var Sale\Basket $basket */
     if (!($basket = $basketItem->getCollection())) {
         throw new Main\ObjectNotFoundException('Entity "Basket" not found');
     }
     if (empty($fields['LID'])) {
         $fields['LID'] = $basket->getSiteId();
     }
     if (empty($fields['LID'])) {
         if ($order = $basket->getOrder()) {
             $fields['LID'] = $order->getField('LID');
         }
         //$order->getField('LID')
     }
     if (empty($fields['FUSER_ID'])) {
         $fields['FUSER_ID'] = $basket->getFUserId(true);
     }
     return $fields;
 }
Пример #5
0
 public static function checkAvailableProductQuantity(BasketItem $basketItem, $deltaQuantity)
 {
     global $APPLICATION;
     $result = new Result();
     $resultProductData = array();
     $orderId = null;
     $userId = null;
     $siteId = null;
     /** @var Basket $basket */
     $basket = $basketItem->getCollection();
     if (($order = $basket->getOrder()) !== null) {
         $userId = $order->getUserId();
         $siteId = $order->getSiteId();
     }
     if ($userId === null || $siteId === null) {
         static $usersIds = array();
         if (empty($usersIds[$basket->getFUserId()])) {
             $usersIds[$basket->getFUserId()] = \CSaleUser::GetUserID($basket->getFUserId());
         }
         $userId = $usersIds[$basket->getFUserId()];
         $siteId = $basket->getSiteId();
     }
     if ($provider = $basketItem->getProvider()) {
         if ($provider instanceof Provider) {
             throw new NotSupportedException('provider not supported');
             //					$result = $provider::getProductData($siteId, $userId, $currency, $providerBasketItemList, $select);
         } elseif ($provider && array_key_exists("IBXSaleProductProvider", class_implements($provider))) {
             $needQuantity = $basketItem->getQuantity();
             if ($order && $order->getId() > 0) {
                 $needQuantity = $deltaQuantity;
             }
             $data = array("PRODUCT_ID" => $basketItem->getProductId(), "QUANTITY" => $needQuantity, "USER_ID" => $userId, "SITE_ID" => $siteId, "BASKET_ID" => $basketItem->getId(), "CHECK_QUANTITY" => "Y", 'CHECK_PRICE' => 'N', 'CHECK_COUPONS' => 'N', "SELECT_QUANTITY_TRACE" => "Y");
             // TODO: !
             if ($deltaQuantity <= 0) {
                 $result->setData(array('AVAILABLE_QUANTITY' => $deltaQuantity));
                 return $result;
             }
             $APPLICATION->ResetException();
             $resultProductData = $provider::GetProductData($data);
             if ($ex = $APPLICATION->GetException()) {
                 $result->addError(new ResultError($ex->GetString(), $ex->GetID()));
             }
         } else {
             $APPLICATION->ResetException();
             $resultProductData = \CSaleBasket::ExecuteCallbackFunction($basketItem->getField('CALLBACK_FUNC'), $basketItem->getField('MODULE'), $basketItem->getProductId(), $basketItem->getQuantity());
             if ($ex = $APPLICATION->GetException()) {
                 $result->addError(new ResultError($ex->GetString(), $ex->GetID()));
             }
         }
     } else {
         $availableQuantity = $basketItem->getQuantity();
         if ($deltaQuantity <= 0) {
             $availableQuantity = $deltaQuantity;
         }
         $result->setData(array('AVAILABLE_QUANTITY' => $availableQuantity));
         return $result;
     }
     $fields = array();
     if (array_key_exists('QUANTITY', $resultProductData)) {
         $fields['AVAILABLE_QUANTITY'] = $resultProductData['QUANTITY'];
     }
     if (array_key_exists('QUANTITY_TRACE', $resultProductData)) {
         $fields['QUANTITY_TRACE'] = $resultProductData['QUANTITY_TRACE'] == "Y";
     }
     if (!empty($fields)) {
         $result->setData($fields);
     }
     return $result;
 }