1

I tried to many ways to do this, but isn't executing.

app/code/local/Devra/Address/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Devra_Address>
            <version>0.1.0</version>
        </Devra_Address>
    </modules>
    <global>
        <models>
            <address>
                <class>Devra_Address_Model</class>
                <resourceModel>address_mysql4</resourceModel>
            </address>
            <address_mysql4>
                <class>Devra_Address_Model_Mysql4</class>
                <entities>
                    <address>
                        <table>address</table>
                    </address>
                </entities>
            </address_mysql4>
        </models>
        <resources>
            <address_setup>
                <setup>
                    <module>Devra_Address</module>
                    <class>Mage_Customer_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </address_setup>
            <address_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </address_write>
            <address_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </address_read>
        </resources>
        <blocks>
            <address>
                <class>Devra_Address_Block</class>
            </address>
        </blocks>
        <helpers>
            <address>
                <class>Devra_Address_Helper</class>
            </address>
        </helpers>
        <fieldsets>
            <sales_convert_quote_address>
                <street_new>
                    <to_order_address>*</to_order_address>
                </street_new>
                <street_number>
                    <to_order_address>*</to_order_address>
                </street_number>
                <rut>
                    <to_order_address>*</to_order_address>
                </rut>
                <dpto_off>
                    <to_order_address>*</to_order_address>
                </dpto_off>
            </sales_convert_quote_address>
            <customer_address>
                <street_new>
                    <to_quote_address>*</to_quote_address>
                </street_new>
                <street_number>
                    <to_quote_address>*</to_quote_address>
                </street_number>
                <rut>
                    <to_quote_address>*</to_quote_address>
                </rut>
                <dpto_off>
                    <to_quote_address>*</to_quote_address>
                </dpto_off>
            </customer_address>
        </fieldsets>
    </global>
</config>

app/code/local/Devra/Address/sql/address_setup/mysql4-install-0.1.0.php

<?php

$installer = $this;

$installer->startSetup();

$setup = $this;

$entityTypeId = $setup->getEntityTypeId('customer_address');
$attributeSetId = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

//this is for creating a new attribute for customer address entity
$setup->addAttribute('customer_address', 'street_new', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Calle',
    'global' => 1,
    'visible' => true,
    'required' => true,
    'user_defined' => 1,
    'visible_on_front' => 1,
    'backend' => '',
    'source' => '',
    'default' => '',
    'frontend' => '',
    'unique' => false
));

$setup->addAttribute('customer_address', 'rut', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'RUT',
    'global' => 1,
    'visible' => 1,
    'required' => 1,
    'user_defined' => 1,
    'visible_on_front' => 1,
    'backend' => '',
    'source' => '',
    'default' => '',
    'frontend' => '',
    'unique' => false
));

$setup->addAttribute('customer_address', 'street_number', array(
    'type' => 'int',
    'input' => 'text',
    'label' => 'Numeración',
    'global' => 1,
    'visible' => 1,
    'required' => 1,
    'user_defined' => 1,
    'visible_on_front' => 1,
    'backend' => '',
    'source' => '',
    'default' => '',
    'frontend' => '',
    'unique' => false
));
$setup->addAttribute('customer_address', 'dpto_off', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Depto/Oficina',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1,
    'backend' => '',
    'source' => '',
    'default' => '',
    'frontend' => '',
    'unique' => false
));

Mage::getSingleton('eav/config')
->getAttribute('customer_address', 'street_new')
->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
->save();
Mage::getSingleton('eav/config')
->getAttribute('customer_address', 'street_number')
->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
->save();
Mage::getSingleton('eav/config')
->getAttribute('customer_address', 'dpto_off')
->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
->save();
Mage::getSingleton('eav/config')
->getAttribute('customer_address', 'rut')
->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
->setData("is_used_for_customer_segment", true)
->setData("is_system", 0)
->setData("is_user_defined", 1)
->setData("is_visible", 1)
->setData("sort_order", 100)
->save();


$setup->addAttributeToGroup(
        $entityTypeId, $attributeSetId, $attributeGroupId, 'street_new', '995'  //sort_order
);
$setup->addAttributeToGroup(
        $entityTypeId, $attributeSetId, $attributeGroupId, 'street_number', '996'  //sort_order
);
$setup->addAttributeToGroup(
        $entityTypeId, $attributeSetId, $attributeGroupId, 'dpto_off', '997'  //sort_order
);
$setup->addAttributeToGroup(
        $entityTypeId, $attributeSetId, $attributeGroupId, 'rut', '998'  //sort_order
);


/**
 * Adding Extra Column to sales_flat_quote_address
 * to store the delivery instruction field
 */
$sales_quote_address = $installer->getTable('sales/quote_address');
$installer->getConnection()
        ->addColumn($sales_quote_address, 'street_new', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Street field'
        ));
$installer->getConnection()
        ->addColumn($sales_quote_address, 'street_number', array(
            'type' => Varien_Db_Ddl_Table::TYPE_INT,
            'comment' => 'New Street number field'
        ));
$installer->getConnection()
        ->addColumn($sales_quote_address, 'dpto_off', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Dpto field'
        ));
