2

I have a custom multiselect product attribute:

eav_attribute:

   attribute_id: 290
 entity_type_id: 4
 attribute_code: my_attribute_code
attribute_model: NULL
  backend_model: eav/entity_attribute_backend_array
   backend_type: text
  backend_table: NULL
 frontend_model: NULL
 frontend_input: multiselect
 frontend_label: Style
 frontend_class: NULL
   source_model: NULL
    is_required: 0
is_user_defined: 0
  default_value: 
      is_unique: 0
           note: NULL


catalog_eav_attribute:

                     attribute_id: 290
          frontend_input_renderer: NULL
                        is_global: 0
                       is_visible: 1
                    is_searchable: 0
                    is_filterable: 0
                    is_comparable: 0
              is_visible_on_front: 0
         is_html_allowed_on_front: 0
          is_used_for_price_rules: 0
          is_filterable_in_search: 0
          used_in_product_listing: 1
                 used_for_sort_by: 0
                  is_configurable: 1
                         apply_to: NULL
    is_visible_in_advanced_search: 0
                         position: 0
               is_wysiwyg_enabled: 0
          is_used_for_promo_rules: 0
                    search_weight: 1

When i reindex i can see the column being added to the flat tables. But the value is always NULL

What am i not doing correctly?

  • Looks like the attribute configuration is right. Try rebuilding the 'Product Attributes' index before the flat index. – Marius May 9 '14 at 13:31
  • This has been done. I have also performed a full reindex several times. – Marty Wallace May 9 '14 at 13:37
  • 1
    Try to see if the products have values set for that attribute at store view level. Maybe you have values for the 'default values' but you don't have values for the store view. – Marius Jun 27 '14 at 12:03
  • +1 to Marius answer, this applies to M2 in the same way. Saved me some time debugging as I hadn't considered to look at store view level, since it was a single store instance. – Joseph McDermott Jul 31 '18 at 14:31
3

Your attribute needs a source model to provide the select statement. For example see Mage_Eav_Model_Entity_Attribute_Source_Table::getFlatUpdateSelect():

/**
 * Retrieve Select For Flat Attribute update
 *
 * @param int $store
 * @return Varien_Db_Select|null
 */
public function getFlatUpdateSelect($store)
{
    return Mage::getResourceModel('eav/entity_attribute_option')
        ->getFlatUpdateSelect($this->getAttribute(), $store);
}

This returns the select statement from Mage_Eav_Model_Resource_Entity_Attribute_Option::getFlatUpdateSelect():

/**
 * Retrieve Select for update Flat data
 *
 * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
 * @param int $store
 * @param bool $hasValueField flag which require option value
 * @return Varien_Db_Select
 */
public function getFlatUpdateSelect(Mage_Eav_Model_Entity_Attribute_Abstract $attribute, $store,
    $hasValueField = true
) {
    $adapter        = $this->_getReadAdapter();
    $attributeTable = $attribute->getBackend()->getTable();
    $attributeCode  = $attribute->getAttributeCode();
    $joinConditionTemplate = "%s.entity_id = %s.entity_id"
        . " AND %s.entity_type_id = " . $attribute->getEntityTypeId()
        . " AND %s.attribute_id = " . $attribute->getId()
        . " AND %s.store_id = %d";
    $joinCondition = sprintf($joinConditionTemplate, 'e', 't1', 't1', 't1', 't1',
        Mage_Core_Model_App::ADMIN_STORE_ID);
    if ($attribute->getFlatAddChildData()) {
        $joinCondition .= ' AND e.child_id = t1.entity_id';
    }
    $valueExpr = $adapter->getCheckSql('t2.value_id > 0', 't2.value', 't1.value');
    /** @var $select Varien_Db_Select */
    $select = $adapter->select()
        ->joinLeft(array('t1' => $attributeTable), $joinCondition, array())
        ->joinLeft(array('t2' => $attributeTable),
            sprintf($joinConditionTemplate, 'e', 't2', 't2', 't2', 't2', $store),
            array($attributeCode => $valueExpr));
    if (($attribute->getFrontend()->getInputType() != 'multiselect') && $hasValueField) {
        $valueIdExpr = $adapter->getCheckSql('to2.value_id > 0', 'to2.value', 'to1.value');
        $select
            ->joinLeft(array('to1' => $this->getTable('eav/attribute_option_value')),
                "to1.option_id = {$valueExpr} AND to1.store_id = 0", array())
            ->joinLeft(array('to2' => $this->getTable('eav/attribute_option_value')),
                $adapter->quoteInto("to2.option_id = {$valueExpr} AND to2.store_id = ?", $store),
                array($attributeCode . '_value' => $valueIdExpr));
    }
    if ($attribute->getFlatAddChildData()) {
        $select->where("e.is_child = ?", 0);
    }
    return $select;
}

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.