V
V
Vladimir2019-10-31 12:31:11
1C-Bitrix
Vladimir, 2019-10-31 12:31:11

How to get shipping warehouse ID by order ID in Bitrix?

Good afternoon colleagues, share how you can get the warehouse id from the order id.
I do it like this:

$order = \Bitrix\Sale\Order::load(37);

$shipmentCollection = $order->getShipmentCollection();

foreach($shipmentCollection as $shipment) {
    $shipment_id = $shipment->getId();
  
     if ($shipment->isSystem())
     continue;
      
    $arShipments[$shipment_id] = array(
      'ID' => $shipment_id,
      'ACCOUNT_NUMBER' => $shipment->getField('ACCOUNT_NUMBER'),
      'ORDER_ID' => $shipment->getField('ORDER_ID'),
      'DELIVERY_ID' => $shipment->getField('DELIVERY_ID'),
      'STOCK_ID' => $shipment->getStoreId(),
      'PRICE_DELIVERY' => (float)$shipment->getField('PRICE_DELIVERY'),
      'BASKET' => array(),
    );
  
    
    $shipmentItemCollection = $shipment->getShipmentItemCollection();
    foreach($shipmentItemCollection as $item) {
      
    $basketItem = $item->getBasketItem();

  if (!$basketItem->canBuy() || $basketItem->isDelay())
    continue;
 
    $arItem = array(
       'PRODUCT_ID' => $basketItem->getProductId(),
     'NAME' => $basketItem->getField('NAME'),
     'PRICE' => $basketItem->getPrice(),
     'FINAL_PRICE' => $basketItem->getFinalPrice(), 
     'QUANTITY' => $basketItem->getQuantity(),
     'WEIGHT' => $basketItem->getWeight(),
  );
  
    $arShipments[$shipment_id]['BASKET'][$arItem['PRODUCT_ID']] = $arItem;
    
    } 
}

At the output we have:
Array
(
    [68] => Array
        (
            [ID] => 68
            [ACCOUNT_NUMBER] => 37/2
            [ORDER_ID] => 37
            [DELIVERY_ID] => 2
            [STOCK_ID] => 0
            [PRICE_DELIVERY] => 500
            [BASKET] => Array
                (
                    [6977] => Array
                        (
                            [PRODUCT_ID] => 6977
                            [NAME] => Сплит система Pioneer 07 VEKTOR
                            [PRICE] => 10851
                            [FINAL_PRICE] => 10851
                            [QUANTITY] => 1
                            [WEIGHT] => 0.00
                        )

                )

        )

)

As you can see [STOCK_ID] => 0
The shipment itself did https://yadi.sk/i/d3WyBMKIfFngHA
I tried to change it in different ways, $shipment->getStoreId() still returns 0.
What am I doing wrong?
Thank you.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question