如何重写集合? [英] How to rewrite Collection?

查看:144
本文介绍了如何重写集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想重写 Mage :: getResourceModel('sales / order_collection');

返回的集合

我的目标是重写这个资源,以便我可以过滤掉特定商店的集合。



有关如何做的任何想法吗?我试过直接重写销售/订单模块的收集,但没有成功。我可以重写销售/订单本身,但不是集合,因为当我调用 getCollection()它返回


致命错误:调用未定义的方法
Mage_Sales_Model_Mysql4_Order :: getCollection()



解决方案

p>我可以通过添加以下行到config.xml中重写。

 < global> 
<! - - >
< models>
< sales_mysql4>
< rewrite>
< order_collection> Company_ModelName_Model_Mysql4_Order_Collection< / order_collection>
< / rewrite>
< / sales_mysql4>
< / models>
<! - - >
< / global>然后我将类Collection.php添加到扩展Mage_Sales_Model_Mysql4_Order_Collection的Model / Mysql4 / Order文件夹中。

>

运行以下代码时,即使覆盖了订单集合类,也会产生错误(调用非对象的成员函数joinAttribute()):
Mage: :getResourceModel('sales / order_collection') - > addAttributeToSelect('*') - > joinAttribute('billing_firstname','order_address / firstname','billing_address_id',null,'left');



如果将上面的行重新排列为以下3行,则不会产生错误:



$ collection = Mage :: getResourceModel order_collection');
$ collection-> addAttributeToSelect('*');

$ collection-> joinAttribute('billing_firstname','order_address / firstname','billing_address_id',null,'left'); / p>

我认为这是Magento中的一个错误。您认为吗?



感谢Margots


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()

解决方案

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

这篇关于如何重写集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