$installer->getConnection()
        ->addColumn($sales_quote_address, 'rut', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New RUT field'
        ));

/**
 * Adding Extra Column to sales_flat_order_address
 * to store the delivery instruction field
 */
$sales_order_address = $installer->getTable('sales/order_address');
$installer->getConnection()
        ->addColumn($sales_order_address, 'street_new', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Street field'
        ));
$installer->getConnection()
        ->addColumn($sales_order_address, 'street_number', array(
            'type' => Varien_Db_Ddl_Table::TYPE_INT,
            'comment' => 'New Street number field'
        ));
$installer->getConnection()
        ->addColumn($sales_order_address, 'dpto_off', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New Dpto field'
        ));
$installer->getConnection()
        ->addColumn($sales_order_address, 'rut', array(
            'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
            'comment' => 'New RUT field'
        ));


$config = Mage::getModel('core/config');

//append delivery instruction to address templates in system configuration
$html = Mage::getConfig()->getNode('default/customer/address_templates/html');
$html .= '{{depend street_new}}<br/>Calle: {{var street_new}} {{/depend}}';
$html .= '{{depend street_number}}<br/>Numeración: {{var street_number}} {{/depend}}';
$html .= '{{depend dpto_off}}<br/>Dpto/Oficina: {{var dpto_off}} {{/depend}}';
$html .= '{{depend rut}}<br/>RUT: {{var rut}} {{/depend}}';

$config->saveConfig('customer/address_templates/html', $html);

$text = Mage::getConfig()->getNode('default/customer/address_templates/text');
$text .= '{{depend street_new}}<br/>Calle: {{var street_new}} {{/depend}}';
$text .= '{{depend street_number}}<br/>Numeración: {{var street_number}} {{/depend}}';
$text .= '{{depend dpto_off}}<br/>Dpto/Oficina: {{var dpto_off}} {{/depend}}';
$text .= '{{depend rut}}<br/>RUT: {{var rut}} {{/depend}}';
$config->saveConfig('customer/address_templates/text', $text);

$oneline = Mage::getConfig()->getNode('default/customer/address_templates/oneline');
$oneline .= '{{depend street_new}}<br/>Calle: {{var street_new}} {{/depend}}';
$oneline .= '{{depend street_number}}<br/>Numeración: {{var street_number}} {{/depend}}';
$oneline .= '{{depend dpto_off}}<br/>Dpto/Oficina: {{var dpto_off}} {{/depend}}';
$oneline .= '{{depend rut}}<br/>RUT: {{var rut}} {{/depend}}';
$config->saveConfig('customer/address_templates/oneline', $oneline);

$pdf = Mage::getConfig()->getNode('default/customer/address_templates/pdf');
$pdf .= '{{depend street_new}}<br/>Calle: {{var street_new}} {{/depend}}';
$pdf .= '{{depend street_number}}<br/>Numeración: {{var street_number}} {{/depend}}';
$pdf .= '{{depend dpto_off}}<br/>Dpto/Oficina: {{var dpto_off}} {{/depend}}';
$pdf .= '{{depend rut}}<br/>RUT: {{var rut}} {{/depend}}';
$config->saveConfig('customer/address_templates/pdf', $pdf);

$js_template = Mage::getConfig()->getNode('default/customer/address_templates/js_template');
$js_template .= '{{depend street_new}}<br/>Calle: {{var street_new}} {{/depend}}';
$js_template .= '{{depend street_number}}<br/>Numeración: {{var street_number}} {{/depend}}';
$js_template .= '{{depend dpto_off}}<br/>Dpto/Oficina: {{var dpto_off}} {{/depend}}';
$js_template .= '{{depend rut}}<br/>RUT: {{var rut}} {{/depend}}';
$config->saveConfig('customer/address_templates/js_template', $js_template);
$installer->endSetup();

Also, this is the result for core_resources:

select * from core_resource where code like '%address%';
Empty set (0.00 sec)

I also cleaned the cache, so i don't know what to do.

  • Do you have a file for the module in app/etc/modules? Without it Magento won't pick up the module – Robbie Averill Dec 28 '16 at 23:34
  • What happens if you remove <class>Mage_Customer_Model_Resource_Setup</class> from config.xml and also increase the version then clear the cache. – Adarsh Khatri Dec 29 '16 at 0:24
3

Is your module available in the backend "system > configuration > advanced". If it isn't available check your /etc/modules folder, you should have created and "Devra_Address.xml" file here.

Sometimes Magento fails to run the setup script (caching, errors, ...) A very usefull tool in situations like these is n98-magerun. n98-magerun is a bunch of CLI commands to help you with Magento development and maintenance. It has a script to force run setup's so you can see if yours is available and if Magento is able to run your script.

You can simply install it in your shell folder:

cd shell

And execute

wget https://files.magerun.net/n98-magerun.phar

After that you can force the incremental setup of modules:

php n98-magerun.phar sys:setup:incremental

You should see that there is (minimum) 1 script to install, and if you hit Enter it should install. If you don't see your script, then there is something wrong with your config.xml file.

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.