Enable fields in Customer/Account/create using code

Asked

Viewed 109 times

0

I’m developing a module where it will change the field value Display Data de Nascimento and Ver CPF/CNPJ in Configurações> clientes> Configurações> nome e opções de endereço.

when this value is set as necessary, it shows fields in the client register in customer/account/create, so I use the following code in an installation script, so that when the module is enabled already activate these fields that do not come by default.

code:

$inchooSwitch = new Mage_Core_Model_Config();

$inchooSwitch->saveConfig('customer/address/dob_show', "req", 'default', '');
$inchooSwitch->saveConfig('customer/address/taxvat_show', "req", 'default', '');

code changes successfully, but the fields when I access the page cliente/conta/criar/ do not appear.

Any idea why this happens?

1 answer

0


I found the solution by seeing the system.xml they used a backend_model adminhtml/system_config_backend_customer_show_customer , who had the function _afterSave which defines the attribute as visible and Required, follows the complete code after adjustments:

<?php

Mage::getModel('core/config')->saveConfig('customer/address/dob_show', 'req');
Mage::getModel('core/config')->saveConfig('customer/address/taxvat_show', 'req');
Mage::getModel('core/config')->saveConfig('customer/address/gender_show', 'req');

$dobAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'dob');
$dobAtribute->setData('is_required', 1);
$dobAtribute->setData('is_visible', 1);
$dobAtribute->save();

$taxvatAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'taxvat');
$taxvatAtribute->setData('is_required', 1);
$taxvatAtribute->setData('is_visible', 1);
$taxvatAtribute->save();

$genderAtribute = Mage::getModel('eav/entity_attribute')->loadByCode('customer', 'gender');
$genderAtribute->setData('is_required', 1);
$genderAtribute->setData('is_visible', 1);
$genderAtribute->save();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.