P
P
photosho2019-07-30 17:26:16
1C-Bitrix
photosho, 2019-07-30 17:26:16

How to get order object by XML_ID?

How can I get an order on D7 by XML_ID ("External order code")? I do it like this:

$order = \Bitrix\Sale\OrderBase::loadByFilter([
    'filter' => ['XML_ID' => $xml]
]);

But there is some internal error in OrderBase. What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Gritsuk, 2019-07-31
@photosho

So you see the error.

[Bitrix\Main\NotImplementedException] 
 (140)
/bitrix/modules/sale/lib/orderbase.php:2069
#0: Bitrix\Sale\OrderBase::getList(array)
  /bitrix/modules/sale/lib/orderbase.php:363
#1: Bitrix\Sale\OrderBase::loadFromDb(array)
  /bitrix/modules/sale/lib/orderbase.php:292
#2: Bitrix\Sale\OrderBase::loadByFilter(array)
  /test/index.php:7

You call the class method \Bitrix\Sale\OrderBase. This class is abstract. And the getList method in it needs to be redefined, which is done in its successor \Bitrix\Sale\Order
As a result, your code will look like this:
$order = \Bitrix\Sale\Order::loadByFilter([
    'filter' => ['XML_ID' => $xml]
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question