tags:

views:

307

answers:

1

Hi,

I would like to rewrite the collection that is returned by Mage::getResourceModel('sales/order_collection');

My goal is to rewrite this resource so that i can filter out the collection for particular Store.

Any ideas on how to do it? I tried directly rewrite collection of the sales/order module but no success. I was able to rewrite sales/order itself but not the collection, because when i call getCollection() it returns "Fatal error: Call to undefined method Mage_Sales_Model_Mysql4_Order::getCollection() "

Any idea will help.

Thank you,

Margots

A: 

I was able to rewrite by adding the following lines to the config.xml

<global>
<!-- -->
<models>
  <sales_mysql4>
            <rewrite>
<order_collection>Company_ModelName_Model_Mysql4_Order_Collection</order_collection>
            </rewrite>
   </sales_mysql4>
</models>
<!-- -->
</global>

Then I add class Collection.php in the Model/Mysql4/Order folder that extends Mage_Sales_Model_Mysql4_Order_Collection

Even though this overrides the order collection class it gives an error(Call to a member function joinAttribute() on non-object) when run the following code: Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('*')->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left');

It is not giving error if you rearrange the above line into the following 3 lines:

$collection = Mage::getResourceModel('sales/order_collection'); $collection->addAttributeToSelect('*');
$collection->joinAttribute('billing_firstname', 'order_address/firstname', 'billing_address_id', null, 'left');

I think this is a bug in the Magento. What you think?

Thanks Margots

latvian
That is not a bug...When I overwrite the method addAttributeToSelect() i called the parent::addAttributeToSelect() but never returned it. So, fixed that by adding 'return' in front of parent::addAttributeToSelect()
latvian