1

I want to get only product id and qty from order id

below is way to get order detail

$order = Mage::getModel('sales/order')->loadByIncrementId($orderId);
$items = $order->getAllItems();

but it gives all i want only product id, quantity to minimize load ,

what filter have i to add ?

2 Answers 2

3

You can do this order item collection

Mage::getModel('sales/order_item')->getCollection();

for particular order you can get bu filter of field order_id;

      $orderItems=Mage::getModel('sales/order_item')->getCollection()
->addFieldToFilter('order_id',$orderid);

    foreach($orderItems as $eachorderitem){
    echo $eachorderitem->getQtyOrdered();
    }
1
  • how can i know what to write for other attribute by productprice, product name
    – mcoder
    Oct 30, 2014 at 4:44
1

Please use addAttributeToSelect();

$orderItems=Mage::getModel('sales/order_item')->getCollection()
                            ->addAttributeToSelect('qty_ordered')
                            ->addFieldToFilter('order_id','2');
                foreach($orderItems as $eachorderitem){
                    echo $eachorderitem->getQtyOrdered();
                }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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