如何在 Magento 中加入收藏? [英] How to join collections in Magento?
问题描述
我正在尝试使用产品加入自定义集合,以在管理网格小部件中显示产品名称(不仅仅是 ID).到目前为止,我找不到正确的语法.
I am trying to join a custom collection with products to show the product name (not just the id) in the admin grid widget. So far i can't find the correct syntax.
我可以通过以下方式检索具有产品名称的产品:
I am able to retrieve the products with the product name by the following:
Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name');
Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name');
我可以通过以下方式检索我的自定义集合:
and i can retrieve my custom collection with:
Mage::getResourceModel('xyz_mymodule/model_collection');
Mage::getResourceModel('xyz_mymodule/model_collection');
如何加入这两者,使模块集合成为主集合,而 $model->getId() 返回的 id 仍然是我的自定义集合的 id?
How do i join the two so that the module collection is the primary collection and the id as returned by $model->getId() is still the id of my custom collection?
推荐答案
这里有一个工作示例:
$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->join( array('order_item'=> 'sales_flat_order_item'), 'order_item.order_id = main_table.entity_id', array('order_item.sku'));
这篇关于如何在 Magento 中加入收藏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!