如何重写Collection?

发布于 2024-08-24 23:14:52 字数 334 浏览 3 评论 0原文

我想重写由 Mage::getResourceModel('sales/order_collection'); 返回的集合;

我的目标是重写此资源,以便我可以筛选出特定商店的集合。

关于如何做到这一点有什么想法吗?我尝试直接重写销售/订单模块的集合,但没有成功。我能够重写销售/订单本身,但不能重写集合,因为当我调用 getCollection() 时,它会返回

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

几度春秋 2024-08-31 23:14:52

我能够通过将以下几行添加到 config.xml

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

然后我在扩展 Mage_Sales_Model_Mysql4_Order_Collection 的 Model/Mysql4/Order 文件夹中添加类 Collection.php

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

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

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

我认为这是 Magento 中的一个错误。你认为呢?

谢谢玛戈茨

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文