Adding Field to Admin
First we need to create the address attribute. There are two ways to do this one is through your module sql file or you can do it through directly through sql query.
First we will see it through the module.
In your module’s config.xml file, add this in the resource tag.
<global> <helpers> <myaddress> <class>Bysoft_Myaddress_Helper</class> </myaddress> </helpers> <resources> <myaddress_setup> <setup> <module>Bysoft_Myaddress</module> <class>Mage_Customer_Model_Entity_Setup</class> <!-- This is the important thing--> </setup> <connection> <use>core_setup</use> </connection> </myaddress_setup> <myaddress_write> <connection> <use>core_write</use> </connection> </myaddress_write> <myaddress_read> <connection> <use>core_read</use> </connection> </myaddress_read> </resources>
The important thing is to have your module’s setup class pointed to Mage_Customer_Model_Entity_Setup. Next in the module’s mysql-install file we will put in the code
<?php $installer = $this; $installer->startSetup(); $this->addAttribute('customer_address', 'buyer_mobile', array( 'type' => 'varchar', 'input' => 'text', 'label' => 'Buyer Mobile', 'global' => 1, 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'visible_on_front' => 1 )); Mage::getSingleton('eav/config') ->getAttribute('customer_address', 'buyer_mobile') ->setData('used_in_forms', array('customer_register_address','customer_address_edit','adminhtml_customer_address')) ->save(); $installer->endSetup();
This will add the relevant database entries. If you want to do it directly i.e through database or phpmyadmin. Then you need to do the below.
eav_attribute table
insert a row in this table with values entity_type_id = 2, attribute_code = govt_id, backend_type = varchar, fontend_input = text, fontend_label = Govt ID No#, is_user_defined = 1, is_required = 1, default = NULL.
eav_entity_attribute table
insert a row in this table with values entity_type_id = 2,attribute_set_id =2, attribute_group_id = 2, attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table)
customer_eav_attribute table
insert a row in this table with values attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table), is_visible = 1 rest all column will take default values
customer_form_attribute table
1. insert row in this table with values form_code = adminhtml_customer_address and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This required for the attribute to show up in the admin
2. insert row in this table with values form_code = customer_address_edit and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This required for the attribute to get saved in edit address form and checkout page
3. insert row in this table with values form_code = customer_register_address and attribute_id = (The attribute_id or the primary key of the row inserted in the eav_attribute table). This is required to save the attribute in the create account page
After doing this step, you should be able to do see your new address attribute in the admin.
Address Format Next we need to change the address display format, this format is used everywhere in magento where ever address is displayed. To change the format, go to System -> Configuration -> Customer Configuration -> Address Template There you will see 5 options, we need to change all. Text Add {{depend buyer_mobile}}Buyer Mobile# {{var buyer_mobile}}{{/depend}} where ever you want it. {{depend}} basically checks, if buyer_mobile is not empty. Text One line Add {{depend buyer_mobile}}Buyer Mobile# {{var buyer_mobile}}{{/depend}} where ever you want it. This format shows up in the checkout page shipping,billing address dropdowns. HTML Add {{depend buyer_mobile}}<br/>Buyer Mobile# {{var buyer_mobile}}{{/depend}}. This format is used in many places like Order View, Address Display etc. PDF Add {{depend buyer_mobile}}<br/>Buyer Mobile# {{var buyer_mobile}}{{/depend}}|. This format is used in PDF invoices, shipments etc. Javascript Template Add <br/>Buyer Mobile#{buyer_mobile}. This is used in admin add/edit address area. After saving these in the configuration, the new address format should be visible.
Create Account Address First to show address in the magento create account form we need to make changes to customer\form\register.phtml (magento 1.6- version) or persistent\customer\form\register.phtml (magento 1.6+ version). If your using a module we will overwrite these files and make changes, if your not using a module you can make these changes directly. To overwrite, in your module’s layout xml file
<customer_account_create> <reference name='customer_form_register'> <action method='setTemplate'><template>address/persistent/customer/form/register.phtml</template></action> </reference> </customer_account_create>
Next in the phtml file regsiter.phtml created we will copy the default magento register.phtml contents and add our new field. First in the beginning of the file add this code, which will show all the address fields.
<?php $this->setShowAddressFields(true);?>
Next we need to add our new field, place this code where you want to show the new field
<li class="fields"> <div class="field"> <label for="buyer_mobile" class="required"><em>*</em><?php echo $this->__('Buyer Mobile') ?></label> <div class="input-box"> <input type="text" name="buyer_mobile" value="<?php echo $this->htmlEscape($this->getFormData()->getData('buyer_mobile')) ?>" title="<?php echo $this->__('Buyer Mobile') ?>" id="buyer_mobile" class="input-text required-entry" /> </div> </div> </li>
After this the new field added should be automatically saved to the database. You can view the new field in the admin and my account area.
Edit Address Next, in the My Account -> Edit Address form we need to add the the new field as well. For this we need to edit the customer\address\edit.phtml file. In the module’s layout xml file put in this code
<customer_address_form> <reference name='customer_address_edit'> <action method='setTemplate'><template>address/customer/address/edit.phtml</template></action> </reference> </customer_address_form>
and in the new edit.phtml file put in the form field where every required
<li class="fields"> <div class="field"> <label for="buyer_mobile" class="required"><em>*</em><?php echo $this->__('Buyer Mobile') ?></label> <div class="input-box"> <input type="text" name="buyer_mobile" value="<?php echo $this->htmlEscape($this->getAddress()->getData('buyer_mobile')) ?>" title="<?php echo $this->__('Buyer Mobile') ?>" id="buyer_mobile" class="input-text <?php echo $this->helper('customer/address')->getAttributeValidationClass('telephone'); ?> required-entry" /> </div> </div> </li>
Now editing/saving the Govt ID will work.
Checkout Billing/Shipping Step
Now, we will see what we need to do for adding the fields in shipping and billing steps of checkout page.
For this need to make changes to the checkout/onepage/billing.phtml and checkout/onepage/shipping.phtml files. To do this in the module’s layout xml file put in this code
<checkout_onepage_index> <reference name='checkout.onepage.billing'> <action method='setTemplate'><template>address/checkout/onepage/billing.phtml</template></action> </reference> <reference name='checkout.onepage.shipping'> <action method='setTemplate'><template>address/checkout/onepage/shipping.phtml</template></action> </reference> </checkout_onepage_index>
Next in the shipping.phtml and billing.phtml files need to add the field. Add this code in billing.phtml file
<li class="buyer_mobile"> <div class="buyer_mobile_field"> <div class="left_label"><label for="billing:buyer_mobile" class="required"><em>*</em><?php echo $this->__('Buyer Mobile') ?></label></div> <div class="buyer_mobile_content"> <input type="text" title="<?php echo $this->__('Buyer Mobile') ?>" name="billing[buyer_mobile]" id="billing:buyer_mobile" value="<?php echo $this->htmlEscape($this->getAddress()->getBuyerMobile()) ?>" class="input-text validate-one-required-by-group required-group-1 validate-digits validate-length minimum-length-11 maximum-length-11" /> </div> </div> </li>
and add this code in shipping.phtml file
<li class="buyer_mobile"> <div class="buyer_mobile_field"> <div class="left_label"><label for="billing:buyer_mobile" class="required"><em>*</em><?php echo $this->__('Buyer Mobile') ?></label></div> <div class="buyer_mobile_content"> <input type="text" title="<?php echo $this->__('Buyer Mobile') ?>" name="billing[buyer_mobile]" id="billing:buyer_mobile" value="<?php echo $this->htmlEscape($this->getAddress()->getBuyerMobile()) ?>" class="input-text validate-one-required-by-group required-group-1 validate-digits validate-length minimum-length-11 maximum-length-11" /> </div> </div> </li>
Next, we need to add this xml code to our module config.xml file
<fieldsets> <sales_convert_quote_address> <buyer_mobile> <to_order_address>*</to_order_address> <to_customer_address>*</to_customer_address> </buyer_mobile> </sales_convert_quote_address> <customer_address> <buyer_mobile> <to_quote_address>*</to_quote_address> </buyer_mobile> </customer_address> </fieldsets> </global>
Next we need to add govt_id column in the tables sales_flat_order_address, sales_flat_quote_address. To do this in your module’s sql file
$tablequote = $this->getTable('sales/quote_address'); $installer->run(" ALTER TABLE $tablequote ADD `buyer_mobile` varchar(255) NOT NULL "); $tablequote = $this->getTable('sales/order_address'); $installer->run(" ALTER TABLE $tablequote ADD `buyer_mobile` varchar(255) NOT NULL ");
Now, if a new address is created from the checkout step the new field will be added to the database and show up the order view.
These are all the places where the address shows up. The new field we have added will automatically show up in emails, pdfs etc.
相关推荐
magento custom menu 可以自己定制的导航菜单
“#magento2custom”
请通过运行命令行进行安装: composer需要php-cuong / magento2-module-core 安装PHPCuong_CustomerAddressAutocomplete模块: 作曲家需要php-cuong / magento2-customer-address-autocomplete php bin / ...
magento入门原版书.。。The Definitive Guide to Magento.pdf
Ajax-Magento-ajax-add-to-cart.zip,[模块magento 1]magento ajax添加到购物车-ajoter vos produits au panier en ajax/感谢ajax将您的产品添加到购物车,ajax代表异步javascript和xml。它是多种web技术的集合,包括...
Apress.The.Definitive.Guide.to.Magento.Dec.2009.pdf Apress于2009重磅推出的Magento上手书籍,原书地址:http://www.apress.com/book/view/9781430272298
You’ll start by getting a general understanding of what Magento is, why and how you should use it, and whether it is possible and feasible to migrate from an old web store to Magento 2. As you work ...
magentoCustomerAddressSql 用于查询 magento 的... 仅使用地址相关表转储数据库: mysqldump --opt -h IP_ADDRESS -u DATABASE_NAME -pPASSWORD --lock-tables=false peaches_prod customer_address_entity_int custo
compared to Magento 1. Where Magento 1 could be installed through FTP or SSH, Magento 2 is installable only via the command-line interface for an experienced webmaster. Chapter 2, Magento 2 System ...
magento-custom-stock-status Magento:自定义库存状态兼容:1.5、1.6、1.6.1、1.6.2.0、1.7、1.8、1.8.1、1.9、1.13、1.14 注意:安装前检查社区版本视图文件
magento自定义地址 一个简单的模块,可将“邻居”和“补码”字段添加到Magento商店中的客户地址。
概述该存储库包含将Magento 2与TurnTo的Social Commerce服务连接的Magento 2扩展。 与Magento社区和企业版2.1.x-2.3.x兼容。安装说明使用Composer安装(推荐) 在您的Magento根安装目录中运行以下命令: composer ...
Get a hands-on introduction to custom shipping and payment methods ☆ 出版信息:☆ [作者信息] Branko Ajzele [出版机构] Packt Publishing [出版日期] 2013年09月25日 [图书页数] 128页 [图书语言] 英语...
What this book covers Chapter 1, Installing Magento 2 on Apache and NGINX, is a ... It also includes how to add unit/functional tests as this is a new requirement for extensions listed on the new Magento
magento数据结构分析 magento数据字典
magik shoes magento 模板, magento 1.7 模板
magento的SMTP插件magento的SMTP插件magento的SMTP插件
Magento 添加到购物车矩阵 显示所有可配置的产品颜色和尺寸组合以及可用库存,并允许将产品大量添加到购物车。
magento2-custom-header