3

I would like to add additional text field as Landmark in Billing Address and Shipping Address.

So I created a simple module as below

app/etc/modules/

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

app/code/local/Ucs/CustomField/etc/config.xml

<config>
    <modules>
        <Ucs_CustomField>
            <version>0.0.1</version>
        </Ucs_CustomField>
    </modules>
    <global>
         <resources>
            <landmark>
                <setup>
                    <module>Ucs_CustomField</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </landmark>
        </resources>
        <fieldsets>
            <sales_convert_quote>
                <landmark>
                    <to_order>*</to_order>
                </landmark>
            </sales_convert_quote>
            <customer_address>
                <landmark>
                    <to_quote_address>*</to_quote_address>
                </landmark>
            </customer_address>
        </fieldsets>
    </global>
</config>

app/code/local/Ucs/CustomField/sql/landmark/mysql4-install-0.0.1.php

<?php
$installer = $this;

$installer->startSetup();

$this->addAttribute('customer_address', 'landmark', array(
    'type' => 'varchar',
    'input' => 'text',
    'label' => 'Landmark',
    'global' => 1,
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'visible_on_front' => 1
));
Mage::getSingleton('eav/config')
    ->getAttribute('customer_address', 'landmark')
    ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address'))
    ->save();

$tablequote = $this->getTable('sales/quote_address');
$installer->run("ALTER TABLE  $tablequote ADD  `landmark` varchar(255) NOT NULL");

$tablequote = $this->getTable('sales/order_address');
$installer->run("ALTER TABLE  $tablequote ADD  `landmark` varchar(255) NOT NULL");

$installer->endSetup(); 

After Creating this, I modified System->Configuration->Customer Configuration->Address Template

For Text added {{depend landmark}}Landmark {{var landmark}}{{/depend}}

Text One Line , {{depend landmark}}Landmark {{var landmark}}{{/depend}}..

But From admin side in Sales->Order Grid or Customer side my account View Order, Print order, I cant see newly created field?

What is wrong with my code?

1 Answer 1

2

I did a mistake in config.xml

         <fieldsets>
            <sales_convert_quote>
                <landmark>
                    <to_order>*</to_order>
                </landmark>
            </sales_convert_quote>
            <customer_address>
                <landmark>
                    <to_quote_address>*</to_quote_address>
                    <to_order_address>*</to_order_address>
                </landmark>
            </customer_address>
            <sales_convert_quote_address>
                <landmark>
                    <to_order_address>*</to_order_address>
                    <to_customer_address>*</to_customer_address>
                </landmark>
            </sales_convert_quote_address>
        </fieldsets>

After making this change in config.xml it is working fine.

For Magento 2:

app/code/<Vendor_Name>/<Customer_Extension>/etc/fieldset.xml

Create an xml like above and place the below code.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:DataObject/etc/fieldset.xsd">
  <scope id="global">
      <fieldset id="sales_convert_quote_address">
       <field name="custom_field">
          <aspect name="to_order"/>
       </field>
      </fieldset>
      </scope>
</config>
2
  • i have same issue in magento 2. how should i fix there?
    – sam
    Commented Oct 20, 2020 at 5:14
  • @sam please refer the updated answer
    – Anto S
    Commented Oct 20, 2020 at 5:23

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.