2

I need to add two fields for Customer in customer's registration. I managed to do it and its working fine for customer registration. But it is not getting saved in case of onepage checkout (if customer is trying to register himself at the time of checkout).

Below is my Code

Code for app\code\local\ComName\ModuleName\etc\config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <ComName_ModuleName>
      <version>0.1.0</version>
    </ComName_ModuleName>
  </modules>
  <global>
    <helpers>
      <modulename>
        <class>ComName_ModuleName_Helper</class>
      </modulename>
    </helpers>
    <models>
      <modulename>
        <class>ComName_ModuleName_Model</class>
        <resourceModel>modulename_mysql4</resourceModel>
      </modulename>
    </models>
    <resources>
      <customerattribute1417600661_setup>
        <setup>
          <module>ComName_ModuleName</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute1417600661_setup>
      <customerattribute1417600661_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute1417600661_write>
      <customerattribute1417600661_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute1417600661_read>
    </resources>
  </global>
</config>

Code for app\code\local\ComName\ModuleName\Helper\Data.php:

class ComName_ModuleName_Helper_Data extends Mage_Core_Helper_Abstract
{

}

Code for app\code\local\ComName\ModuleName\sql\customerattribute1417600661_setup\mysql4-install-0.1.0.php:

$installer = $this;
$installer->startSetup();
$installer->addAttribute("customer", "dri_license",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Driving License",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""
    ));
        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "dri_license");
$used_in_forms=array();
$used_in_forms[]="adminhtml_customer";
$used_in_forms[]="checkout_register";
$used_in_forms[]="customer_account_create";
$used_in_forms[]="customer_account_edit";
$used_in_forms[]="adminhtml_checkout";
        $attribute->setData("used_in_forms", $used_in_forms)
        ->setData("is_used_for_customer_segment", true)
        ->setData("is_system", 0)
        ->setData("is_user_defined", 1)
        ->setData("is_visible", 1)
        ->setData("sort_order", 100)
        ;
        $attribute->save();
$installer->endSetup();

I have added fields in billing.phtml

Please help me if anyone have any idea on what i missing

4

I'd say that you need to change your XML like this:

<global>
    <fieldsets>
        <checkout_onepage_quote>
            <new_attribute>
                <to_customer>*</to_customer>
            </new_attribute>
        </checkout_onepage_quote>
        <customer_account>
            <new_attribute>
                <to_quote>*</to_quote>
            </new_attribute>
        </customer_account>
    </fieldsets>
</global>

And also - add the field to the quote in your setup file like this:

$installer = $this;
$installer->startSetup();

$connection = $installer->getConnection();
$quote_table_name = $installer->getTable('sales/quote');
$connection->addColumn($quote_table_name, 'new_attribute', array(
    'type' => Varien_Db_Ddl_Table::TYPE_TEXT,
    'length' => 255,
    'nullable' => false,
    'comment' => 'New Attribute',
));

$installer->endSetup();

(You can, of course use the alter table call, but I like this method better.)

Magento is first copying the fields from your request to the quote and then it's copying them back to the customer when the customer is being created.

Also, be sure that you have your new attribute ("new_attribute" in the example above) in the customer_form_attribute table for the checkout_register form_code

Hope that helps.

0

I think the part you are missing is the conversion from quote to customer that happens when you complete the checkout process.

This can be done with a small section of xml.

<global>
    <fieldsets>
        <checkout_onepage_quote>
            <customer_your_attribute>
                <to_customer>your_attribute</to_customer>
            </customer_your_attribute>
        </checkout_onepage_quote>
    </fieldsets>
</global>

This you copy your attribute from the customer part of the quote to the actual customer model when the quote is converted to an order.

The magic happens in the function Mage_Checkout_Model_Type_Onepage::_prepareNewCustomerQuote here you can see the call to the function Mage::helper('core')->copyFieldset('checkout_onepage_quote', 'to_customer', $quote, $customer);

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.