S
S
sr362020-05-13 12:34:51
1C-Bitrix
sr36, 2020-05-13 12:34:51

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();

And then I don’t understand at all, I’m confused

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sr36, 2020-05-13
@sr36

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 question

Ask a Question

731 491 924 answers to any question