S
S
sneeskaa2020-10-05 21:37:56
1C-Bitrix
sneeskaa, 2020-10-05 21:37:56

Why does getting a list of goods in Bitrix d7 not work?

You need to get a list of goods in the basket with section ID 114. To do this, I used the function from the office. documentation:

<? $dbRes = \Bitrix\Sale\Basket::getList([
    'select' => ['NAME', 'QUANTITY'],
    'filter' => [      
        '=IBLOCK_SECTION_ID' => '114',
        '=FUSER_ID' => \Bitrix\Sale\Fuser::getId(), 
        '=ORDER_ID' => null,
        '=LID' => \Bitrix\Main\Context::getCurrent()->getSite(),
        '=CAN_BUY' => 'Y',
    ]
]);

while ($item = $dbRes->fetch())
{
    var_dump($item);
   
}
?>


Opened a table containing products. The section ID is called IBLOCK_SECTION_ID there, but the error is returned:
Unknown field definition `IBLOCK_SECTION_ID` (IBLOCK_SECTION_ID) for \Bitrix\Sale\Internals\Basket Entity. (100)


It is clear that he messed up - the question is where?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton, 2020-10-06
@anton99zel

<?
require_once($_SERVER['DOCUMENT_ROOT'] . "/bitrix/modules/main/include/prolog_before.php");//подключить, если надо
use Bitrix\Sale;
$dbRes = \Bitrix\Sale\Basket::getList(array(
        'filter' => array(
        'FUSER_ID' => Sale\Fuser::getId(), 
        'ORDER_ID' => null,
        'LID' => SITE_ID,
        'CAN_BUY' => 'Y',
    ),
'select' => array('PRODUCT_ID', 'NAME'),
));
while ($item = $dbRes->fetch())
{
$res = CIBlockElement::GetByID($item);
if($arRes = $res->Fetch()) 
if ($arRes[IBLOCK_SECTION_ID] == '114') //покажем только из раздела с id 114
print_r ($item[NAME].'</br>');//выведем названия
}
?>

Basket::getList - contains no sections!

M
Mikhail, 2020-10-08
@RuComMarket

the IBLOCK_SECTION_ID column is not contained in b_sale_basket, it is
necessary to get it through join
, respectively, add runtime

'runtime' => [
'ELEMENT' => [
            'data_type' => '\Bitrix\Iblock\ElementTable',
            'reference' => ['=this.PRODUCT_ID' => 'ref.ID'],
            'join_type' => 'left'
        ],
]

and we add to the filter
'=ELEMENT.IBLOCK_SECTION_ID' => 114
or to the getMap of the basket, it seems there is a PRODUCT connecting with the product, you can try in the filter without runtime
'=PRODUCT.IBLOCK_SECTION_ID' => 114

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question