M
M
MMnka2021-06-15 08:25:40
1C-Bitrix
MMnka, 2021-06-15 08:25:40

How to display the delivery status as part of an order in 1s Bitrix?

Good afternoon!
I need to display the shipment status of an order. I tried to do it with

<?= htmlspecialcharsbx($shipment['STATUS_NAME'])?>
but I get the last value of the array. As I understand it, you need to rewrite the Basket or Shipment class. Tell me in which direction to move?
60c839923c7f0327707460.png
60c839ad49689523427420.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2021-06-15
@MMnka

Are you changing some component or writing your own? At least give the code or the name of the component that you edit from the standard ones, it's not clear. It is somehow not right to start from the "familiar" $shipment, you need to understand what is in this variable.

As I understand it, you need to rewrite the Basket or Shipment class

It's not exactly necessary.
Here is the code for how to get the status text for order shipments
$orderId = 57024;

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

$order = \Bitrix\Sale\Order::load($orderId);
$shipmentCollection = $order->getShipmentCollection();

/** @var \Bitrix\Sale\Shipment $shipment */
foreach ($shipmentCollection as $shipment) {
    if($shipment->isSystem()) {
        continue;
    }
    
    $statusCode = $shipment->getField('STATUS_ID');
    $statusLang = \Bitrix\Sale\StatusLangTable::getList(
        [
            'filter' => [
                'ID' => $statusCode,
                'LID' => LANGUAGE_ID
            ]
        ]
    )->fetchAll();
    
    var_dump($statusLang);
}

Execution result
array (size=1)
  0 => 
    array (size=4)
      'STATUS_ID' => string 'DN' (length=2)
      'LID' => string 'ru' (length=2)
      'NAME' => string 'Ожидает обработки' (length=33)
      'DESCRIPTION' => string 'Ожидает обработки' (length=33)

I
Ilya, 2021-06-15
@rpsv

As I understand it, you need to rewrite the Basket or Shipment class. Tell me in which direction to move?

What for?
but I get the last value of the array.

From what array? Does the shipping value actually match the value in the database? (in the admin area, go to the list of orders and check the status, or directly through the table view).
Otherwise, when displaying the status, simply create an order object Order::load() from there, pull out the shipping info Order::getShipmentCollections (not exactly, google which method is used) --- but there are very big doubts that the wrong info got into the standard order component, most likely you are reading something wrong.
There is also such a moment that you will most likely have 2 deliveries - one service delivery, the other selected when ordering (if nothing has been fixed), you can filter it by the isSystem property (also not accurate, but the IDE will tell you which method/property to read, there is no such thing in the documentation, although something may have already changed)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question