{"id":470,"date":"2015-04-22T09:44:33","date_gmt":"2015-04-22T08:44:33","guid":{"rendered":"http:\/\/dknzdesign.com\/?p=470"},"modified":"2015-04-23T11:58:42","modified_gmt":"2015-04-23T10:58:42","slug":"how-to-add-custom-fields-in-checkout-page-in-magento","status":"publish","type":"post","link":"https:\/\/dknzdesign.com\/sl\/blog\/magento\/how-to-add-custom-fields-in-checkout-page-in-magento\/","title":{"rendered":"Kako dodati polja po meri na stran za dokon\u010danje nakupa v magentu"},"content":{"rendered":"<p>We will see in this blog to add a custom field in any of the Magento checkout page steps. I have demonstrated to add one field in the billing step. You should have good knowledge of developing modules in Magento.<\/p>\n<h3>Step1: Adding HTML This is the most simple step.<\/h3>\n<p>We will have to add a text field to the billing.phtml file. For magento 1.6(-) the file to edit is checkout\/onepage\/billing.phtml and for magento 1.6(+) you need to edit file persistent\/checkout\/onepage\/billing.phtml. Open the phtml file, find the code<\/p>\n<pre>&lt;? php if ($this-&gt;canShip()): ?&gt;<\/pre>\n<p>and just above the line add this<\/p>\n<pre class=\"php\" style=\"font-family: monospace\">&lt;li class=&quot;fields&quot;&gt;\r\n\t&lt;div class=&quot;field&quot;&gt;\r\n\t\t&lt;label for=&quot;billing:ssn&quot; class=&quot;required&quot;&gt;&lt;em&gt;*&lt;\/em&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'SSN'<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/label&gt;\r\n\t\t&lt;div class=&quot;input-box&quot;&gt;\r\n\t\t\t&lt;input<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">htmlEscape<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\" title=\"<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'SSN'<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&quot; class=&quot;input-text required-entry&quot; id=&quot;billing:ssn&quot; \/&gt;\r\n\t\t&lt;\/div&gt;\r\n\t&lt;\/div&gt;\r\n&lt;\/li&gt;<\/pre>\n<p>So, as you can see we are simply adding a text with name as custom[ssn] and value as $this-&gt;getQuote()-&gt;getSsn(); You will see the field in the Billing step on the checkout page. The same way you can add the field in any step.<\/p>\n<h3>Step2: Save the field in Quote and Order Tables<\/h3>\n<p>Now to save this field in the quote object and in the database, please follow the below steps. First I will create a database table \u201csales_quote_custom\u201d and for that put the following SLQ code in your modules.<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n<span style=\"color: #000088\">$installer<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">;<\/span>\r\n<span style=\"color: #000088\">$installer<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">startSetup<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n<span style=\"color: #000088\">$installer<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">run<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">\"\r\nCREATE TABLE IF NOT EXISTS {<span style=\"color: #006699;font-weight: bold\">$this-&gt;getTable<\/span>('sales_quote_custom')} (\r\n  `id` int(11) unsigned NOT NULL auto_increment,\r\n  `quote_id` int(11) unsigned NOT NULL,\r\n  `key` varchar(255) NOT NULL,\r\n  `value` text NOT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\nCREATE TABLE IF NOT EXISTS {<span style=\"color: #006699;font-weight: bold\">$this-&gt;getTable<\/span>('sales_order_custom')} (\r\n  `id` int(11) unsigned NOT NULL auto_increment,\r\n  `order_id` int(11) unsigned NOT NULL,\r\n  `key` varchar(255) NOT NULL,\r\n  `value` text NOT NULL,\r\n  PRIMARY KEY (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=utf8;\r\n\"<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n<span style=\"color: #000088\">$installer<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">endSetup<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span><\/pre>\n<p>We have created two tables here; one is for quote and other for order. You can confirm in PHPMyadmin that these tables have been created. Now we have to write event observers to capture quote save and load events and for that please open the your modules config.xml file and inside the tag put in<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #339933\">&lt;<\/span>events<span style=\"color: #339933\">&gt;<\/span>\r\n         <span style=\"color: #339933\">&lt;<\/span>sales_quote_save_before<span style=\"color: #339933\">&gt;<\/span> \r\n             <span style=\"color: #339933\">&lt;<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n                       <span style=\"color: #339933\">&lt;<\/span>save_before<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;<\/span>type<span style=\"color: #339933\">&gt;<\/span>singleton<span style=\"color: #339933\">&lt;\/<\/span>type<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;<\/span>class<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Observer<span style=\"color: #339933\">&lt;\/<\/span>class<span style=\"color: #339933\">&gt;<\/span> \r\n                        <span style=\"color: #339933\">&lt;<\/span>method<span style=\"color: #339933\">&gt;<\/span>saveQuoteBefore<span style=\"color: #339933\">&lt;\/<\/span>method<span style=\"color: #339933\">&gt;<\/span> \r\n                      <span style=\"color: #339933\">&lt;\/<\/span>save_before<span style=\"color: #339933\">&gt;<\/span>\r\n            <span style=\"color: #339933\">&lt;\/<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;\/<\/span>sales_quote_save_before<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;<\/span>sales_quote_save_after<span style=\"color: #339933\">&gt;<\/span> \r\n             <span style=\"color: #339933\">&lt;<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n                       <span style=\"color: #339933\">&lt;<\/span>save_after<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>type<span style=\"color: #339933\">&gt;<\/span>singleton<span style=\"color: #339933\">&lt;\/<\/span>type<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>class<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Observer<span style=\"color: #339933\">&lt;\/<\/span>class<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>method<span style=\"color: #339933\">&gt;<\/span>saveQuoteAfter<span style=\"color: #339933\">&lt;\/<\/span>method<span style=\"color: #339933\">&gt;<\/span>\r\n                      <span style=\"color: #339933\">&lt;\/<\/span>save_after<span style=\"color: #339933\">&gt;<\/span>\r\n            <span style=\"color: #339933\">&lt;\/<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;\/<\/span>sales_quote_save_after<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;<\/span>sales_quote_load_after<span style=\"color: #339933\">&gt;<\/span> \r\n                <span style=\"color: #339933\">&lt;<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n                    <span style=\"color: #339933\">&lt;<\/span>load_after<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>type<span style=\"color: #339933\">&gt;<\/span>singleton<span style=\"color: #339933\">&lt;\/<\/span>type<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>class<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Observer<span style=\"color: #339933\">&lt;\/<\/span>class<span style=\"color: #339933\">&gt;<\/span> \r\n                            <span style=\"color: #339933\">&lt;<\/span>method<span style=\"color: #339933\">&gt;<\/span>loadQuoteAfter<span style=\"color: #339933\">&lt;\/<\/span>method<span style=\"color: #339933\">&gt;<\/span> \r\n                     <span style=\"color: #339933\">&lt;\/<\/span>load_after<span style=\"color: #339933\">&gt;<\/span>\r\n                 <span style=\"color: #339933\">&lt;\/<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;\/<\/span>sales_quote_load_after<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;<\/span>sales_model_service_quote_submit_after<span style=\"color: #339933\">&gt;<\/span> \r\n                <span style=\"color: #339933\">&lt;<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n                    <span style=\"color: #339933\">&lt;<\/span>sales_model_service_quote_submit_after<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>type<span style=\"color: #339933\">&gt;<\/span>singleton<span style=\"color: #339933\">&lt;\/<\/span>type<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>class<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Observer<span style=\"color: #339933\">&lt;\/<\/span>class<span style=\"color: #339933\">&gt;<\/span> \r\n                            <span style=\"color: #339933\">&lt;<\/span>method<span style=\"color: #339933\">&gt;<\/span>saveOrderAfter<span style=\"color: #339933\">&lt;\/<\/span>method<span style=\"color: #339933\">&gt;<\/span> \r\n                     <span style=\"color: #339933\">&lt;\/<\/span>sales_model_service_quote_submit_after<span style=\"color: #339933\">&gt;<\/span>\r\n                 <span style=\"color: #339933\">&lt;\/<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;\/<\/span>sales_model_service_quote_submit_after<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;<\/span>sales_order_load_after<span style=\"color: #339933\">&gt;<\/span> \r\n                <span style=\"color: #339933\">&lt;<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n                    <span style=\"color: #339933\">&lt;<\/span>sales_order_load_after<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>type<span style=\"color: #339933\">&gt;<\/span>singleton<span style=\"color: #339933\">&lt;\/<\/span>type<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>class<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Observer<span style=\"color: #339933\">&lt;\/<\/span>class<span style=\"color: #339933\">&gt;<\/span> \r\n                            <span style=\"color: #339933\">&lt;<\/span>method<span style=\"color: #339933\">&gt;<\/span>loadOrderAfter<span style=\"color: #339933\">&lt;\/<\/span>method<span style=\"color: #339933\">&gt;<\/span> \r\n                     <span style=\"color: #339933\">&lt;\/<\/span>sales_order_load_after<span style=\"color: #339933\">&gt;<\/span>\r\n                 <span style=\"color: #339933\">&lt;\/<\/span>observers<span style=\"color: #339933\">&gt;<\/span>\r\n          <span style=\"color: #339933\">&lt;\/<\/span>sales_order_load_after<span style=\"color: #339933\">&gt;<\/span>\r\n    <span style=\"color: #339933\">&lt;\/<\/span>events<span style=\"color: #339933\">&gt;<\/span><\/pre>\n<p>and next we have to create our Observer classes in Model folder. So create an Observer.php in your modules Model folder.<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n<span style=\"color: #000000;font-weight: bold\">class<\/span> Icorethink_Custom_Model_Observer<span style=\"color: #009900\">{<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> saveQuoteBefore<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$evt<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$quote<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$post<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">app<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getFrontController<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getRequest<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getPost<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #990000\">isset<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$post<\/span><span style=\"color: #009900\">[<\/span><span style=\"color: #0000ff\">'custom'<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">[<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$post<\/span><span style=\"color: #009900\">[<\/span><span style=\"color: #0000ff\">'custom'<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #009900\">[<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">]<\/span><span style=\"color: #339933\">;<\/span>\r\n            <span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> saveQuoteAfter<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$evt<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$quote<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n            <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #339933\">!<\/span><span style=\"color: #990000\">empty<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n                <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_quote'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">deteleByQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setQuoteId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setKey<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setValue<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">save<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n            <span style=\"color: #009900\">}<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> loadQuoteAfter<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$evt<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$quote<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_quote'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$data<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getByQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">foreach<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$data<\/span> <span style=\"color: #b1b100\">as<\/span> <span style=\"color: #000088\">$key<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setData<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$key<\/span><span style=\"color: #339933\">,<\/span><span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> saveOrderAfter<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$evt<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$order<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$quote<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getQuote<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$quote<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n            <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #339933\">!<\/span><span style=\"color: #990000\">empty<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n                <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">deleteByOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$order<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">,<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setOrderId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$order<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setKey<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'ssn'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setValue<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$order<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">save<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n            <span style=\"color: #009900\">}<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> loadOrderAfter<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$evt<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$order<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$evt<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$data<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getByOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$order<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">foreach<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$data<\/span> <span style=\"color: #b1b100\">as<\/span> <span style=\"color: #000088\">$key<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000088\">$order<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">setData<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$key<\/span><span style=\"color: #339933\">,<\/span><span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n<span style=\"color: #009900\">}<\/span><\/pre>\n<p>So, we have captured the quote events sales_quote_save_before,sales_quote_save_after and sales_quote_load_after in above line of codes. These events will save our custom field to database. Details of functions are given in comments.<br \/>\nWe have already create model classes for this<br \/>\nIcorethink_Custom_Model_Custom_Order<br \/>\nIcorethink_Custom_Model_Custom_Quote<br \/>\nWhich you will find in the source code<\/p>\n<p>Detailed Explanation<\/p>\n<p>The first event captured by our module is sales_quote_save_before and saveQuoteBefore() function is called in our Observer class. What this function does, just before $quote-&gt;save() function is called, it reads our custom variable value \u2018ssn\u2019 from FORM POST data and simply sets it in the $quote object.<br \/>\nThe next event captured by our module is sales_quote_save_after and saveQuoteAfter() function is called in our Observer class. What this function does, just after $quote-&gt;save() function is called i.e the quote object get stored in database, it store our custom variable to our database table \u201csales_quote_custom\u201d<br \/>\nThe next event is sales_quote_load_after and function called is loadQuoteAfter(). When the $quote-&gt;load($id) is called, i.e quote is created from database entries, our function is called and this read the values of the custom variable from our database table \u201csales_quote_custom\u201d and sets it back again in the quote object.<br \/>\nThe next event captured in sales_model_service_quote_submit_after and function called is saveOrderAfter(). This event is called, just after an order is successfully placed. In this event, we read our custom field value from quote object and put in order table.<br \/>\nThe next event is sales_order_load_after and function called is loadOrderAfter(). This event is fired when $order-&gt;load() function is called, we read our fields values from database and place it back in the order object.<\/p>\n<h3>Step3: Display Our Field in My Account -&gt; View Order<\/h3>\n<p>After the order is placed by the customer, our custom fields needs to be visible in My Account. So to do this in our module fronted layout file, in my case its custom.xml.<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> xml version<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"1.0\"<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n&lt;layout version=\"0.1.0\"&gt;\r\n    &lt;sales_order_view&gt;\r\n        &lt;reference name=\"my.account.wrapper\"&gt;\r\n            &lt;block type=\"custom\/custom_order\" name=\"custom.order\" template=\"custom\/order.phtml\" after='sales.order.info' \/&gt;\r\n        &lt;\/reference&gt;\r\n    &lt;\/sales_order_view&gt;\r\n&lt;\/layout&gt;<\/pre>\n<p>This layout file is simple and understandable. Basically, we are taking reference of my.account.wrapper block and adding a child block to it. Our block type is custom\/order_view and template file is custom\/order.phtml. So we need to create our block class<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n<span style=\"color: #000000;font-weight: bold\">class<\/span> Icorethink_Custom_Block_Custom_Order <span style=\"color: #000000;font-weight: bold\">extends<\/span> Mage_Core_Block_Template<span style=\"color: #009900\">{<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> getCustomVars<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getByOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> getOrder<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span>\r\n    <span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #b1b100\">return<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">registry<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'current_order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n<span style=\"color: #009900\">}<\/span><\/pre>\n<p>and our order.phtml file<\/p>\n<pre class=\"php\" style=\"font-family: monospace\">&lt;div class=&quot;col-set order-info-box&quot;&gt;\r\n    &lt;div class=&quot;col&quot;&gt;\r\n        &lt;div class=&quot;box&quot;&gt;\r\n            &lt;div class=&quot;box-title&quot;&gt;\r\n                &lt;h2&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'Custom Fields'<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/h2&gt;\r\n            &lt;\/div&gt;\r\n            &lt;div class=&quot;box-content&quot;&gt;\r\n\u00a0\r\n                    <span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n                        <span style=\"color: #000088\">$custom<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getCustomVars<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                        <span style=\"color: #b1b100\">foreach<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$custom<\/span> <span style=\"color: #b1b100\">as<\/span> <span style=\"color: #000088\">$key<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n                    <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n                        &lt;b&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$key<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/b&gt; : <span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #339933\">;<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span> &lt;br\/&gt;\r\n                    <span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #009900\">}<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n\u00a0\r\n            &lt;\/div&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;<\/pre>\n<p>After doing this, you should be able to see your custom field in My Account page as shown here My Account View Order<\/p>\n<h3>Step4: Admin Order View Page<\/h3>\n<p>Next we need to show our custom field in Admin -&gt; Order -&gt; View Order page. To do this, in our adminhtml layout file, in my case custom.xml we will put in this code.<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> xml version<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"1.0\"<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n&lt;layout version=\"0.1.0\"&gt;\r\n    &lt;adminhtml_sales_order_view&gt;\r\n        &lt;reference name=\"order_info\"&gt;\r\n            &lt;action method='setTemplate'&gt;&lt;template&gt;custom\/sales\/order\/info.phtml&lt;\/template&gt;&lt;\/action&gt;\r\n            &lt;block type=\"adminhtml\/sales_order_view_info\" name=\"order_info2\" template=\"sales\/order\/view\/info.phtml\"&gt;&lt;\/block&gt;\r\n            &lt;block type=\"custom\/adminhtml_custom_order\" name=\"custom.order\" template='custom\/order.phtml'\/&gt;\r\n        &lt;\/reference&gt;\r\n    &lt;\/adminhtml_sales_order_view&gt;\r\n&lt;\/layout&gt;<\/pre>\n<p>So basically here i have added my block \u201ccustom.order\u201d to the existing order_info block. So the code for block class custom\/adminhtml_custom_order would be<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n<span style=\"color: #000000;font-weight: bold\">class<\/span> Icorethink_Custom_Block_Adminhtml_Custom_Order <span style=\"color: #000000;font-weight: bold\">extends<\/span> Mage_Adminhtml_Block_Sales_Order_Abstract<span style=\"color: #009900\">{<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> getCustomVars<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$model<\/span> <span style=\"color: #339933\">=<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">getModel<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom\/custom_order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #000088\">$model<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getByOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getId<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n<span style=\"color: #009900\">}<\/span><\/pre>\n<p>and next we need to create their phtml files custom\/order.phtml<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #000088\">$_order<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getOrder<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n&lt;div class=&quot;box-left&quot;&gt;\r\n    &lt;div class=&quot;entry-edit&quot;&gt;\r\n        &lt;div class=&quot;entry-edit-head&quot;&gt;\r\n            &lt;h4 class=&quot;icon-head head-account&quot;&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">helper<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'sales'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'Custom Fields'<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/h4&gt;\r\n        &lt;\/div&gt;\r\n        &lt;div class=&quot;fieldset&quot;&gt;\r\n            &lt;table cellspacing=&quot;0&quot; class=&quot;form-list&quot;&gt;\r\n            <span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n                <span style=\"color: #000088\">$custom<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getCustomVars<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n                <span style=\"color: #b1b100\">foreach<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$custom<\/span> <span style=\"color: #b1b100\">as<\/span> <span style=\"color: #000088\">$key<\/span> <span style=\"color: #339933\">=&gt;<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n            &lt;tr&gt;\r\n                &lt;td style=&quot;width:10%&quot; class=&quot;label&quot;&gt;&lt;strong&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> Mage<span style=\"color: #339933\">::<\/span><span style=\"color: #004000\">helper<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'sales'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">-&gt;<\/span>__<span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$key<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/strong&gt;&lt;\/td&gt;\r\n                &lt;td class=&quot;value&quot;&gt;<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$value<\/span><span style=\"color: #339933\">;<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>&lt;\/td&gt;\r\n            &lt;\/tr&gt;\r\n            <span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #009900\">}<\/span> <span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n            &lt;\/table&gt;\r\n        &lt;\/div&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;\r\n&lt;div class=&quot;clear&quot;&gt;&lt;\/div&gt;<\/pre>\n<p>custom\/sales\/order\/info.phtml<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getChildHtml<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'order_info2'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span>\r\n<span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php <span style=\"color: #b1b100\">echo<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getChildHtml<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #0000ff\">'custom.order'<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span><span style=\"color: #000000;font-weight: bold\">?&gt;<\/span><\/pre>\n<p>custom\/sales\/order\/view\/tab\/info.phtml<br \/>\nyou can get this file from the source code, there code in file is the default magento file. After doing these steps in admin we should be able to see this Admin Order View Page<\/p>\n<h3>Step5: Adding Custom Fields to Order Email<\/h3>\n<p>The final step, is adding the custom fields selected by user to the order email. So when user places an order, we will add our custom field to the order email. To do this open the order email template located at<br \/>\napp\\locale\\en_US\\template\\email\\sales\\order_new.html<br \/>\napp\\locale\\en_US\\template\\email\\sales\\order_new_guest.html<br \/>\nadd the below code where you want<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #009900\">{<\/span><span style=\"color: #009900\">{<\/span> depend order<span style=\"color: #339933\">.<\/span>hasCustomFields<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #009900\">}<\/span><span style=\"color: #009900\">}<\/span>\r\n                    <span style=\"color: #339933\">&lt;<\/span>table cellspacing<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"0\"<\/span> cellpadding<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"0\"<\/span> border<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"0\"<\/span> width<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"650\"<\/span><span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;<\/span>thead<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;<\/span>tr<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>th align<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"left\"<\/span> width<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"325\"<\/span> bgcolor<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"#EAEAEA\"<\/span> style<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"font-size:13px; padding:5px 9px 6px 9px; line-height:1em;\"<\/span><span style=\"color: #339933\">&gt;<\/span>Custom Fields<span style=\"color: #339933\">:&lt;\/<\/span>th<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;\/<\/span>tr<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;\/<\/span>thead<span style=\"color: #339933\">&gt;<\/span>  \r\n                        <span style=\"color: #339933\">&lt;<\/span>tbody<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;<\/span>tr<span style=\"color: #339933\">&gt;<\/span>\r\n                            <span style=\"color: #339933\">&lt;<\/span>td valign<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"top\"<\/span> style<span style=\"color: #339933\">=<\/span><span style=\"color: #0000ff\">\"font-size:12px; padding:7px 9px 9px 9px; border-left:1px solid #EAEAEA; border-bottom:1px solid #EAEAEA; border-right:1px solid #EAEAEA;\"<\/span><span style=\"color: #339933\">&gt;<\/span>\r\n                                <span style=\"color: #009900\">{<\/span><span style=\"color: #009900\">{<\/span> <span style=\"color: #000000;font-weight: bold\">var<\/span> order<span style=\"color: #339933\">.<\/span>getFieldHtml<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span> <span style=\"color: #009900\">}<\/span><span style=\"color: #009900\">}<\/span>\r\n                                <span style=\"color: #339933\">&amp;<\/span>nbsp<span style=\"color: #339933\">;<\/span>\r\n                            <span style=\"color: #339933\">&lt;\/<\/span>td<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;\/<\/span>tr<span style=\"color: #339933\">&gt;<\/span>\r\n                        <span style=\"color: #339933\">&lt;\/<\/span>tbody<span style=\"color: #339933\">&gt;<\/span>\r\n                    <span style=\"color: #339933\">&lt;\/<\/span>table<span style=\"color: #339933\">&gt;<\/span>\r\n                    <span style=\"color: #009900\">{<\/span><span style=\"color: #009900\">{<\/span> <span style=\"color: #339933\">\/<\/span>depend <span style=\"color: #009900\">}<\/span><span style=\"color: #009900\">}<\/span>\r\n                    <span style=\"color: #339933\">&lt;<\/span>br<span style=\"color: #339933\">\/&gt;<\/span><\/pre>\n<p>So as per the above code, we need to two functions hasCustomFields() and getFieldHtml() in our Order class. So next we will override the Mage_Sales_Model_Order model. Open your config.xml file and inside section put in this code<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #339933\">&lt;<\/span>sales<span style=\"color: #339933\">&gt;<\/span>\r\n\t<span style=\"color: #339933\">&lt;<\/span>rewrite<span style=\"color: #339933\">&gt;<\/span>\r\n\t\t<span style=\"color: #339933\">&lt;<\/span>order<span style=\"color: #339933\">&gt;<\/span>Icorethink_Custom_Model_Sales_Order<span style=\"color: #339933\">&lt;\/<\/span>order<span style=\"color: #339933\">&gt;<\/span>\r\n\t<span style=\"color: #339933\">&lt;\/<\/span>rewrite<span style=\"color: #339933\">&gt;<\/span>\r\n<span style=\"color: #339933\">&lt;\/<\/span>sales<span style=\"color: #339933\">&gt;<\/span><\/pre>\n<p>and next create our new model class Icorethink_Custom_Model_Sales_Order<\/p>\n<pre class=\"php\" style=\"font-family: monospace\"><span style=\"color: #000000;font-weight: bold\">&lt;?<\/span> php\r\n<span style=\"color: #000000;font-weight: bold\">class<\/span> Icorethink_Custom_Model_Sales_Order <span style=\"color: #000000;font-weight: bold\">extends<\/span> Mage_Sales_Model_Order<span style=\"color: #009900\">{<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> hasCustomFields<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">if<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">&amp;&amp;<\/span> <span style=\"color: #339933\">!<\/span><span style=\"color: #990000\">empty<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #009900;font-weight: bold\">true<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #009900\">}<\/span><span style=\"color: #b1b100\">else<\/span><span style=\"color: #009900\">{<\/span>\r\n            <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #009900;font-weight: bold\">false<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n    <span style=\"color: #000000;font-weight: bold\">public<\/span> <span style=\"color: #000000;font-weight: bold\">function<\/span> getFieldHtml<span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #009900\">{<\/span>\r\n        <span style=\"color: #000088\">$var<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #000088\">$this<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #004000\">getSsn<\/span><span style=\"color: #009900\">(<\/span><span style=\"color: #009900\">)<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #000088\">$html<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #0000ff\">&#039;&lt;b&gt;SSN:&lt;\/b&gt;&#039;<\/span><span style=\"color: #339933\">.<\/span><span style=\"color: #000088\">$var<\/span><span style=\"color: #339933\">.<\/span><span style=\"color: #0000ff\">&#039;&lt;br\/&gt;&#039;<\/span><span style=\"color: #339933\">;<\/span>\r\n        <span style=\"color: #b1b100\">return<\/span> <span style=\"color: #000088\">$html<\/span><span style=\"color: #339933\">;<\/span>\r\n    <span style=\"color: #009900\">}<\/span>\r\n<span style=\"color: #009900\">}<\/span><\/pre>\n<p>This should add the custom fields to the order.<\/p>\n<p>Using the above steps anyone having basic knowledge of magento module development can add custom fields in any step of checkout page.<\/p>","protected":false},"excerpt":{"rendered":"<p>V tem spletnem dnevniku bomo videli, kako dodati polje po meri v kateri koli korak Magentove strani za nakup. Pokazal sem dodajanje enega polja v koraku obra\u010dunavanja. Imeti morate dobro znanje o razvoju modulov v Magentu. 1. korak: Dodajanje HTML-ja To je najpreprostej\u0161i korak. Dodati bomo morali \u2026<\/p>","protected":false},"author":2,"featured_media":482,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[40],"tags":[92,43,91],"_links":{"self":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/470"}],"collection":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/comments?post=470"}],"version-history":[{"count":11,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/470\/revisions"}],"predecessor-version":[{"id":483,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/posts\/470\/revisions\/483"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/media\/482"}],"wp:attachment":[{"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/media?parent=470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/categories?post=470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dknzdesign.com\/sl\/wp-json\/wp\/v2\/tags?post=470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}