1

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();
    }
}
1

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);
        }
     }
  • Thanks. So in the conditional where you put 'used for order object', how would I be able to access the order item, like sku? – Michael Jul 14 '15 at 11:26
  • Ok I've seen your edit. My problem now is that $paymentInfo is instanceof Mage_Sales_Model_Order_Payment, so it goes into the 'used for order object' part. – Michael Jul 14 '15 at 11:30
  • let me check... – Amit Bera Jul 14 '15 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.