E
E
Evgeny Nikolaev2021-08-19 12:10:58
API
Evgeny Nikolaev, 2021-08-19 12:10:58

How to get a list of products for a certain infoblock using \Bitrix\Catalog\ProductTable::getList?

I'm trying to get a list of products for a specific Bitrix infoblock using the D7 method \Bitrix\Catalog\ProductTable::getList with the following code:

<?php
require $_SERVER['DOCUMENT_ROOT'].'/bitrix/modules/main/include/prolog_before.php';

$result = \Bitrix\Catalog\ProductTable::getList(array(
    'filter' => array("=ELEMENT_IBLOCK_ID"=>46),
));

if($product=$result->fetch()) {
  var_dump($product);
}


I get the following error:

[Bitrix\Main\SystemException]
Unknown field definition `ELEMENT_IBLOCK_ID` (ELEMENT_IBLOCK_ID) for Product Entity. (100)
/var/www/u0073302/data/www/leader-t.ru/bitrix/modules/main/lib/orm/query/chain.php:346

Documentation here https://dev.1c-bitrix. ru/api_help/catalog/classes/... it says that the code of the product infoblock is ELEMENT_IBLOCK_ID . Then why the error? If I specify IBLOCK_ID, then the error is similar, but if I specify, for example, the Id-product in the filter, that is, using the ID key, then it works fine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-08-19
@nikolaevevge

It's weird to use d7 and rely on the documentation for the old kernel method.
If you open the b_catalog_product table (to which you are making a query), you will see that there is no such field there.
If you need information on the fields of the infoblock element (without fields that refer to the catalog), then you need to use the methods of the corresponding module \Bitrix\Iblock\ElementTable::getList - there is an IBLOCK_ID field.
In your case, if you open the file with the description of the entity /bitrix/modules /catalog/lib/product.php in the getMap method you can see the description of the relationship

'IBLOCK_ELEMENT' => new Main\Entity\ReferenceField(
  'IBLOCK_ELEMENT',
  '\Bitrix\Iblock\Element',
  array('=this.ID' => 'ref.ID'),
  array('join_type' => 'LEFT')
),

This means that the fields of the entity described in the \Bitrix\Iblock\ElementTable class can be accessed through this key
'filter' => array("IBLOCK_ELEMENT.IBLOCK_ID"=>46),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question