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

		$catalogData = $productData['CATALOG'];

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

		$catalogReservedQuantity = (float)$catalogData['QUANTITY_RESERVED'];
		$catalogQuantity = self::getTotalAmountFromPriceList($catalogData);

		$fields = array();

		$isExistsReserve = static::isExistsCommonStoreReserve($productData) && static::isReservationEnabled();
		$isNeedShip = ($productQuantity < 0);

		if ($isNeedShip)
		{
			$productQuantity = abs($productQuantity);
			if (($productQuantity <= $catalogReservedQuantity + $catalogQuantity) || $catalogData["CAN_BUY_ZERO"] == "Y")
			{
				if ($isExistsReserve)
				{
					if ($productQuantity <= $catalogReservedQuantity)
					{
						$needReservedQuantity = $catalogReservedQuantity - $productQuantity;
						$fields["QUANTITY_RESERVED"] = $needReservedQuantity;
					}
					else
					{
						$fields["QUANTITY_RESERVED"] = 0;
						$fields["QUANTITY"] = $catalogQuantity - ($productQuantity - $catalogReservedQuantity);
					}
				}
				else
				{
					$fields["QUANTITY"] = $catalogQuantity - $productQuantity;
				}

			}
			else //not enough products - don't deduct anything
			{
				$result->addError(
					new SaleResultError(
						MainLocalizationLoc::getMessage(
							"DDCT_DEDUCTION_QUANTITY_ERROR",
							array_merge(
								self::getProductCatalogInfo($productId),
								array("#PRODUCT_ID#" => $productId)
							)
						), "DDCT_DEDUCTION_QUANTITY_ERROR"
					)
				);
			}
		}
		else
		{
			if ($isExistsReserve)
			{
				$fields["QUANTITY_RESERVED"] = $catalogReservedQuantity + $productQuantity;
			}
			else
			{
				$fields["QUANTITY"] = $catalogQuantity + $productQuantity;
			}
		}

		if (!$productData['PRODUCT']['USED_RESERVATION'])
		{
			if (isset($fields['QUANTITY_RESERVED']))
			{
				unset($fields['QUANTITY_RESERVED']);
			}
		}

		if (!empty($fields))
		{
			$internalResult = CatalogModelProduct::update($productId, $fields);

			if ($internalResult-> isSuccess())
			{
				$quantityValues = array();

				if (isset($fields['QUANTITY']))
				{
					$quantityValues[QuantityControl::QUANTITY] = $fields['QUANTITY'];
					QuantityControl::resetAvailableQuantity($productId);
				}

				if (isset($fields['QUANTITY_RESERVED']))
				{
					$quantityValues[QuantityControl::RESERVED_QUANTITY] = $fields['QUANTITY_RESERVED'];
				}

				if (!empty($quantityValues))
				{
					QuantityControl::setValues($productId, $quantityValues);
				}
			}
			else
			{
				self::convertErrors($internalResult);
			}
			unset($internalResult);
		}

		return $result;
	}