Getting quote item data in abstract class
Question
I'm creating an abstract class that is extending Mage_Payment_Model_Method_Abstract
.
When I run
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cartItems = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
Mage::log($item->getSku(),null,'test.log',true);
}
I get nothing in the logs about this. How can I get access to the items?
Update
Thanks to Amit's answer below I was able to find out how to get the sku for the order
$orders = Mage::getModel('sales/order_collection');
foreach($orders as $order){
$items = $order->getAllVisibleItems();
foreach($items as $item){
$sku = $item->getSku();
}
}
Solution
As Mage::getSingleton('checkout/session')->getQuote()
using it working
on frontend
but it does not work on backend.
For backend magento use different model
Mage::getSingleton('adminhtml/session_quote')-.
Better solution is below:
$paymentInfo = $this->getInfoInstance();
if ($paymentInfo instanceof Mage_Sales_Model_Order_Payment) {
// used for order object
} else {
$Quote = $paymentInfo->getQuote();
// put your code here
$Quote = $quote->getAllVisibleItems();
foreach ($cartItems as $item) {
Mage::log($item->getSku(),null,'test.log',true);
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange