1

I wanted orders collection by shipping region id. What I have done:

$order = Mage::getModel('sales/order')->getCollection()->getLastItem();
print_r($order->getData());

When I do print_r the order data, so region_id is not accessible otherwise I would have used addAttributeToFilter() or addFieldToFilter().

region_id is accessible on the print_r($order->getShippingAddress()->getData());

How can I add region_id in the filter?

Edited

I want something like this

Mage::getModel('sales/order')->getCollection()->addFieldToFilter('region_id',517)

all orders whose shipping region id is 517.

1 Answer 1

2

You can get filter the order collection by region_id like this

$ordercollection = Mage::getModel('sales/order')->getCollection();
$ordercollection->getSelect()->joinLeft(array('sfoa' => 'sales_flat_order_address'),'main_table.entity_id = sfoa.parent_id',array('region_id'=>'sfoa.region_id'));
$ordercollection->addFieldToFilter('region_id',array('eq'=>'32'));
echo "<pre>";print_r($ordercollection->getData());

Note : 32 here is the region_id by which you can filter your orders.

2
  • no.. i want something like this Mage::getModel('sales/order')->getCollection()->addFieldToFilter('region_id',517) Commented Jun 12, 2015 at 11:29
  • Check my updated answer Commented Jun 12, 2015 at 11:42

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.