I want to add one new custom field to one checkout page in Magento. I created a module with the installer:
$installer = $this; $installer->startSetup(); $setup = new Mage_Eav_Model_Entity_Setup('core_setup'); $setup->addAttribute('order', 'deliverydate', array( 'position' => 1, 'input' => 'text', 'type' => 'varchar', 'label' => 'Choose delivery date', 'visible' => 1, 'required' => 0, 'user_defined' => 1, 'global' => 1, 'visible_on_front' => 1, )); $installer->endSetup();
With phpmyadmin, I see that the field has been added to the mage_eav_attribute table. I also added this to shipping-method.phtml:
<div class="form-list field"> <label for="deliverydate"><?php echo $this->__('Choose delivery date') ?></label> <div class="input-box"> <input type="text" name="deliverydate" id="deliverydate" title="<?php echo $this->__('deliverydate') ?>" class="input-text" /> </div> </div>
When I place an order, the custom field is not saved. How to make it work? So I added some custom fields for the client and they work fine. I can also see my custom customer fields automatically on admin / client, but I canβt see my custom order field in admin / sales_order. thanks
*Edit:
Here is what I did:
I added an observing .php to the name of the company / module / model / observer.
class Company_Module_Model_Observer { public function Deliverydate($observer){ //get event data $event = $observer->getEvent(); //get order $order = $event->getOrder(); //set the country here $order->setDeliverydate('11.11.2012'); //echo "observer"; } }
And here is my config.xml:
<?xml version="1.0"?> <config> <modules> <Company_Module> <version>0.1.0</version> </Company_Module> </modules> <global> <resources> <Company_Module_setup> <setup> <module>Company_Module</module> <class>Company_Module_Model_Resource_Mysql4_Setup</class> </setup> </Company_Module_setup> </resources> <events> <checkout_type_onepage_save_order> <observers> <Company_Module_Model_Observer> <type>singleton</type> <class>Company_Module_Model_Observer</class> <method>Deliverydate</method> </Company_Module_Model_Observer> </observers> </checkout_type_onepage_save_order> </events> </global> </config>
I think there are some problems with my supervisor. I think this is not shooting.
*Edit:
My supervisor is working now. The file name should be Observer.php, not an observer .php.