Reply to comment

Here is another how-to dealing with the way to add our custom registration field to the checkout process and pushing it to the customer account on order validation.

The hack is to add the "Flavour" field to the billing address step of the Onepage Checkout.

For this, we need to override the Sales module.

First, follow steps 1. and 2. but reading/using/writing "Sales" instead of "Customer"

Then, in app/local/.../Sales/etc/config.xml, around line 153 :
change

</sales_convert_quote_address>

to

<flavour><to_order>*</to_order></flavour>
</sales_convert_quote_address>

Then we need to modify the Sales/Model/Convert/Quote.php file (best practice is to override it in order not to lose our changes on core updates)

Modify the public function addressToOrder() (around line 66) like this :

public function addressToOrder(Mage_Sales_Model_Quote_Address $address, $order=null)
    {
        if (!($order instanceof Mage_Sales_Model_Order)) {
            $order = $this->toOrder($address->getQuote());
        }
 
        if(!Mage::helper('customer')->isLoggedIn()) {
        	$quote = $address->getQuote();
	        $customer = $quote->getCustomer();
	        $flavour = $address->getFlavour();
        	$customer->setFlavour($flavour);
        }
 
        Mage::helper('core')->copyFieldset('sales_convert_quote_address', 'to_order', $address, $order);
 
        Mage::dispatchEvent('sales_convert_quote_address_to_order', array('address'=>$address, 'order'=>$order));
        return $order;
    }

At last, we need to add the "Flavour" field to the billing step of the One Step Checkout.

Add the following lines to your theme's checkout/onepage/billing.phtml file where you want the "Flavour" field to appear :

<?php if(!$this->helper('customer')->isLoggedIn()) : ?>
<div class="field">
                        <label for="billing:flavour"><?php echo $this->__('Favourite Ice Cream Flavour') ?></label>
                        <div class="input-box">
                            <input type="text" id="billing:flavour" name="billing[flavour]" value="" title="<?php echo $this->__('Favourite Ice Cream Flavour') ?>" class="input-text" />
                        </div>
</div>
<?php endif; ?>

Please note that the goal of this how-to is to add a customer-account-wide "Flavour" field rather than an address-wide field (like a "mobile phone" field would be). So, once the "Flavour" field has been set at the customer's first order, it will not be available at checkout for further orders. This explains the use of "isLoggedIn()".

My favourite Ice Cream flavour is Ben & Jerry's chocolate and macadamia nuts!
Tested on Magento 1.4.0.1

Reply

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <apache>, <bash>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <perl>, <php>, <python>, <ruby>, <xml>. The supported tag styles are: <foo>, [foo].

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.