1

Following this tutorial, I try to get values of multiselect attribute in a product grid.

Products have some selected values for this attribute and the 'filter_condition_callback' for this column work.

In the renderer I use below code but in the grid I get an empty list.

I hope someone can help.

public function render(Varien_Object $row) {

    $colors=explode(',',$row->getColors());
    $suppstr="";
    if(count($colors)>0)
    {
        $suppstr="<ul>";
        foreach($colors as $value)
        {
            $attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'colors');
            if ($attribute->usesSource()) {
            $suppstr   .= "<li>".$attribute->getSource()->getOptionText($value)."</li>";
            }

        }
        $suppstr   .= "</ul>";

    }
      return $suppstr;    

}
  • did you try with removing if ($attribute->usesSource()) { condition? – Jaimin Sutariya Mar 24 '17 at 14:07
  • not before your comment, I get the same result <td><ul><li></li></ul></td> – vhanahrni Mar 24 '17 at 14:11
  • getSource()->getAllOptions() output all options – vhanahrni Mar 24 '17 at 14:16
  • Try var_dump($colors) to check if you get data. – Jaimin Sutariya Mar 24 '17 at 14:19
  • no i get an empty array – vhanahrni Mar 24 '17 at 14:26
0

It seems like you dont have set option values for your store. Try,

$storeId   = 0; // Your Store Id
$suppstr   .= "<li>".$attribute->getSource()->setStoreId(0)->getOptionText($value)."</li>";
  • the grid block extends Mage_Adminhtml_Block_Widget_Grid and in _prepareCollection() I have Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID); – vhanahrni Mar 24 '17 at 14:55
  • with your answer i get : Call to undefined method Mage_Eav_Model_Entity_Attribute_Source_Table::setStoreId() – vhanahrni Mar 24 '17 at 14:57

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.