0

I need something to do using order item ids when order is created.

I tried sales_order_place_after and sales_order_save_after events, but unfortunately. Items from $observer->getEvent()->getOrder()->getAllVisibleItems() do not have Ids.

Which way should I go to achieve my needs? Also I need to avoid use of checkout controller events, because my code should work on the admin scope too.

1

After digging into ResourceModel\Order and AbstractModel classes I found event sales_order_save_commit_after and it works perfectly for me.

0

You can try this way. you don't need to inject order model

$order = $observer->getEvent()->getOrder();
$orderItems = $order->getAllItems();
foreach($orderItems ad $item){
 echo "Order Item ID :".$item->getItemId();
}

Let me know if it does not work for you.

  • No, It doesn't work. But I already found solution – spiil Nov 9 '18 at 10:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.