want to print order details and product details (variants) which are ordered.
My xml file
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_order_save_after">
<observer name="recipes_sales_order_save_after"
instance="Vendorname\Modulename\Observer\Observer" />
</event>
</config>
My observer file
<?php namespace Vendorname\Modulename\Observer;
use Magento\Framework\Event\ObserverInterface;
public function __construct(
\Magento\Sales\Model\Order $order
)
{
$this->order = $order;
}
public function execute(\Magento\Framework\Event\Observer
$observer)
{
$order = $observer->getEvent()->getOrder();
$writer = new \Zend\Log\Writer\Stream(BP . '/var/log/nitesh.log');
$logger = new \Zend\Log\Logger();
$logger->addWriter($writer);
$logger->info($order->getOrderId());
foreach( $order->getAllVisibleItems() as $item ) {
$logger->info( $item->getHana()); //" HANA is new attribute name"
$logger->info( $item->getProductId());
}
but getHana not print