Answer the question
In order to leave comments, you need to log in
How to make a filter by quantity in Bitrix D7 for join requests?
Good afternoon.
The task is to get all goods with quantity in all warehouses > n.
Moreover, it should be possible to limit the condition to certain warehouses.
For example, select all products with a total quantity in warehouses of 3.8 and 12 - more than 9 pieces.
Here is what I managed to write at the moment
$query = new \Bitrix\Main\Entity\Query(\Bitrix\Iblock\ElementTable::getEntity());
$query->setSelect(["ID", "price","store"])
->setFilter([
"IBLOCK_ID" => $this->iblockId,
"IBLOCK_SECTION_ID" => $this->iblockSectionId,
"ACTIVE" => "Y",
"price.CATALOG_GROUP_ID" => 1,
">price.PRICE" => 0
])
->setOrder(array("ID" => "ASC"))
->setLimit(10);
/**
* Join таблицы с ценами
*/
$query->registerRuntimeField("price",[
"data_type" => "\Bitrix\Catalog\PriceTable",
'reference' => [
'this.ID' => 'ref.PRODUCT_ID'
],
]);
$query->registerRuntimeField("store",[
"data_type" => "\Bitrix\Catalog\StoreProductTable",
'reference' => [
'this.ID' => 'ref.PRODUCT_ID'
],
]);
$elements = $query->exec();
Answer the question
In order to leave comments, you need to log in
Decided as follows
$query->registerRuntimeField("store",[
"data_type" => "\Bitrix\Catalog\StoreProductTable",
'reference' => [
'this.ID' => 'ref.PRODUCT_ID'
],
]);
$query->registerRuntimeField("DETAIL_AMOUNT",[
"data_type" => "integer",
"expression" => array("sum(%s)", "store.AMOUNT")
]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question