0

Is their any way i can get the product names in sales_order_place_after observer ?

I get the order object but not sure how to fetch the products.

Any thoughts ?

0

You can get product names from order object like as follows:

$order = $observer->getEvent()->getOrder();

foreach ($order->getAllItems() as $item) {
    $arrProductNames[] = $item->getName();
}
0

You can retrieve the product names like this:

/** @var \Magento\Sales\Model\Order $order */
$order = $observer->getOrder();

foreach ($order->getItems() as $item) {
    // retrieve the names from the order items
    $productNames[] = $item->getName();

    // or retrieve the names from the product instance
    $productNames2[] = $item->getProduct()->getName();
}
0

In order to obtain the ordered product order data from the sales_order_after observer in the order that you would like, parse the orders in an orderly manner:

$fantasticOrderData = $observer->getEvent()->getOrder();

foreach ($fantasticOrderData->getAllItems() as $evenMoreFantasticItemData) {
    $superDuperCoolProductNames[] = $evenMoreFantasticItemData->getName();
}

I trust this answer is in order.

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.