I'm currently working on module witch have to write custom data to order and quote. This data are passed from onestep/checkout. I have added checkbox in shipping method section by editing template.
So far I have created attribute for order and quote with install script witch is displayed in tables:
$installer = $this;
$installer->startSetup();
$installer->addAttribute('order', 'stoque', array(
'type' =>'int',
'label' => 'Que to service station',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'unique' => 0,
'is_configurable' => 0,
'position' => 1,
));
$installer->addAttribute('quote', 'stoque', array(
'type' =>'int',
'label' => 'Que to service station',
'global' => 1,
'visible' => 1,
'required' => 0,
'user_defined' => 1,
'searchable' => 0,
'filterable' => 0,
'comparable' => 0,
'visible_on_front' => 1,
'visible_in_advanced_search' => 0,
'unique' => 0,
'is_configurable' => 0,
'position' => 1,
));
$installer->endSetup();
Here is config.xml global section
<models>
<modulename>
<class>Vendor_Module_Model</class>
</modulename>
</models>
<fieldsets>
<sales_convert_quote>
<attributename><to_order>*</to_order></attributename>
</sales_convert_quote>
<sales_convert_order>
<attributename><to_quote>*</to_quote></attributename>
</sales_convert_order>
</fieldsets>
<modulename_write>
<connection>
<use>core_write</use>
</connection>
</modulename_write>
<modulename_read>
<connection>
<use>core_read</use>
</connection>
</modulename_read>
<resources>
<modulename_setup>
<setup>
<module>Vendor_Module</module>
<class>Mage_Sales_Model_Mysql4_Setup</class>
</setup>
</modulename_setup>
</resources>
<events>
<checkout_controller_onepage_save_shipping_method>
<observers>
<modulename_observer>
<class>modulename/observer</class>
<method>setStoqueVal</method>
</modulename_observer>
</observers>
</checkout_controller_onepage_save_shipping_method>
<checkout_type_onepage_save_order>
<observers>
<modulename_observer_order>
<class>modulename/observer</class>
<method>saveDataToOrder</method>
</modulename_observer_order>
</observers>
</checkout_type_onepage_save_order>
</events>
</global>
This is Observer class:
protected $_stoQue;
public function setStoqueVal($observer){
$fieldVal = Mage::app()->getFrontController()->getRequest()->getParam('stoque');
if($fieldVal){
$this->_stoQue = true;
}else{
$this->_stoQue = false;
}
}
public function saveDataToOrder($observer) {
var_dump($this->_stoQue);
die;
}
HTML:
<input type="checkbox" name="stoque" class="stoque-checkbox">
As you can see I'm trying to change $this->_stoQue value when checkbox is checked. And it is changed in setStoqueVal method, but when i'm trying to get this value in saveDataToOrder method it return NULL even with singleton set in config.xml. So far i have tried to pass it via register but still no use.
I'd really appreciate some help.
Ok, so i solved this without passing data but creating only one observer and saving data to quote first. Names of fields in both tables are similar, so data from quote is automatically saved to order.
Here is observer method:
public function setStoqueVal($observer){
$fieldVal = Mage::app()->getFrontController()->getRequest()->getParam('stoque');
$quote = $observer->getEvent()->getQuote();
if (!empty($fieldVal) && $fieldVal == "on") {
$quote->setStoque(1);
$quote->save();
}
}