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.