3

I have this piece of code:

public function getAllOpenOrders() {
     $collection = Mage::getResourceModel('sales/order_item_collection');
                $collection->getSelect()->join( array('orders'=> sales_flat_order), 'orders.entity_id = main_table.order_id', array('orders.status'));
                $collection->addAttributeToFilter('orders.status',
                    array( 
                        array('eq' => 'pending'),
                        array('eq' => 'processing'),
                    )
                );
}

When I var_dump the first object in a foreach loop is see the object has the following data.

["status"]=> string(7) "pending"

But when I do echo $object->getStatus(); it returns a different value. It returns Ordered when I echo and string(7) "Ordered" when I var_dump it.

What am I missing, or what am I doing wrong?

EDIT:

The foreach loop in my template file

<?php $orders = $this->getAllOpenOrders(); ?>

<?php foreach($orders as $order): ?>
     <?php var_dump($order->getStatus()); ?>
<?php endforeach; ?>
  • Can u please share code inside loo[ – Amit Bera Aug 24 '16 at 19:30
  • @AmitBera sure, just added the loop – Akif Aug 24 '16 at 19:35
3

This is because getStatus() of order items (this is what your collection returns!) is an actual method and not a magic getter:

public function getStatus()
{
    return $this->getStatusName($this->getStatusId());
}

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.