1

I tried to create a shopping module with help, when I install the module it should add a custom attribute but for some reason it is not working

I have this structure:

enter image description here

config.xml is simple and just telling where to find the resource and the module name:

 <?xml version="1.0"?>
<config>
  <modules>
    <Cart_Shopping>
      <version>1.0.0</version>
      <title> Product Message</title>
    </Cart_Shopping>
  </modules>
  <global>
    <resources>
      <shop_setup>
        <setup>
          <module>Cart_Shopping</module>
          <class>Mage_Eav_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </shop_setup>
      <shop_write>
        <connection>
          <use>core_write</use>
        </connection>
      </shop_write>
    </resources>
  </global>
  <adminhtml>
    <fieldsets>
      <cart_message>
        <create>1</create>
        <update>1</update>
      </cart_message>
    </fieldsets>
  </adminhtml>
</config>

here is installer,the mysql4-install-1.0.0

$installer = Mage::getResourceModel('catalog/setup', 'catalog_setup');
Mage::log("negin", null, 'mylogfile.log');
$installer->startSetup();
$installer->addAttribute('catalog_product', 'cart_message', array(
  'type'              => 'varchar',
  'backend'           => '',
  'frontend'          => '',
  'label'             => 'Message in Cart',
  'input'             => 'select',
  'class'             => '',
  'source'            => 'catalog/product_attribute_source_layout',
  'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
  'visible'           => true,
  'required'          => false,
  'user_defined'      => false,
  'default'           => '',
  'searchable'        => true,
  'filterable'        => false,
  'comparable'        => false,
  'visible_on_front'  => true,
  'unique'            => false,
  'group'             => 'General'
));
$installer->endSetup();

also app/etc/modules file which is reading the codepool of local:

  <config>
    <modules>
      <Cart_Shopping>
        <active>true</active>
        <codePool>local</codePool>
        <version>1.0.0</version>
      </Cart_Shopping>
    </modules>
  </config>

would you please tell me what is wrong in my configuration?

1 Answer 1

1

you config.xml should be like this. And you should have to include Namespace in your config.xml

<config>
    <modules>
        <Namespace_Shopping>
            <version>1.0.0</version>
        </Namespace_Shopping>
    </modules>
    <global>          
      <resources>
            <shop_setup>
                <setup>
                    <module>Namespace_Shopping</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </shop_setup>
       </resources>            
    </global>
</config>

make sure your main configuration file for module should be content namespace as well

Module configuration file should be as

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

EDIT

Also make sure core_resource table should not content your module version entry with 1.0.0. if it is there then your installer file wont execute.

hope, it works for you.

6
  • It didn't work for me, I am updating the question with the suggestion I have a question why I should define class of <class>Mage_Eav_Model_Entity_Setup</class> here? in my installer i am defining the resource
    – Nickool
    Apr 13, 2015 at 17:01
  • you have to create attribute and for eav type setup class must be use to call function from this. Also make sure core_resource table should not content your module version entry with 1.0.0. if it is there then your installer file wont execute.
    – liyakat
    Apr 14, 2015 at 4:08
  • omg! thank you thank you thank you! I did deleted that module version from the table and now I do not have any problem!
    – Nickool
    Apr 14, 2015 at 18:04
  • please also update the answer so everybody would know they should delete the module version entry in core_resource
    – Nickool
    Apr 14, 2015 at 18:05
  • @NeginNickparsa,updated.you have sufficient reputation to make vote up. it would be great to put trust on my answer as well
    – liyakat
    Apr 15, 2015 at 4:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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