1

I have a custom column in my catalog product grid for a custom attribute. I'm using the observer method of inserting the column: on core_block_abstract_prepare_layout_before:

public function appendAuthorColumn(Varien_Event_Observer $observer)
{
 $block = $observer->getBlock();
 if ($block->getType() == 'adminhtml/catalog_product_grid') {
 $authors = Mage::helper('companyx_authors')->getAuthorOptionHash();
 $block->addColumnAfter('author_id', array(
 'header' => 'Author',
 'type' => 'options',
 'index' => 'author_id',
 'options' => $authors,
 'width' => '150',
 ), 'name');
 }
}

I am updating the collection using the catalog_product_collection_load_before event:

public function addAuthorToCollection(Varien_Event_Observer $observer)
{
 $collection = $observer->getCollection();
 if (!isset($collection)) {
 return $this;
 }
 $collection->addAttributeToSelect('author_id');
 return $this;
}

Everything works as expected, except when I want to filter by product name: the author column is blank. When I filter by any other column, it is populated.

The only difference with product name is that it's a free text field. I can't think of anything else.

asked Jan 22, 2016 at 18:15

1 Answer 1

2

Instead of adding the attribute to the collection, join it:

public function addAuthorToCollection(Varien_Event_Observer $observer)
{
 $collection = $observer->getCollection();
 if (!isset($collection)) {
 return $this;
 }
 $collection->joinAttribute('author_id', 'catalog_product/author_id', 'entity_id', null, 'left'); //use this instead
 return $this;
}
7ochem
7,61516 gold badges54 silver badges82 bronze badges
answered Dec 6, 2016 at 15:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.