I need get data from text area in which customer write comment, than that comment I need add to order using sales_order_place_before event and save order to sales_flat_order. Customer comment must add to table with new column which I created, it's named 'comment'
-
What have you done so far ?– Abdul PathanAug 30, 2019 at 16:07
-
I'm stuck, I can't get data from text area which located in checkout block, and than add this comment to order in sales_flet_order(to my custom column 'comment').– Roman RomanchukAug 30, 2019 at 16:10
-
Have you created Order Atrribute ?– Abdul PathanAug 30, 2019 at 16:11
-
no, can you tell me more about this Order Atrribute?– Roman RomanchukAug 30, 2019 at 16:12
1 Answer
Step 1 : Create custom order attribute. Create a custom module and create a Mysql installer file in your module. {/app/code/local/namespace/modulename/sql/module_setup/mysql4-install-1.1.php}. Before this make sure you have added all resource model related information in etc/config.xml.
Put the content in the file.
<?php
$installer = $this;
$installer->startSetup();
$installer->addAttribute("order", "order_comment", array("type"=>"varchar"));
$installer->addAttribute("quote", "order_comment", array("type"=>"varchar"));
$installer->endSetup();
Step 2 : Create an Observer to save the details for event checkout_type_onepage_save_order
.
class Namespace_Modulename_Model_Observer
{
public function saveCustomData($event)
{
$quote = $event->getSession()->getQuote();
$quote->setData('order_comment', $event->getRequestModel()->getPost('order_comment'));
return $this;
}
}
Step 3: In your etc/config file make sure you write fiedset quote to order conversion code.
<global>
<fieldsets>
<sales_convert_quote>
<order_comment><to_order>*</to_order></order_comment>
</sales_convert_quote>
<sales_convert_order>
<order_comment><to_quote>*</to_quote></order_comment>
</sales_convert_order>
</fieldsets>
</global>
For more reference on custom EAV Order attribute please refer http://ka.lpe.sh/2013/05/10/magento-add-attribute-to-order/
Hope it finds you helpful. Thanks