Y
Y
Yuriy2019-09-19 11:47:27
1C-Bitrix
Yuriy, 2019-09-19 11:47:27

Bitrix quick order, how to get shipping cost?

Tell me how to get the shipping cost at the time of sending an email with a quick order?
quick order on a component from Aspro.
Hooking on the quick order event

$eventManager = Bitrix\Main\EventManager::getInstance();
  $eventManager->addEventHandler("main", "OnBeforeEventAdd", array('OrderMailModify', 'OneClickBuyModify'));

but as I understand it, OnBeforeEventAdd is triggered before the order itself is saved, and the shipment is already added after.
trying to get delivery
public function OneClickBuyModify($event, &$siteId, &$arFields){
        if ($event != 'NEW_ONE_CLICK_BUY'){
        	return true;
        } 

        $order = \Bitrix\Sale\Order::load($arFields['RS_ORDER_ID']);
        $shipmentCollection = $order->getShipmentCollection();
        $arFields['PRICE_DELIVERY'] = $shipmentCollection->getBasePriceDelivery();

$shipmentCollection->getBasePriceDelivery() - returns 0, although there is a shipment for 300r in the generated order,
how to actually get the shipment?
for a regular order, this principle works, $shipmentCollection->getBasePriceDelivery() returns the correct amount. I understand that the OnBeforeEventAdd event fires before saving the order for 1Click purchase and quick order?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy, 2019-09-19
@yous

I will answer myself

public function OneClickBuyModify($event, &$siteId, &$arFields){
        if ($event != 'NEW_ONE_CLICK_BUY'){
        	return true;
        } 
if(class_exists('\Bitrix\Sale\Internals\OrderTable')){
            $arOrder = \Bitrix\Sale\Internals\OrderTable::getList(array('order' => array('ID' => 'ASC'), 'filter' => array('ID' => $arFields['RS_ORDER_ID'])))->Fetch();
        }
        else{
            $arOrder = CSaleOrder::GetList(array(), array('ID' => $arFields['RS_ORDER_ID']))->Fetch();
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question