4

I am looking to learn how to combine both name and size attributes in the app/code/local/Mage/Adminhtml/Block/Catalog/Product/Grid.php file (yes, we will make a local) so that when I view products these two will appear together separated by a space. We have separated size as an attribute and we need it to appear in the name column of the grid. What we would see now might be something like "Fruit Drink Grape" and I wish to see "Fruit Drink Grape 8 fl. oz."

6

First: It's better to make a proper rewrite of this class or add your colums via observer.

However, you could update your name column like this:

$this->addColumn('name',
        array(
            'header'=> Mage::helper('catalog')->__('Name'),
            'index' => array('name', 'size'),
            'type' => 'concat',
            'filter_index' => "CONCAT(name, ' ', size)"
    ));
  • Thank you for your answer. However, it did not work. Any suggestions? Yes, I did refresh cache. – Scot Oct 10 '15 at 23:21
  • Update. I decided to flush cache too. Now what I have is the actual size attribute number concatenated at the end of the name, not the actual size label. So, items have a 4-digit number and the end with no space. – Scot Oct 10 '15 at 23:24
  • Hi, maybe you can update you question with the collection that your grid uses. Maybe there is a join missing to retrieve the attribute value? – Anna Völkl Oct 12 '15 at 18:57
2

You can add below code in your admin grid file:

$this->addColumn('name', 
    array(
        'header'       => $this->__('Name'),
        'sortable'     => true,
        'index'        => array('name', 'size'),
        'type'         => 'concat',
        'separator'    => ' ',
        'filter_index' => "CONCAT(name, ' ', size)",
        'width'        => '140px',
    )
);
  • FYI This answer had some additional detail that was helpful – shaune Jan 11 '19 at 15:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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