0

I'm trying to add a custom product attribute called popularity a decimal so I can use it for sorting products on the catalog pages.

I've created a module for this and while I can see the module is installed in System > Config > Advanced their is no record of the table in the core_resource table.

I have tried clearing the cache & re-indexing.

app/etc/modules/Namespace_PopularityAttribute.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_PopularityAttribute>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Namespace_PopularityAttribute>
  </modules>
</config>

app/code/local/Namespace/PopularityAttribute/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_PopularityAttribute>
      <version>0.1.0</version>
    </Namespace_PopularityAttribute>
  </modules>
  <global>
    <helpers>
      <popularityattribute>
        <class>Namespace_PopularityAttribute_Helper</class>
      </popularityattribute>
      <resources>
        <popularityattribute_setup>
          <setup>
            <module>PopularityAttribute</module>
            <class>PopularityAttribute_Model_Resource_Eav_Mysql4_Setup</class>
          </setup>
          <connection>
            <use>core_setup</use>
          </connection>
        </popularityattribute_setup>
        <popularityattribute_write>
          <connection>
            <use>core_write</use>
          </connection>
        </popularityattribute_write>
        <popularityattribute_read>
          <connection>
            <use>core_read</use>
          </connection>
        </popularityattribute_read>
      </resources>
    </helpers>
  </global>
</config> 

app/code/local/Namespace/PopularityAttribute/sql/popularityattribute_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'popularity', array(
    'group'         => 'Our Custom Group',
    'input'         => 'text',
    'type'          => 'decimal',
    'label'         => 'Popularity',
    'note' => 'Will be used as the default method of sorting products on the category pages in descending order.',
    'default' => true,
    'default_value' => 0,
    'sort_order' => 2,
    'visible'       => false,
    'required'      => false,
    'user_defined' => false,
    'searchable' => false,
    'filterable' => false,
    'comparable'    => false,
    'visible_on_front' => false,
    'visible_in_advanced_search'  => false,
    'is_html_allowed_on_front' => false,
    'global'     => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'used_in_product_listing' => true,
));
$installer->endSetup();
1

Try this:

app/etc/modules/Namespace_PopularityAttribute.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_PopularityAttribute>
      <active>true</active>
      <codePool>local</codePool>
     </Namespace_PopularityAttribute>
  </modules>
</config>

app/code/local/Namespace/PopularityAttribute/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Namespace_PopularityAttribute>
      <version>0.1.0</version>
    </Namespace_PopularityAttribute>
  </modules>
  <global>
    <resources>
            <popularityattribute_setup>
                <setup>
                    <module>Namespace_PopularityAttribute</module>
                    <class>Mage_Catalog_Model_Resource_Setup</class>
                </setup>
            </popularityattribute_setup>
     </resources>
  </global>
</config>

app/code/local/Namespace/PopularityAttribute/sql/popularityattribute_setup/mysql4-install-0.1.0.php

<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute('catalog_product', 'popularity', array(
    'input'         => 'text',
    'type'          => 'decimal',
    'label'         => 'Popularity',
    'default'           => true,
    'default_value'     => 0,
    'sort_order'        => 2,
    'visible'           => false,
    'required'          => false,
    'user_defined'      => false,
    'searchable'        => false,
    'filterable'        => false,
    'comparable'        => false,
    'visible_on_front'      => false,
    'visible_in_advanced_search'=> false,
    'is_html_allowed_on_front'  => false,
    'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
    'used_in_product_listing'   => true,
    'note'          => 'Will be used as the default method of sorting products on the category pages in descending order.',

));
$installer->endSetup();

Note: clearing the cache & re-indexing.

  • this doesn't actually add the popularity attribute properly. I can't see it on the admin panel, on manage products or manage attributes pages – Holly Mar 9 '16 at 13:03
  • I can see the module version in core_resource and the attribute in the eav_attribute tables but it is not showing up on the manage product / attribute pages – Holly Mar 9 '16 at 18:36
  • Updated ans pls check now – Abdul Mar 10 '16 at 4:36

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.