Updating Product Stocks in 1C-Bitrix Using PHP
1C-Bitrix is a popular platform for creating and managing websites. If you need to change the stock levels for a product in the system, you can use a PHP function.
Example Function
<?php/** * Устанавливает новое количество товара на складе в 1С Битрикс. * * @param int $productId - Идентификатор товара. * @param int $quantity - Новое количество товара. * @param int $storeIdInBitrix - Идентификатор склада в 1С Битрикс. */function setQuantityForOffer($productId, $quantity, $storeIdInBitrix){
// Получение данных о товаре на складе $storeProduct = CCatalogStoreProduct::GetList(array(), array( "PRODUCT_ID" => $productId, "STORE_ID" => $storeIdInBitrix ), array('ID');
$storeProduct = $storeProduct->Fetch();
// Собираем массив данных для обновления или добавления записи $arFields = array( "PRODUCT_ID" => $productId, "STORE_ID" => $storeIdInBitrix, "AMOUNT" => $quantity, );
// Если запись существует, обновляем её, иначе добавляем новую if ($storeProduct) { CCatalogStoreProduct::Update($storeProduct['ID'], $arFields); } else { CCatalogStoreProduct::Add($arFields); }
}
How to Use
Simply call the setQuantityForOffer
function with the required parameters:
$productId = 123; // Замените на реальный идентификатор товара$quantity = 50; // Новое количество товара$storeIdInBitrix = 1; // Идентификатор склада в 1С Битрикс
setQuantityForOffer($productId, $quantity, $storeIdInBitrix);