• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/product/catalogprovider.php
  • Класс: BitrixCatalogProductCatalogProvider
  • Вызов: CatalogProvider::shipProduct
static function shipProduct(array $productData, array $productStoreDataList = array()): SaleResult
	{
		$result = new SaleResult();

		$productId = $productData['PRODUCT_ID'];

		$productQuantity = self::getTotalAmountFromQuantityList($productData);

		$needShip = ($productQuantity < 0);

		if (
			//CatalogConfigState::isUsedInventoryManagement()
			$productData['PRODUCT']['USED_STORE_INVENTORY']
		)
		{
			if (empty($productStoreDataList) && $needShip)
			{
				$result->addError(
					new SaleResultError(
						MainLocalizationLoc::getMessage(
							"DDCT_DEDUCTION_STORE_ERROR",
							array_merge(
								self::getProductCatalogInfo($productId),
								array("#PRODUCT_ID#" => $productId)
							)
						), "DDCT_DEDUCTION_STORE_ERROR"
					)
				);
				return $result;
			}

			$setQuantityList = array();
			$r = static::getSetableStoreQuantityProduct($productData, $productStoreDataList);
			if ($r->isSuccess())
			{
				$resultData = $r->getData();
				if (!empty($resultData[Base::FLAT_QUANTITY_LIST]))
				{
					$setQuantityList = $resultData[Base::FLAT_QUANTITY_LIST];
				}
			}
			else
			{
				return $r;
			}

			/*if (!$productData['PRODUCT']['USED_STORE_INVENTORY']) // product types without stores
			{
				$setQuantityList = [];
			} */

			$r = static::updateCatalogStoreAmount($setQuantityList);
			if ($r->isSuccess())
			{
				$resultData = $r->getData();
				if (!empty($resultData['AMOUNT_UPDATED_LIST']))
				{
					foreach($resultData['AMOUNT_UPDATED_LIST'] as $catalogStoreIsUpdated)
					{
						if ($catalogStoreIsUpdated === true)
						{
							static::clearHitCache(self::CACHE_STORE_PRODUCT);
							if ($needShip)
							{
								$r = static::deleteBarcodes($productData);
							}
							else
							{
								$r = static::addBarcodes($productData);
							}

							if (!$r->isSuccess())
							{
								$result->addErrors($r->getErrors());
							}
						}
					}
				}
			}
			else
			{
				return $r;
			}

			return static::shipQuantityWithStoreControl($productData);
		}
		elseif (isset($productData["CATALOG"]))
		{
			if ($productData["CATALOG"]["QUANTITY_TRACE"] == "N")
			{
				return $result;
			}
		}

		return static::shipQuantityWithoutStoreControl($productData);

	}