2

To clarify, this is ONLY on join attributes

My layout handles are correctly setup, I can filter the inherited columns correctly.

$collection->getSelect()->join(
        array('entity_int_status' => 'catalog_product_entity_int'),
        'entity_int_status.attribute_id = 80 AND entity_int_status.entity_id = main_table.product_id',
        array('status' => 'entity_int_status.value')
);

That's how I've joined the status value from catalog_product_entity_int in my Grid. If I try filter by this column, Magento:

  1. On first attempt redirects to the dashboard, and if I then try view the page again
  2. Throws an error report, reading that the column cannot be found

I need to log out & back in again to get the page to load again (i.e forget the filters). Why are the attributes which are joined not able to be filtered?

Edit 1: Please note that this is only for filter, not sort.

1
  • To debug try setting $this->setSaveParametersInSession(false); (may stop you from have to re-login). Can you add the addColumn code for status? Also try add the table prefix for status. Also try debug the sql Mage::log($collection->getSelect()) Commented Aug 28, 2014 at 13:56

2 Answers 2

2

if suggest left joint: fist get status attribute

step1:

$status = Mage::getResourceModel('catalog/product')->getAttribute('status');

step2:

$collection->getSelect()->joinLeft(
    array('product' => $status->getBackend()->getTable()),
    'product.entity_id = main_table.product_id
    AND product.attribute_id = '.(int) $status->getAttributeId().'',
    array('status_name'=>'value')
    );

add grid colums:

 $this->addColumn('status_name', array(
        'header' => Mage::helper('yourhelper')->__('Status'),
        'align' =>'left',
        'index' => 'status_name',
        'filter_index' =>'product.value'
      ));
1

Change the code as following:

$collection->getSelect()->join('catalog_product_entity_int',
        'catalog_product_entity_int.attribute_id = 80 AND catalog_product_entity_int.entity_id = main_table.product_id',
        array('status' => 'catalog_product_entity_int.value')
);

Hope it will work.

3
  • Doesn't make a difference. Same issue persists.
    – Moose
    Commented Aug 28, 2014 at 14:41
  • are you using the code before $this->setCollection($collection); return parent::_prepareCollection();
    – MTM
    Commented Aug 28, 2014 at 14:42
  • Accepted Amit Bera's answer, this got me sorted out. And yes, to answer your question, I was declaring the code before those calls.
    – Moose
    Commented Aug 29, 2014 at 9:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.