Magento - créer un nouveau client de l'attribut

J'ai besoin de créer 4 nouveaux attributs de clients dans ma boutique magento. J'ai créé un module ci-dessous pour le faire:

Customerattribute >
    etc > config.xml
    Model > Mysql4 > Setup.php
    sql > customerattribute_setup > mysql4-install-0.0.1.php

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
  <modules>
    <Custom_Customerattribute>
      <version>0.0.1</version>
    </Custom_Customerattribute>
  </modules>
    <global>
        <resources>
            <customerattribute_setup>
                <setup>
                    <module>Custom_Customerattribute</module>
                    <class>Custom_Customerattribute_Model_Mysql4_Setup</class>
                </setup>
                ....
            </customerattribute_setup>
        </resources>
    </global>
</config>

Setup.php

class Custom_Customerattribute_Model_Mysql4_Setup extends Mage_Eav_Model_Entity_Setup 
{
    /**
     * This method returns true if the attribute exists.
     * 
     * @param string|int $entityTypeId
     * @param string|int $attributeId
     * @return bool
     */
    public function attributeExists($entityTypeId, $attributeId) 
    {
        try 
        {
            $entityTypeId = $this->getEntityTypeId($entityTypeId);
            $attributeId = $this->getAttributeId($entityTypeId, $attributeId);
            return !empty($attributeId);
        } 
        catch(Exception $e) 
        {
            return FALSE;
        }
    }
}

mysql4-install-0.0.1.php

$installer = $this;
$installer->startSetup();
$entity = $installer->getEntityTypeId('customer');

if(!$installer->attributeExists($entity, 'paypal')) {
    $installer->removeAttribute($entity, 'paypal');
}

$installer->addAttribute($entity, 'paypal', array(
        'type' => 'text',
        'label' => 'Paypal',
        'input' => 'text',
        'visible' => TRUE,
        'required' => FALSE,
        'default_value' => '',
        'adminhtml_only' => '0'
));

$forms = array(
    'adminhtml_customer',
    'customer_account_edit'
);
$attribute = Mage::getSingleton('eav/config')->getAttribute($installer->getEntityTypeId('customer'), 'paypal');
$attribute->setData('used_in_forms', $forms);
$attribute->save();

$installer->endSetup();

Cela fonctionne pour mon premier client de l'attribut de paypal mais maintenant, je veux être en mesure d'ajouter 3 autres. J'avais espéré que si je change la mysql4-install-0.0.1.php fichier de dire ceci:

$installer = $this;
$installer->startSetup();
$entity = $installer->getEntityTypeId('customer');

if(!$installer->attributeExists($entity, 'attribute_2')) {
    $installer->removeAttribute($entity, 'attribute_2');
}

$installer->addAttribute($entity, 'attribute_2', array(
        'type' => 'text',
        'label' => 'Attribute 2',
        'input' => 'text',
        'visible' => TRUE,
        'required' => FALSE,
        'default_value' => '',
        'adminhtml_only' => '0'
));

$forms = array(
    'adminhtml_customer',
    'customer_account_edit'
);
$attribute = Mage::getSingleton('eav/config')->getAttribute($installer->getEntityTypeId('customer'), 'attribute_2');
$attribute->setData('used_in_forms', $forms);
$attribute->save();

$installer->endSetup();

et téléchargé le nouveau fichier et suis retourné sur le site attribute_2 serait ajouté, mais il n'est pas.

Pourquoi ce travail une fois, mais pas de nouveau?

Avez-vous gérer? Et pourriez-vous partager l'extension ou le code si possible (nous avons besoin de 4 attributs) ;P

OriginalL'auteur odd_duck | 2014-11-04