Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Module for create products attributes no work
 
roilld
Jr. Member
 
Total Posts:  4
Joined:  2011-06-30
 

I have made a module to create a product attribute following the tutorial “Installing Custom Attributes with Your Module”. Magento loads the module and I can see it and enable/disable it in “system>configuration>advanced”. The problem is that the attribute is not created and Magento does not display errors during execution and does not write reports in the system.log file.
Please can someone help me? This is the content of the four files that I created:

.../app/etc/modules/NDB_NdbAttr.xml

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

.../app/code/local/NDB/NdbAttr/etc/config.xml

<?xml version="1.0"?>
<config>
    <global>
        <
modules>
            <
ndb_ndbattr>
                <
version>1.0.0</version>
                <class>
NDB_NdbAttr_Model</class>
            </
ndb_ndbattr>
        </
modules>

        <
resources>
            <
ndbattr_setup>
                <
setup>
                    <
module>NdbAttr</module>
                    <class>
NDB_NdbAttr_Model_Resource_Eav_Mysql4_Setup</class>
                </
setup>
                <
connection>
                    <use>
core_setup</use>
                </
connection>
            </
ndbattr_setup>
            
            <
ndbattr_write>
              <
connection>
                <use>
core_write</use>
              </
connection>
            </
ndbattr_write>
            
            <
ndbattr_read>
              <
connection>
                <use>
core_read</use>
              </
connection>
            </
ndbattr_read>
        </
resources>
    </global>
    
    <
adminhtml>
        <
events>
            <
catalog_product_prepare_save>
                <
observers>
                    <
ndbattr>
                        <class>
ndbattr/observer</class>
                        <
method>productSave</method>
                    </
ndbattr>
                </
observers>
            </
catalog_product_prepare_save>
        </
events>
    </
adminhtml>
</
config>

.../app/code/local/NDB/NdbAttr/sql/ndbattr_setup/mysql4-install-1.0.0.php

$installer $this;
$installer->installEntities();

.../app/code/local/NDB/NdbAttr/Model/Resource/Eav/Mysql4/Setup.php

class NDB_NdbAttr_Model_Resource_Eav_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup
{
    
public function getDefaultEntities()
    
{
        
return array(
            
'catalog_product' => array(
                
'entity_model'                    => 'catalog/product',
                
'attribute_model'                => 'catalog/resource_eav_attribute',
                
'table'                            => 'catalog/product',
                
'additional_attribute_table'    => 'catalog/eav_attribute',
                
'entity_attribute_collection'    => 'catalog/product_attribute_collection',
                
'attributes'        => array(
                    
'ndb_attr' => array(
                        
'group'             => 'General',
                        
'label'             => 'NDB Attribute',
                        
'type'              => 'varchar',
                        
'input'             => 'text',
                        
'default'           => '',
                        
'class'             => '',
                        
'backend'           => '',
                        
'frontend'          => '',
                        
'source'            => '',
                        
'global'            => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                        
'visible'           => true,
                        
'required'          => false,
                        
'user_defined'      => false,
                        
'searchable'        => false,
                        
'filterable'        => false,
                        
'comparable'        => false,
                        
'visible_on_front'  => false,
                        
'visible_in_advanced_search' => false,
                        
'unique'            => false
                    
),
               )
           ), 
      );
    
}
}

Thanks for the help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
roilld
Jr. Member
 
Total Posts:  4
Joined:  2011-06-30
 

I have deleted and disabled the EAV cache, but the problem persists. I’ve seen anything that could be important, the core_resource table does not have any record with “value=ndbattr_setup” on “code” field; can this evidence be helpful?
Thanks for the help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
roilld
Jr. Member
 
Total Posts:  4
Joined:  2011-06-30
 

I made a test to make sure that all files of the module are executed. In the file .../app/code/local/NDB/NdbAttr/sql/ndbattr_setup/mysql4-install-1.0.0.php I wrote:

Mage::log('mysql4-install-1.0.0.php called');
and in the file .../app/code/local/NDB/NdbAttr/Model/Resource/Eav/Mysql4/Setup.php I wrote:
Mage::log('Setup.php called');
hoping to find these two log message in the system.log file but I did not find anything in this file. This means that the files have not been executed? Then what is the problem of my module?
 
Magento Community Magento Community
Magento Community
Magento Community
 
roilld
Jr. Member
 
Total Posts:  4
Joined:  2011-06-30
 

Finally I solved the problem, in the config.xml file I have put the tag “modules” outside of the tag “global” and I rewrote some lines that were wrong. This is the new file:

<?xml version="1.0"?>
<config>
    <
modules>
        <
NDB_NdbAttr>
            <
version>1.0.0</version>
        </
NDB_NdbAttr>
    </
modules>

    <global>
        <
resources>
            <
ndbattr_setup>
                <
setup>
                    <
module>NDB_NdbAttr</module>
                    <class>
NDB_NdbAttr_Model_Resource_Eav_Mysql4_Setup</class>
                </
setup>
                <
connection>
                    <use>
core_setup</use>
                </
connection>
            </
ndbattr_setup>
            
            <
ndbattr_write>
              <
connection>
                <use>
core_write</use>
              </
connection>
            </
ndbattr_write>
            
            <
ndbattr_read>
              <
connection>
                <use>
core_read</use>
              </
connection>
            </
ndbattr_read>
        </
resources>
    </global>
    
    <
adminhtml>
        <
events>
            <
catalog_product_prepare_save>
                <
observers>
                    <
ndbattr>
                        <class>
ndbattr/observer</class>
                        <
method>productSave</method>
                    </
ndbattr>
                </
observers>
            </
catalog_product_prepare_save>
        </
events>
    </
adminhtml>
</
config>
 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top