2

I have a question for my magento version 1.9.3.6, I create a module to add a custom field in Customer Registration Form and Checkout Registration Form.

config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Webcomnet_Field>
      <version>1.0.0</version>
    </Webcomnet_Field>
  </modules>
  <global>
    <helpers>
      <field>
        <class>Webcomnet_Field_Helper</class>
      </field>
    </helpers>
    <models>
      <field>
        <class>Webcomnet_Field_Model</class>
        <resourceModel>field_mysql4</resourceModel>
      </field>
    </models>
    <resources>
      <customerattribute1550847105_setup>
        <setup>
          <module>Webcomnet_Field</module>
          <class>Mage_Customer_Model_Entity_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </customerattribute1550847105_setup>
      <customerattribute1550847105_write>
        <connection>
          <use>core_write</use>
        </connection>
      </customerattribute1550847105_write>
      <customerattribute1550847105_read>
        <connection>
          <use>core_read</use>
        </connection>
      </customerattribute1550847105_read>
    </resources>
  </global>
</config>

install code:

    <?php
$installer = $this;
$installer->startSetup();


$installer->addAttribute("customer", "cod_univoco",  array(
    "type"     => "varchar",
    "backend"  => "",
    "label"    => "Codice Univoco",
    "input"    => "text",
    "source"   => "",
    "visible"  => true,
    "required" => false,
    "default" => "",
    "frontend" => "",
    "unique"     => false,
    "note"       => ""

    ));

        $attribute   = Mage::getSingleton("eav/config")->getAttribute("customer", "cod_univoco");


$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();

Then I edited the files "register.phtml" to show the field in registration form, the file "form/edit.phtml" to show the field in edit form in customer account section and the file "billing.phtml" to show the field in checkout registration form.

The module works fine for the customer registration form and the edit form, the problem is in the checkout form, the field appear but if I insert a value that value is not saved.

What can I do? Thanks

1 Answer 1

0

The file billing.phtml is for the billing address. Customer and customer address are two different models. Your value does not get saved because it is not part of the address attributes. Upon saving the billing form a async call gets made with the serialized form as payload. So if you add a additional field in the template its data should get transferred to the backend if you use a name like billing[something]. In the Onepage controller the data from billing[] gets saved to the billing address model.

So if you do want to keep your attribute at the customer attributes you could extend one of Mage_Checkout_OnepageController::saveBillingAction or Mage_Checkout_Model_Type_Onepage::saveBilling to look for the name of your attribute in the data and save it to the customer instead. The controller seems to be the better place for that.

1
  • I understand thanks. I try to extend model Mage_Checkout_OnepageController::saveBillingAction or Mage_Checkout_Model_Type_Onepage::saveBilling I'm new enough to magento and I still have to study how to do it in the right way. I try this to my test site, thanks.
    – DanMar
    Feb 23, 2019 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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