如何重写Collection?
我想重写由 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过将以下几行添加到 config.xml
然后我在扩展 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
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