I am using Magento 1.9.0.1 and right now i am developing a magento extension to add new custom attribute to the order.
I am doing everything by this guide: https://stackoverflow.com/questions/12936470/adding-a-new-attribute-to-order-in-magento You can see the guide as an answer to the question.
So let me show all the files i've created:
1: /app/code/community/VivasIndustries/Vshippingone/etc/config.xml:
<?xml version="1.0"?>
<config>
<modules>
<VivasIndustries_Vshippingone>
<version>1.1</version>
</VivasIndustries_Vshippingone>
</modules>
<global>
<fieldsets>
<sales_convert_quote>
<my_custom_input_field_one><to_order>*</to_order></my_custom_input_field_one>
</sales_convert_quote>
<sales_convert_order>
<my_custom_input_field_one><to_quote>*</to_quote></my_custom_input_field_one>
</sales_convert_order>
</fieldsets>
<helpers>
<vshippingone>
<class>VivasIndustries_Vshippingone_Helper</class>
</vshippingone>
</helpers>
<models>
<vshippingone>
<class>VivasIndustries_Vshippingone_Model</class>
<resourceModel>vshippingone_mysql4</resourceModel>
</vshippingone>
</models>
<resources>
<vshippingone_setup>
<setup>
<module>VivasIndustries_Vshippingone</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</vshippingone_setup>
<vshippingone_write>
<connection>
<use>core_write</use>
</connection>
</vshippingone_write>
<vshippingone_read>
<connection>
<use>core_read</use>
</connection>
</vshippingone_read>
</resources>
<events>
<adminhtml_sales_order_create_process_data_before>
<observers>
<vshippingone>
<type>singleton</type>
<class>vshippingone/observer</class>
<method>saveCustomDataOne</method>
</vshippingone>
</observers>
</adminhtml_sales_order_create_process_data_before>
</events>
<blocks>
<vshippingone>
<class>VivasIndustries_Vshippingone_Block</class>
</vshippingone>
</blocks>
</global>
</config>
2: /app/code/community/VivasIndustries/Vshippingone/Model/Observer.php:
<?PHP
class VivasIndustries_Vshippingone_Model_Observer
{
public function saveCustomDataOne($event)
{
$quote = $event->getSession()->getQuote();
$quote->setData('my_custom_input_field_one', $event->getRequestModel()->getPost('my_custom_input_field_one'));
return $this;
}
}
3: /app/code/community/VivasIndustries/Vshippingone/sql/vshippingone_setup/mysql4-install-1.1.php
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "my_custom_input_field_one", array("type"=>"varchar"));
$installer->addAttribute("quote", "my_custom_input_field_one", array("type"=>"varchar"));
$installer->endSetup();
4: /app/etc/modules/VivasIndustries_Vshippingone.xml:
<?xml version="1.0"?>
<config>
<modules>
<VivasIndustries_Vshippingone>
<active>true</active>
<codePool>community</codePool>
<version>1.1</version>
</VivasIndustries_Vshippingone>
</modules>
</config>
By my understanding i've added the following:
In: /app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml - I've added the following line so i can see the input field in the checkout page:
<input type="text" name="my_custom_input_field_one" id="my_custom_input_field_one"></input>
Then in: /app/design/adminhtml/default/default/template/sales/order/view/tab/info.phtml:
I've added the following:
<?php if($_order->getMyCustomInputFieldOne()): ?>
<tr>
<td class="label"><label><?php echo Mage::helper('sales')->__('My Custom Input Field One') ?></label></td>
<td class="value"><strong><?php echo $_order->getMyCustomInputFieldOne() ?></strong></td>
</tr>
<?php endif; ?>
Then i go and submit a new order. Then i go back in the admin panel to see that new order and i can not see the information shown in the admin order view page.
When i remove the if
statements i simply see this text My Custom Input Field One
but nothing more. I can not see the information inserted in the input field in the checkout page before submiting the order.
This are all the files i have created and edited. Nothing else was made or changed. Perhaps i am forgetting something, but i do not know what, or i have mistake somewhere.
Can you help me out fix it ?
$_order->getMyCustomInputFieldOne()
12345
but in the admin order view page nothing is shown. I hope i understand your question right.