如何在Magento中加入收藏?

如何在Magento中加入收藏?,magento,join,collections,grid,Magento,Join,Collections,Grid,我正在尝试加入一个定制的产品集合,以便在管理网格小部件中显示产品名称(而不仅仅是id)。到目前为止,我找不到正确的语法 我可以通过以下方式检索具有产品名称的产品: Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name') 我可以通过以下方式检索我的自定义收藏: Mage::getResourceModel('xyz_mymodule/model_collection') 如何将这两者结合起来,

我正在尝试加入一个定制的产品集合,以便在管理网格小部件中显示产品名称(而不仅仅是id)。到目前为止,我找不到正确的语法

我可以通过以下方式检索具有产品名称的产品:

Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('name')

我可以通过以下方式检索我的自定义收藏:

Mage::getResourceModel('xyz_mymodule/model_collection')


如何将这两者结合起来,使模块集合成为主要集合,并且$model->getId()返回的id仍然是我的自定义集合的id?

这里有一个工作示例:

$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'));

只是快速更正,我不得不在表名上添加引号: 数组('order\u item'=>'sales\u flat\u order\u item'), 另外,不需要getSelect(),因为第三个参数是属性列表。 最后一个参数指定要使用的联接类型

我的版本如下:



当我把桌子放进去的时候,这正是我需要的。我使用了:$collection->getSelect()->join(数组('product'=>'catalog\u product\u flat\u 1'),'product.entity\u id=main\u table.product\u fk',数组('*',“product\u name”=>“product.name”,“container\u name”=>“main\u table.name”,);在中硬编码表名?在使用前缀的情况下,这似乎会中断。应该使用Mage::getSingleton('core/resource')->getTableName('sales/order')来利用任何社区/本地覆盖以及处理前缀。@BetoCastilo您忽略了这样一个事实,即有时magento的
join
joinTable
函数会比正常查询减少记录数,类似于此代码
$collection->joinTable(数组('sfoi'=>'sales/order\u item'),'product\u id=entity\u id',数组('last\u salled\u date'=>'MAX(sfoi.created\u at'),'total\u qty\u salled'=>'SUM(sfoi.qty\u ordered')$集合->getSelect()->组('e.entity_id'),如何解决这个问题?谢谢你的提示,请随意编辑答案:D@VickyDevThanks,我错过了那些引用:)
$collection = Mage::getResourceModel($this->_getCollectionClass());
$collection->join(array('order'=> 'sales/order'),'order.entity_id=main_table.entity_id', array('po_number'=>'po_number', 'imi_customer_email' =>'imi_customer_email'), null,'left');
$this->setCollection($collection);`