Magento - 根据 RMA 网格中的 EAV(自定义)属性过滤客户



我正在使用Magento 1.4.1.1和AW RMA扩展。

安装此扩展后,我在管理员中看到 RMA 请求网格和待处理 RMA 请求网格。

我希望能够根据EAV(自定义)属性过滤此网格中的请求,例如存储在customer_entity_varchar中的customer_referrer_id

该扩展有一个表aw_rma_entity,它还在其中保存customer_id。RMA 网格获取的数据如下所示:

$collection = Mage::getModel('awrma/entity')
                ->getCollection();

尝试 1

我尝试将客户实体与此表联接,如下所示:

$collection->getSelect()->join('customer_entity', 'customer_id = customer_entity.entity_id', array('entity_id' => 'customer_entity.entity_id'));

结果 1

这只显示一个没有网格的页面。如果它有效,我会尝试加入customer_entity_varchar以在customer_referrer_id字段上应用过滤器。


尝试 2

我所做的另一个尝试是先加载客户集合,然后将 RMA 实体数据联接到其中,如以下代码所示:

$collection = Mage::getResourceModel('customer/customer_collection');
$collection->joinRight('awrma/entity', 'customer_id=entity_id', array('*'));

结果 2

第二次尝试生成以下错误:

错误消息-------------------------------->项目 (Mage_Customer_Model_Customer)具有相同ID"XXX"的已存在";

尽管事实上它早些时候在销售订单网格中过滤结果的类似问题之后以这种方式对我有用

这可能不是最好的解决方案,但它很可能有效:

$collection = Mage::getModel('awrma/entity')->getCollection();
$collection->getSelect()->joinInner('customer_entity_varchar', 'customer_id=entity_id', array('attribute_id' =>'attribute_id','value'=>'value') );                
$logged_in_admin = Mage::getSingleton('admin/session')->getUser()->getEmail();  
$customer_referrer_attribute_id = //Set this equal to attribute_id FROM table eav_attribute WHERE attribute_code = "customer_referrer_id"     
$collection->addFieldToFilter('attribute_id', $customer_referrer_attribute_id );
$collection->addFieldToFilter('value', $customer_referrer_id);

最新更新