Question

Okay so I am trying to add a field to the registration with my module. Obviously I have to add an attribute. So my "install script" is really just an upgrade to the customer entity. However, the module is enabled and yet when I refresh the front end it will not run my install script. I have put a die at the front to see if its even hitting it and its not.

I have checked about 7 other stack overflow questions and each of the errors was pretty blatant. Things like the config not matching the folder it was in. Using customer_setup as the name. Errors in the setup file. Over and over i've looked at my code and i KNOW im missing something small. Some typo somewhere.....but ive wasted too much time now, so I hand it off to you great people.

Config.xml

<config>
    <modules>
        <BlizzardLabs_Customer>
            <version>0.1.0</version>
        </BlizzardLabs_Customer>
    </modules>
    <global>
        <fieldsets>
            <customer_account>
                <flavour>
                  <create>1</create>
                  <update>1</update>
                </flavour>
            </customer_account>
        </fieldsets>
        <resources>
            <blizzardlabs_customer_setup>
                <setup>
                    <module>BlizzardLabs_Customer</module>
                    <class>BlizzardLabs_Customer_Model_Entity_Setup</class>
                </setup>
            </blizzardlabs_customer_setup>
        </resources>
    </global>
</config>

BlizzardLabs/Customer/Model/Entity/Setup.php

class BlizzardLabs_Customer_Model_Entity_Setup extends Mage_Customer_Model_Entity_Setup {

  public function getDefaultEntities() {
    $entities = parent::getDefaultEntities();

    // Add flavour to customer attributes
    $entities['customer']['attributes']['flavour'] = array(
        'label' => 'Ice Cream Flavour',
        'visible' => true,
        'required' => true,
    );

    return $entities;
  }

}

BlizzardLabs/Customer/sql/blizzardlabs_customer_setup/mysql4-install-0.1.0.php

Mage::log('Installing BlizzardLabs_Customer');

$installer = $this;
$installer->startSetup();
$installer->addAttribute('customer', 'flavour', array(
    'label' => 'Ice Cream Flavour',
    'type' => 'varchar',
    'input' => 'text',
    'visible' => true,
    'required' => true,
    'position' => 1,
));

$attrs = array('flavour');

foreach ($attrs as $item) {
  $attr = Mage::getSingleton('eav/config')->getAttribute('customer', $item);
  $attr->setData('used_in_forms', array('adminhtml_customer','customer_account_edit','customer_account_create'))->save();
}

$installer->endSetup();

echo "information added to database";

Update: I apologize for the typo. the script IS in blizzardlabs_customer_setup

code_resource table:

+-------------------------------------+---------+
| code                                | version |
+-------------------------------------+---------+
| adminnotification_setup             | 1.0.0   |
| admin_setup                         | 0.7.1   |
| amazonpayments_setup                | 0.1.2   |
| api_setup                           | 0.8.1   |
| backup_setup                        | 0.7.0   |
| bundle_setup                        | 0.1.8   |
| catalogindex_setup                  | 0.7.10  |
| cataloginventory_setup              | 0.7.5   |
| catalogrule_setup                   | 0.7.7   |
| catalogsearch_setup                 | 0.7.6   |
| catalog_setup                       | 0.7.69  |
| checkout_setup                      | 0.9.3   |
| chronopay_setup                     | 0.1.0   |
| cms_setup                           | 0.7.8   |
| compiler_setup                      | 0.1.0   |
| contacts_setup                      | 0.8.0   |
| core_setup                          | 0.8.13  |
| cron_setup                          | 0.7.1   |
| customer_setup                      | 0.8.11  |
| cybermut_setup                      | 0.1.0   |
| cybersource_setup                   | 0.7.0   |
| dataflow_setup                      | 0.7.4   |
| directory_setup                     | 0.8.5   |
| downloadable_setup                  | 0.1.15  |
| eav_setup                           | 0.7.13  |
| enterprise_admingws_setup           | 0.0.1   |
| enterprise_catalogevent_setup       | 0.0.4   |
| enterprise_catalogpermissions_setup | 0.0.6   |
| enterprise_customerbalance_setup    | 0.0.10  |
| enterprise_enterprise_setup         | 0.0.1   |
| enterprise_giftcardaccount_setup    | 0.0.12  |
| enterprise_giftcard_setup           | 0.0.8   |
| enterprise_invitation_setup         | 0.0.3   |
| enterprise_logging_setup            | 0.1.8   |
| enterprise_pci_setup                | 0.0.3   |
| enterprise_staging_setup            | 0.1.10  |
| enterprise_websiterestriction_setup | 0.0.1   |
| eway_setup                          | 0.1.0   |
| flo2cash_setup                      | 0.1.1   |
| giftmessage_setup                   | 0.7.2   |
| googleanalytics_setup               | 0.1.0   |
| googlebase_setup                    | 0.1.1   |
| googlecheckout_setup                | 0.7.3   |
| googleoptimizer_setup               | 0.1.2   |
| ideal_setup                         | 0.1.0   |
| log_setup                           | 0.7.6   |
| newsletter_setup                    | 0.8.0   |
| oscommerce_setup                    | 0.8.10  |
| paybox_setup                        | 0.1.3   |
| paygate_setup                       | 0.7.0   |
| payment_setup                       | 0.7.0   |
| paypaluk_setup                      | 0.7.0   |
| paypal_setup                        | 0.7.2   |
| poll_setup                          | 0.7.2   |
| productalert_setup                  | 0.7.2   |
| protx_setup                         | 0.1.0   |
| rating_setup                        | 0.7.2   |
| reports_setup                       | 0.7.7   |
| review_setup                        | 0.7.4   |
| salesrule_setup                     | 0.7.7   |
| sales_setup                         | 0.9.38  |
| sendfriend_setup                    | 0.7.2   |
| shipping_setup                      | 0.7.0   |
| sitemap_setup                       | 0.7.2   |
| strikeiron_setup                    | 0.9.1   |
| tag_setup                           | 0.7.2   |
| tax_setup                           | 0.7.8   |
| usa_setup                           | 0.7.0   |
| weee_setup                          | 0.13    |
| wishlist_setup                      | 0.7.4   |
+-------------------------------------+---------+
Was it helpful?

Solution

I think you need to add the mysql4-install-0.1.0.php inside a folder called blizzardlabs_customer_setup. Just like the name of your xml tag inside the <resources> tag. So the path should be BlizzardLabs/Customer/sql/blizzardlabs_customer_setup/mysql4-install-0.1.0.php. Before trying it again with the modified path make sure you delete the record from the table core_resource with the code blizzardlabs_customer_setup and clear the cache.
Off topic. If you work with Magento EE 1.12 you can lose the mysql4 in the install script name. You can make it install-0.1.0.php. But it's not that important. It works both ways.

[EDIT]
I've tested tried to run your script. I've created the files as you described. The only thing I added was the module declaration file: app/etc/modules/BlizzardLabs_Customer.xml with this content.

<?xml version="1.0"?>
<config>
    <modules>
        <BlizzardLabs_Customer>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Customer />
            </depends>
        </BlizzardLabs_Customer>
    </modules>
</config>

And everything worked perfectly. Make sure you cleared the cache. Make sure that the local modules are not disabled (in app/etc/local.xml this tag is set to false <disable_local_modules>false</disable_local_modules>). This is all I can think about.

OTHER TIPS

Thought I should do the right thing and post this. On looking in the "core_resource" table in the database I can already see a customer_setup entry that is from the magento core.

My guess is that this is why you can't use blizzardlabs_customer_setup not anything to do with 2 underscores. So one of the checks after running the install if you can't see it in "core_resource" table should be to ensure you haven't used anything that could contravene with already existing entries, e.g. anything_customer_setup_g

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top