Ozair Kafray
Ozair Kafray

Reputation: 13539

Magento - filtering customers based on an EAV (custom) attribute in RMA Grid

I am using Magento 1.4.1.1 and the AW RMA extension over it.

With this extension installed I see an RMA requests grid and Pending RMA requests grid in admin.

I want to be able to filter requests in this grid based on an EAV (custom) attribute e.g., customer_referrer_id which is stored in customer_entity_varchar

The extension has a table aw_rma_entity in which it also keeps customer_id. The RMA Grid fetches data like this:

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

ATTEMPT 1

I have attempted to join the customer entity with this table as follows:

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

RESULT 1

This just shows a page with no grid. If it had worked I would have then attempted to join customer_entity_varchar to apply the filter on the customer_referrer_id field.


ATTEMPT 2

The other attempt I have made is to load the customer collection first and then join RMA entity data to it as in the following code:

$collection = Mage::getResourceModel('customer/customer_collection');

$collection->joinRight('awrma/entity', 'customer_id=entity_id', array('*'));

RESULT 2

The second attempt generates the following error:

Error Message--------------------------------> Item (Mage_Customer_Model_Customer) with the same id "XXX" already exist";

This is despite of the fact that it had worked for me earlier in this way after a similar question for filtering results in the Sales Orders Grid

Upvotes: 3

Views: 2206

Answers (1)

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 8856

This is probably not the best solution, but it will most likely work:

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

Upvotes: 4

Related Questions