Created
October 7, 2011 16:54
-
-
Save italoandre/1270785 to your computer and use it in GitHub Desktop.
Adding customer and address atributtes to Magento's Database - Adicionando atributos de cliente e endereço ao banco de dados do Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| USAGE: | |
| Paste this code inside any file called by Magento, like the app/design/frontend/package/theme/page/html/head.phtml and just acess your store. The code will run and after that it must be removed or commented. Be aware that not removing or commenting it will add these attributes to the database everytime code runs. | |
| USO: | |
| Cole este código dentro de qualquer arquivo chamado pelo Magento, como o app/design/frontend/package/theme/page/html/head.phtml e acesse sua loja. O código será executado e depois disso ele deve ser removido ou comentado. Esteja ciente de que não remover ou comentar o código irá adicionar estes atributos ao banco cada vez que for executado. | |
| */ | |
| $eavConfig = Mage::getSingleton('eav/config'); | |
| //Set customer attributes - Define os atributos de cliente | |
| $attributes = array( | |
| 'attribute_name' => array( | |
| 'label' => 'Attribute Label', | |
| 'is_user_defined' => 0, | |
| 'is_system' => 0, | |
| 'is_visible' => 1, | |
| 'sort_order' => 100, | |
| 'is_required' => 0, | |
| 'validate_rules' => array( | |
| 'max_text_length' => 255, | |
| ), | |
| 'admin_checkout' => 1 | |
| ), | |
| ); | |
| //Set address attributes - Define os atributos de endereço | |
| $attrAddress = array( | |
| 'addres_attribute' => array( | |
| 'label' => 'Address Attribute Label', | |
| 'is_user_defined' => 0, | |
| 'is_system' => 0, | |
| 'is_visible' => 1, | |
| 'sort_order' => 100, | |
| 'is_required' => 0, | |
| 'validate_rules' => array( | |
| 'max_text_length' => 255, | |
| ), | |
| 'admin_checkout' => 1 | |
| ), | |
| ); | |
| //Database operations - Operações do banco de dados | |
| $installer = Mage::getModel('customer/entity_setup'); | |
| $installer->startSetup(); | |
| foreach ($attributes as $attributeCode => $data) { | |
| $installer->addAttribute('customer', $attributeCode, array( | |
| 'label' => $data['label'], | |
| 'visible' => 1, | |
| 'required' => 0, | |
| 'position' => 1, | |
| )); | |
| $attribute = $eavConfig->getAttribute('customer', $attributeCode); | |
| //$attribute->setWebsite($store->getWebsite()); | |
| $attribute->addData($data); | |
| if (false === ($data['is_system'] == 1 && $data['is_visible'] == 0)) { | |
| $usedInForms = array( | |
| 'customer_account_create', | |
| 'customer_account_edit', | |
| 'checkout_register', | |
| 'adminhtml_customer', | |
| 'adminhtml_checkout' | |
| ); | |
| $attribute->setData('used_in_forms', $usedInForms); | |
| } | |
| $attribute->save(); | |
| } | |
| foreach ($attrAddress as $attributeCode => $data) { | |
| $installer->addAttribute('customer_address', $attributeCode, array( | |
| 'label' => $data['label'], | |
| 'visible' => 1, | |
| 'required' => 0, | |
| 'position' => 1, | |
| )); | |
| $attribute = $eavConfig->getAttribute('customer_address', $attributeCode); | |
| //$attribute->setWebsite($store->getWebsite()); | |
| $attribute->addData($data); | |
| if (false === ($data['is_system'] == 1 && $data['is_visible'] == 0)) { | |
| $usedInForms = array( | |
| 'customer_register_address', | |
| 'customer_address_edit', | |
| 'adminhtml_customer_address', | |
| 'checkout_register', | |
| 'adminhtml_customer', | |
| 'adminhtml_checkout' | |
| ); | |
| $attribute->setData('used_in_forms', $usedInForms); | |
| } | |
| $attribute->save(); | |
| } | |
| $installer->endSetup(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment