3

My order #100000010 has 3 items. But when I used this code, it did not echo anything. Where is my mistake

<?php   
$id_order = 100000010;
$order = Mage::getModel('sales/order')->load($id_order);
$items = $order->getAllItems();
foreach($items as $i):
  echo $_product = Mage::getModel('catalog/product')
            ->load($i->getProductId())->getSku();
endforeach;?>
3

Hi 100000010 is order increment id.it is not order id.. So need to change

to

$order = Mage::getModel('sales/order')->loadByIncrementId($id_order)

from

$order = Mage::getModel('sales/order')->load($id_order);
4

The long number is the order's increment_id, which is different from its entity_id (which is what load() expects).

Use loadByIncrementId() to load by increment ID:

$order = Mage::getModel('sales/order')->loadByIncrementId($id_order);

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.