F
F
Franco Mannino2022-04-20 14:54:18
1C-Bitrix
Franco Mannino, 2022-04-20 14:54:18

Birtix: how to collect order data correctly?

It is required to collect in one array not only the fields that I receive in the request

$parameters = [
   'filter' => [
       ">=DATE_INSERT" => $date
   ],
   'order' => ["DATE_INSERT" => "ASC"]
];


$dbRes = \Bitrix\Sale\Order::loadByFilter($parameters);


or

$dbRes = \Bitrix\Sale\Order::getList($parameters);

but also data on the buyer, order items, payment, etc.
For one order, all this can be obtained as

$order = \Bitrix\Sale\Order::load($id);
$order_props = $order->getPropertyCollection()->getArray();
$basket = $order->getBasket();


But you need to get for an array of orders, and it turns out that you have to make a request for each order in a loop, and this, as I understand it, is not very good.

Is it possible in this situation to get everything in one query?
Is another method needed, or are there other $parameters ?

$result = Bitrix\Sale\Order:: какой-то метод (с параметрами) ->toArray();


Given that the ultimate goal is to output everything in JSON

echo \Bitrix\Main\Web\Json::encode($result);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Tkachev, 2022-04-20
@Real_Farmer

Perhaps this will help

use Bitrix\Sale;

$filter=[
'USER_ID' => '13627' ,
];


$user_orders = Sale\Order::getList(
                [
                    'filter'  => $filter,
                    'select'  => [
"ID",
"BASKET.PRODUCT_ID",
"USER.ID",
"SHIPMENT.STATUS_ID", 
"PAYMENT.ID"
],
                ]
            )->fetchAll();

 var_dump($user_orders);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question