How to get value of custom attribute of product in observer?

by Midlaj   Last Updated January 20, 2018 11:09 AM

I have created a sales_order_save_after event observer. i will show the code below

SalesOrderSaveAfter.php

public function execute(\Magento\Framework\Event\Observer $observer)
{   
    //get the order object
    $order = $observer->getEvent()->getOrder();
    if ($order instanceof \Magento\Framework\Model\AbstractModel) 
    {   
        //get status
        $new_status =   $order->getStatus();
        //check the new status is confirm or canceled

        if ($new_status == 'confirm' || $new_status == 'canceled') 
        {    
            //parameters = array()
            $params         =   array();
            $order_id       =   $order->getId();
            $customer_id    =   $order->getCustomerId();

            if( !empty($order_id) ) {
                $product_ids = array();
                foreach( $order->getAllVisibleItems() as $item ) {
                    $product_ids[] =    $item->getProductId();
                    $product       =    $item->getData();
                    //$nrv         =    $item->getProduct()->getAttributeText('nrv');

                }        
            }


            //$nrv = Mage::getModel('catalog/product')->load($product_ids)->getAttributeText('nrv');

            $params     =   array(
                'order_id'      =>  $order_id,
                'customer_id'   =>  $customer_id,
                'product_id'    =>  $product_ids,
                'status'        =>  $new_status,
                'product'       =>  $product, 
                //'nrv'         =>  $nrv,
            ); 
        }

        //call the curl
        $this->curlCall($params);

    }
    return $this;
}

Everything is working correctly. Am getting All the information except custom attribute. I added custom attribute nrv to each of the product. but i didn't get value of custom attribute. How can I get the custom attribute value in observer?. Thanks in advance for your valuable answer.



Related Questions



what is the event when store configuration save?

Updated April 02, 2016 08:04 AM

order details in observer not working - magento 2

Updated April 26, 2016 08:03 AM

sales_order_creditmemo_save_after event in magento 2?

Updated February 23, 2016 06:04 AM

Which event should I use for an RMA observer?

Updated September 21, 2016 09:25 AM