0

I want to store an attribute value as an order comment when an order is placed.

Here is my code:

class Easylife_Meta_Model_Observer
{
    public function autocomment($observer)
    {
        $_product->getProduct();
        $comment = $_product->getDeliveryTime();
        $order = $observer->getEvent()->getOrder();
        $history = $order->addStatusHistoryComment( $comment, false);
        $history->setIsCustomerNotified(false);
        $order->save();
    }
}
  • You need to get order in observer, from order object you can get all items. – Pawan Jun 7 '18 at 3:28
0

You can do like this:

public function getAttr($observer)
{
    //Get quote item
    $event = $observer->getEvent();
    $quoteItem = $event->getQuoteItem();
    // get product attributes from $quoteItem
    $_options = $quoteItem->getProduct()->getData('your-attribute');
}

Or if the above code doesn't work then you can change Magento event checkout_cart_product_add_after instead of sales_order_place_after.

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.