0

The Magento sales/order_item_collection is showing the same order multiple times,

$salesCollection = Mage::getResourceModel('sales/order_item_collection')
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
        ->load();

    foreach($salesCollection as $order){
        if(!empty($order)){
         // my order details ...
        }
    }

This is what im getting after printing the following methods

getIncrementId() - getOrderId() - getId() - getStatus()

100001519-1519-5083-Ordered
100001519-1519-5084-Ordered
100001519-1519-5085-Ordered
100001519-1519-5086-Ordered
100001519-1519-5087-Ordered
100001519-1519-5088-Ordered
100001519-1519-5089-Ordered
100001519-1519-5090-Ordered
100001519-1519-5091-Ordered
100001519-1519-5092-Ordered
100001519-1519-5093-Ordered
100001520-1520-5094-Ordered
100001520-1520-5095-Ordered
100001520-1520-5096-Ordered
100001520-1520-5097-Ordered
100001520-1520-5098-Ordered
100001520-1520-5099-Ordered

What i noticed is the order #100001519 has 11 items & #100001520 has 6 items. Is there anything wrong with my code ?

1 Answer 1

0

add another filter to collection:

addAttributeToFilter('parent_id',0) and will proper items listing

1
  • Im getting an error when i tried to filter the collection with parent_id : Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'parent_id' in 'where clause'
    – Shan
    Commented Oct 17, 2017 at 6:59

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.