A
A
Alexander2021-12-07 17:56:07
1C-Bitrix
Alexander, 2021-12-07 17:56:07

How to filter items by SKU in Bitrix?

There is an array of articles.

"128806", "145267", "103748", "124208", "128804", "128805", "147683", "124201", "125533", "128801", "115858", "133042"

You need to understand how many of them are in stock and when they are updated.

I don't understand what to look for. No problems found by ID
$amount = \Bitrix\Catalog\StoreProductTable::getList([
        'filter' => [
            'PRODUCT_ID' => $request['offerId']
        ]
    ])->fetchAll();


I don’t understand how to search by article without knowing the product ID.
Where to think then?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-12-07
@kikher

use Bitrix\Iblock\ElementPropertyTable;
use Bitrix\Main\ORM\Fields\Relations\Reference;
use Bitrix\Main\ORM\Query\Join;

\Bitrix\Main\Loader::includeModule('catalog');

$propertyId = 20;
$propertyValue = ['188-12-07'];

$result = \Bitrix\Catalog\StoreProductTable::getList([
  'filter' => [
    'ELEMENT_PROPERTIES.IBLOCK_PROPERTY_ID' => $propertyId,
    'ELEMENT_PROPERTIES.VALUE' => $propertyValue,
  ],
  'runtime' => [
    new Reference('ELEMENT_PROPERTIES', ElementPropertyTable::class, Join::on('this.PRODUCT_ID', 'ref.IBLOCK_ELEMENT_ID'))
  ]
])->fetchAll();

print_r($result);

If it is known for sure that the values ​​of the property article and others do not match, you can not transfer
'ELEMENT_PROPERTIES.IBLOCK_PROPERTY_ID' => $propertyId,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question