3

We setup 2 website/store. When we tried to create customer from a store (i.e. not main store). By using customer/form_register type form submission. customer created successfully but taxvat field not saving with customer information. All other required customer attributes firstname, lastname, email saving correctly but only taxvat attribute not saving.

Code for Load layout with customer/form_register block type :

<reference name = "content">
   <block type = "customer/form_register" name = "customer_form_register" template = "seller/seller.phtml">
      <action method = "setShowAddressFields"><value>true</value></action>
        <block type = "page/html_wrapper" name = "customer.form.register.fields.before" as = "form_fields_before" translate = "label">
           <label>Form Fields Before</label>
        </block>
   </block>
</reference>

Template File :

<form name="test-form1" id="my-custom-form1" action="<?php echo $this->getPostActionUrl(); ?>" method="post">
    <input type="hidden" name="success_url" value="<?php echo $this->getSuccessUrl(); ?>" />
    <input type="hidden" name="error_url" value="<?php echo $this->getErrorUrl(); ?>" />
    <div>
        <div>
            <label>Email <span class="required">*</span></label>
            <input type="text" name="email"/>
        </div>
    </div>

    <div>
        <div>
            <label>First Name <span class="required">*</span></label>
            <input type="text" name="firstname"/>
        </div>
    </div>

    <div>
        <div>
            <label>Middle Name <span class="required">*</span></label>
            <input type="text" name="middlename"/>
        </div>
    </div>

    <div>
        <div>
            <label>Last Name <span class="required">*</span></label>
            <input type="text" name="lastname"/>
        </div>
    </div>

    <div>
        <div>
            <label>Tax/Vat Number <span class="required">*</span></label>
            <input type="text" name="taxvat"/>
        </div>
    </div>

    <div>
        <div>
            <input type="submit" name="sub" value="Submit">
        </div>
    </div>
</form>

This problem also exist for middlename, prefix, suffix attribute.

All these attributes 'taxvat', 'middlename', 'prefix', 'suffix' are exist in default magento setup same like 'firstname', 'lastname', 'email' exist. the only difference is they are not required.

Can anyone please tell me why this is happened and how to resolve this problem?

  • Share your controller code – Arunendra Jan 25 '17 at 6:44
  • If you have recently created taxvat attribute, just clear your cache and var/lock folder. Re-index your magento and try again. – Jaimin Sutariya Jan 25 '17 at 6:44
  • taxvat is a magento attribute . I have only use there name in my form field and I have clear cache. But my problem is not solve. – Rakesh Patidar Jan 25 '17 at 6:52
4

This happens because those attributes you mentioned have is_visible set to 0 in the customer_eav_attribute table. They are saved with this value when they are created by the setup.

Before saving the customer data, in the controller (Mage_Customer_AccountController) the _getCustomerErrors function is called:

protected function _getCustomerErrors($customer)
{
    $errors = array();
    $request = $this->getRequest();
    if ($request->getPost('create_address')) {
        $errors = $this->_getErrorsOnCustomerAddress($customer);
    }
    $customerForm = $this->_getCustomerForm($customer);
    $customerData = $customerForm->extractData($request);
    $customerErrors = $customerForm->validateData($customerData);
    if ($customerErrors !== true) {
        $errors = array_merge($customerErrors, $errors);
    } else {
        $customerForm->compactData($customerData);
        $customer->setPassword($request->getPost('password'));
        $customer->setConfirmation($request->getPost('confirmation'));
        $customerErrors = $customer->validate();
        if (is_array($customerErrors)) {
            $errors = array_merge($customerErrors, $errors);
        }
    }
    return $errors;
}

Not all the data you submit from the form gets set on the customer model in order to be saved. The data is first extracted in Mage_Customer_Model_Form class, which extends Mage_Eav_Model_Form. The first condition for the attribute data to be set on the customer model is that the specific attribute should be associated to submited form (you can check these in the customer_form_attribute table by filtering by form_code customer_account_create). This condition should be met for the attributes you mentioned since they are added to this form when they are created by the setup. The second condition for the attribute data to be set on the customer model is to pass the validation in the Mage_Eav_Model_Form::extractData function:

public function extractData(Zend_Controller_Request_Http $request, $scope = null, $scopeOnly = true)
{
    $data = array();
    foreach ($this->getAttributes() as $attribute) {
        if ($this->_isAttributeOmitted($attribute)) {
            continue;
        }
        $dataModel = $this->_getAttributeDataModel($attribute);
        $dataModel->setRequestScope($scope);
        $dataModel->setRequestScopeOnly($scopeOnly);
        $data[$attribute->getAttributeCode()] = $dataModel->extractValue($request);
    }
    return $data;
}

The _isAttributeOmitted function will check the is_visible value:

protected function _isAttributeOmitted($attribute)
{
    if ($this->_ignoreInvisible && !$attribute->getIsVisible()) {
        return true;
    }
    return false;
}

You can check the is_visible values for those attribute by running this query on your database:

SELECT * FROM customer_eav_attribute c WHERE attribute_id IN (
    SELECT attribute_id FROM eav_attribute
    WHERE attribute_code IN ('taxvat', 'middlename', 'prefix', 'suffix') AND entity_type_id=1
);

If the value for is_visible is 0 then you can change it to 1.

If you are using Magento Enterprise then you can edit the customer attributes in Customers -> Attributes -> Manage Customer Attributes. If you set Show on Frontend to Yes then the customer attribute values should be saved correctly into the database.

  • 1
    Good answer @Marina. However, it would be best to do this in an upgrade script: $attribute = Mage::getSingleton("eav/config")->getAttribute("customer", 'taxvat'); $attribute->setData('is_visible', 1); $attribute->save(); – Giel Berkers Oct 26 '17 at 9:09
  • Great suggestion, @Giel! If it's not Magento Enterprise, where you can edit this from admin, a setup script in a custom module would be the way to go. This way it's easier to deploy too. – Marina Vilcea Oct 26 '17 at 9:57

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.