Rus
Eng
Работа со складами и количеством товаров в Битрикс D7
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

All English-language materials have been translated fully automatically using the Google service

Selecting a warehouse by ID in Bitrix via D7

$arStore = \Bitrix\Catalog\StoreTable::getById($ID)->fetch();

Selection of active warehouses:

// Selection of all active warehouses:
$rsStore = \Bitrix\Catalog\StoreTable::getList(array(
	'filter' => array('ACTIVE'>='Y'),
));

while($arStore=$rsStore->fetch()){
	$arIBlockListID['STORES'][$arStore['ID']]=$arStore;
}

To select all fields, including custom ones, add to the query the construction 'select' => array ('*', 'UF_ *') :

$arStore = \Bitrix\Catalog\StoreTable::getList(array(
    'filter'=>array('=ID'=>$storeId),
    'select'=>array('*','UF_*'),
))->fetch();

Add caching to the selection of warehouses

CModule::IncludeModule("catalog");
$cntIBLOCK_List = 'Stores';
$cache = new CPHPCache();
$cache_time = 3600*24*360; //кеш на год
$cache_id = 'arIBlockListID'.$cntIBLOCK_List;
$cache_path = 'arIBlockListID';
if ($cache_time > 0 && $cache->InitCache($cache_time, $cache_id, $cache_path))
{
	$res = $cache->GetVars();
	if (is_array($res["arIBlockListID"]) && (count($res["arIBlockListID"]) > 0)){
		$arIBlockListID = $res["arIBlockListID"];
	}
	$arIBlockListID['CACHE']='true';

}
if (!is_array($arIBlockListID))
{
	$arIBlockListID['CACHE']='false';
	//Выборка всех активных складов:
	$rsStore = \Bitrix\Catalog\StoreTable::getList(array(
		'filter' => array('ACTIVE'>='Y'),
	));

	while($arStore=$rsStore->fetch()){
		$arIBlockListID['STORES'][$arStore['ID']]=$arStore;
	}

	//////////// end cache /////////
	if ($cache_time > 0)
	{
		$cache->StartDataCache($cache_time, $cache_id, $cache_path);
		$cache->EndDataCache(array("arIBlockListID"=>$arIBlockListID));
	}
}

If you are using Aspro store, you can use the built-in function:

$arStores=CNextCache::CCatalogStore_GetList(array(), array("ACTIVE" => "Y"), false, false, array());

Get all information about the product, including the quantity (deprecated method):

CCatalogProduct::GetByID($productID)

Fetching the quantity of a product with an identifier in $ productId in all active warehouses:

$rsStoreProduct = \Bitrix\Catalog\StoreProductTable::getList(array(
	'filter' => array('=PRODUCT_ID'=>$arResult["ID"],'STORE.ACTIVE'=>'Y'),
	'select' => array('*','UF_*'),
));

while($arStoreProduct=$rsStoreProduct->fetch()){
	$amount[$arStoreProduct['STORE_ID']] = $arStoreProduct;
}

Selecting the quantity of goods with the identifier in $ productId in all active warehouses (additionally, select the warehouse name):

$rsStoreProduct = \Bitrix\Catalog\StoreProductTable::getList(array(
    'filter' => array('=PRODUCT_ID'=>$productId,'STORE.ACTIVE'=>'Y'),
    'select' => array('AMOUNT','STORE_ID','STORE_TITLE' => 'STORE.TITLE'),
));

while($arStoreProduct=$rsStoreProduct->fetch()){
    print_r($arStoreProduct);
}

Fetching the quantity of goods with an identifier in $ productId in a warehouse with an identifier in $ storeId (additionally select the name of the warehouse and the name of the product):

$rsStoreProduct = \Bitrix\Catalog\StoreProductTable::getList(array(
    'filter' => array('=PRODUCT_ID'=>$productId,'=STORE_ID'=>$storeId),
    'limit' => 1,
    'select' => array('AMOUNT','STORE_TITLE' => 'STORE.TITLE', 'PRODUCT_NAME' => 'PRODUCT.IBLOCK_ELEMENT.NAME'),
));

if($arStoreProduct=$rsStoreProduct->fetch()){
    print_r($arStoreProduct);
}

& nbsp;

Site materials used:

Comments

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site