T
T
tgarl2021-10-01 11:50:02
1C-Bitrix
tgarl, 2021-10-01 11:50:02

How to fit orders by product properties?

Products have properties: brands, type...
How can I get a list of orders that have products with the property brand = ..., or type = shoes?

You can filter by product name like this

$parameters = [
      'filter' => [
        'BASKET.NAME' => "%".$_REQUEST['CODE']."%"
      ]
    ];
$dbRes = \Bitrix\Sale\Order::getList($parameters);

В BASKET не передаются эти свойства.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2021-10-01
@tgarl

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

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

$propertyId = 1;

$result = \Bitrix\Sale\Order::getList([
  'filter' => ['PROPERTIES.IBLOCK_PROPERTY_ID' => $propertyId, '!PROPERTIES.VALUE' => false],
  'select' => ['ID'],
  'runtime' => [
    new Reference(
      'PROPERTIES', ElementPropertyTable::class,
      Join::on('this.BASKET.PRODUCT_ID', 'ref.IBLOCK_ELEMENT_ID')
    )
  ]
])->fetchAll();

print_r($result);

Specify your $propertyId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question