0

I need to add a field to the checkout process for my store. I have created a field on the frontend where a user can type in the 'Mail Hub' for their location.

How do I capture this information in the backend?

2

You need to add an attribute to the customer address eav model in your setup scripts. Something like this:

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$setup->addAttribute('customer_address', 'field', array(
    'label'     => 'Field',
    'type'      => 'varchar',
    'input'     => 'text',
    'visible'   => true,
    'required'  => true,
    'position'  => 1,
    ));

and capture an event in your module's observer. You can use this event for example: checkout_type_onepage_save_order

Then in your observer method

public function observerMethod(Varien_Event_Observer $observer) {

    $address = $observer->getQuote()->getShippingAddress();
    $address->set{yourFieldName}(Mage::app()->getRequest()->getParam('{yourFieldName}'))->save();
    return $this;
}
  • Will this also create a field in the order object? I will need a field in the order xml called <mail_hub> which captures the customers mail hub info. – Andy Apr 20 '15 at 14:09
  • no, order has flat structue, it's in one table. You can add a column to order table in your setup file like this: $connection->addColumn($this->getTable('sales/order'),’field’, “VARCHAR DEFAULT NULL"); And in the observer - add this field from request to your order and save it. Same as with the address – Eugen Bogdanovich Apr 20 '15 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.