9

Magento Not adding custom Attribute to flat table..... I have a market place extension...which have some attribute but some attributes not adding to flat table...due to my extension not working....

attribute setting is...

$catalogEavSetup->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'approval', array(
    'group' => 'General',
    'sort_order' => 21,
    'type' => 'int',
    'backend' => '',
    'frontend' => '',
    'label' => 'Approval',
    'note' => '',
    'input' => 'select',
    'class' => '',
    'source' => 'vendorsproduct/source_approval',
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
    'visible' => true,
    'required' => false,
    'user_defined' => false,
    'default' => '1',
    'visible_on_front' => false,
    'unique' => false,
    'is_configurable' => false,
    'used_for_promo_rules' => false,
    'used_in_product_listing'  => true,
));

whole setting is correct..but due to mysql limit 65536...some attributes is not adding to flat tables... I need to know that how to add these attribute in flat tables...

16

You need to enable visible_on_front to push into the Catalog Flat tables. Category flat tables are affected by used_in_product_listing.

As for the limit in MySQL I believe that is a separate question and should be migrated out as a separate Q&A.

  • its not coming in flat table....is there any good way to indexing or getting value of attribute – Deepak Rai Sep 2 '15 at 17:05
  • 6
    Totally wrong. You only need to enable "used_in_product_listing" to make it appear on catalog_product_flat table. – Kingshuk Deb Jul 21 '16 at 7:44
  • Agreed with @KingshukDeb i just tested and enabling "used_in_product_listing" will make the attribute show in catalog_product_flat table – Long M K Nguyễn Jul 30 '18 at 22:27
  • I still have the same problem. The attribute is working fine, products do have values, a lot actually. But though, no data in the flat catalog :( – Keenora Fluffball Apr 12 at 12:14
  • If you are in the same case than @DeepakRai, you have defined your own source model. If so, you need to implement 2 methods to add the attribute is flat table. I added an answer to explain how. – Cladiuss Jul 15 at 8:27
4

Another way to add attributes to flat tables is to set them in your config.xml frontend section ...

<product>
    <collection>
        <attributes>
            <attribute_code/>
        </attributes>
    </collection>
</product>
2

For me it was enough to set only "used_in_product_listing" => true

'attribute_code' => array(
    'type'                          => 'int',
    'input'                         => 'select',
    'global'                        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'required'                      => 0,
    'is_configurable'               => 0,
    'visible_in_advanced_search'    => 0,
    'comparable'                    => 0,
    'is_html_allowed_on_front'      => 0,
    'user_defined'                  => 1,
    'used_in_product_listing'       => 1,
    'source'                        => 'eav/entity_attribute_source_boolean',
)

and run catalog_product_flat reindex to get product attribute in flat table:

php shell/indexer.php --reindex catalog_product_flat
  • Does it also work on core Magento attributes (quantity_and_stock_status specifically)? – Mateusz Serotiuk Jun 30 '17 at 11:22
  • No. Stock is a separate entity in Magento and it is not included into flat tables of catalog_product_flat. So you need to use separate Magento model to get qty. – vpodorozh Jun 7 '18 at 8:37
1

As already told in other answers, you need used_in_product_listing to be set to 1.

But as you defined a source model ('source' => 'vendorsproduct/source_approval',), you may need an extra step :

In your source model, you most probably extended Mage_Eav_Model_Entity_Attribute_Source_Abstract and already implemented getAllOptions.

But you also need to implements two more methods :

  • getFlatColums (this is not a typo, there is no "n")
  • getFlatUpdateSelect

To implement them, take example from the Magento native source model Mage_Eav_Model_Entity_Attribute_Source_Boolean.

Here is an example of what you should end up with :

class Vendor_Products_Model_Source_Approval
    extends Mage_Eav_Model_Entity_Attribute_Source_Abstract
{
    /**
     * Option values
     */
    const VALUE_APPROVED = 1;
    const VALUE_NOT_APPROVED = 0;


    /**
     * Retrieve all options array
     *
     * @return array
     */
    public function getAllOptions()
    {
        if (is_null($this->_options)) {
            $this->_options = array(
                array(
                    'label' => Mage::helper('vendorsproduct')->__('Yes'),
                    'value' => self::VALUE_APPROVED
                ),
                array(
                    'label' => Mage::helper('vendorsproduct')->__('No'),
                    'value' => self::VALUE_NOT_APPROVED
                ),
            );
        }
        return $this->_options;
    }

    /**
     * Retrieve option array
     *
     * @return array
     */
    public function getOptionArray()
    {
        $_options = array();
        foreach ($this->getAllOptions() as $option) {
            $_options[$option['value']] = $option['label'];
        }
        return $_options;
    }

    /**
     * Get a text for option value
     *
     * @param string|integer $value
     * @return string
     */
    public function getOptionText($value)
    {
        $options = $this->getAllOptions();
        foreach ($options as $option) {
            if ($option['value'] == $value) {
                return $option['label'];
            }
        }
        return false;
    }

    /**
     * Retrieve flat column definition
     *
     * @return array
     */
    public function getFlatColums()
    {
        $attributeCode = $this->getAttribute()->getAttributeCode();
        $column = array(
            'unsigned'  => false,
            'default'   => null,
            'extra'     => null
        );

        if (Mage::helper('core')->useDbCompatibleMode()) {
            $column['type']     = 'tinyint(1)';
            $column['is_null']  = true;
        } else {
            $column['type']     = Varien_Db_Ddl_Table::TYPE_SMALLINT;
            $column['length']   = 1;
            $column['nullable'] = true;
            $column['comment']  = $attributeCode . ' column';
        }

        return array($attributeCode => $column);
    }

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

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.