B
B
budro2020-08-20 14:15:00
1C-Bitrix
budro, 2020-08-20 14:15:00

Can the shipping cost be changed?

Is it possible to reset the shipping cost in Bitrix by the OnSaleOrderBeforeSaved event?
setDeliveryPrice doesn't work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PetrPo, 2020-08-20
@budro

You need to change not the shipping cost, but the shipping cost. Something like this:

$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sale', 'OnSaleOrderBeforeSaved', ['OrderEvents', 'onBeforeOrderSaveHandler']);

class OrderEvents {
  public static function onBeforeOrderSaveHandler(\Bitrix\Main\Event $event) {
    $order = $event->getParameter('ENTITY');
    $shipmentCollection = $order->getShipmentCollection();
    
    foreach($shipmentCollection as $shipment) {
      if(!$shipment->isSystem())
        $shipment->setBasePriceDelivery(0, false);
    }
  }
}

UPD
About if(!$shipment->isSystem()) I'm not sure, I took it from the sale.order.ajax component. I remember that there, like, two shipments are created - one system, but I don’t remember why.

B
budro, 2020-08-21
@budro

The price does not change, so I already tried.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question