Here is my attribute,
<?php ini_set('memory_limit','8048MB'); class Gta_GetOrderDetails_Model_Observer { public function getdetailsafterorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); foreach($items as $item){ $sku = $item->getSku(); $name= $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); } Mage::log($item->getName(),null,'event.log', true); ### start test observer ### // $order = $Observer->getEvent(); // Mage::log($order->getName(),null,'event.log'); ### end test observer ### } } ?>
Using mage::log how to print sku, name, qty ordered, price
Solved! Go to Solution.
Hello @Aveeva, Use it as below:
<?php class Gta_GetOrderDetails_Model_Observer { public function getdetailsafterorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); foreach($items as $item){ $sku = $item->getSku(); $name= $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); $loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price]; Mage::log(json_encode(print_r($loggerInfo, true))); } ### start test observer ### // $order = $Observer->getEvent(); // Mage::log($order->getName(),null,'event.log'); ### end test observer ### } } ?>
Hope it will help you.
If it helps you, please accept it as solution and give kudos.
Regards.
Hello @Aveeva,
Please use following code :
Mage::log(json_encode(print_r($item->getData(), true)));
Hope this will help you.
If it helps you please accept it as solution and give us kudos.
Regards
Hello @Aveeva ,
For creating log of array you can try using the following code
Mage::log(print_r($arr, 1), null, 'logfile.log');
Or
Mage::log($arr, null, 'logfile.log');
Hope it helps you!
Kudos and accept as solution if it works for you!
@Sarvagya Pandey How can i solve the below error,
Fatal error: Allowed memory size of 2097152 bytes exhausted (tried to allocate 1028096 bytes) in C:\wamp\www\magepro\app\code\local\Gta\GetOrderDetails\Model\Observer.php on line 19
<?php class Gta_GetOrderDetails_Model_Observer { public function getdetailsafterorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); foreach($items as $item){ $sku = $item->getSku(); $name = $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); } // Mage::log($item->getName(),null,'event.log', true); // Mage::log(print_r($item),null,'event.log', true); Mage::log(json_encode(print_r($item->getData(), true))); //line 19 ### start test observer ### // $order = $Observer->getEvent(); // Mage::log($order->getName(),null,'event.log'); ### end test observer ### } } ?>
@surbhiiagr How to declare $arr in my script?
Hello @Aveeva, Use it as below:
<?php class Gta_GetOrderDetails_Model_Observer { public function getdetailsafterorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); foreach($items as $item){ $sku = $item->getSku(); $name= $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); $loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price]; Mage::log(json_encode(print_r($loggerInfo, true))); } ### start test observer ### // $order = $Observer->getEvent(); // Mage::log($order->getName(),null,'event.log'); ### end test observer ### } } ?>
Hope it will help you.
If it helps you, please accept it as solution and give kudos.
Regards.
@Sarvagya Pandey May i know why dedicated log file not generated :
<?php class Gta_GetOrderDetails_Model_Observer { public function getdetailsafterorder($Observer) { $order = $Observer->getEvent()->getOrder(); $items = $order->getAllItems(); foreach($items as $item){ $sku = $item->getSku(); $name= $item->getName(); $qty = $item->getQtyOrdered(); $price = $item->getPrice(); $loggerInfo = ['sku' => $sku, 'name' => $name, 'qty' => $qty, 'price' => $price]; Mage::log(json_encode(print_r($loggerInfo, null,'event.log', true))); } ### start test observer ### // $order = $Observer->getEvent(); // Mage::log($order->getName(),null,'event.log'); ### end test observer ### } } ?>
@Aveeva ,
$arr is the name of your array in your case it is $item so.
Mage::log($item, null, 'logfile.log');
@surbhiiagr How can i solve below error
( ! ) Fatal error: Out of memory (allocated 299892736) (tried to allocate 295702528 bytes) in C:\wamp\www\magepro\app\Mage.php on line 839