3

I have an old module and I need to update it so it will work with a newer Magento version. Basically the module adds some customer fields.

So there a config.xml like this:

<config>
    <modules>
        <DWI_Customer>
            <version>1.0.1</version>
        </DWI_Customer>
    </modules>

    <global>
        <fieldsets>
            <customer_account>
                <membernumber><create>1</create><update>1</update></membernumber>
                ...
            </customer_account>
        </fieldsets>
    </global>
</config>

Notice there is no resources setup config defined but stilll there is a Entity/Setup.php

class DWI_Customer_Model_Entity_Setup extends Mage_Eav_Model_Entity_Setup
{
    public function getDefaultEntities()
    {
        return array(
            'customer' => array(
                'entity_model'          =>'customer/customer',
                'table'                 => 'customer/entity',
                'increment_model'       => 'eav/entity_increment_numeric',
                'increment_per_store'   => false,
                'additional_attribute_table' => 'customer/eav_attribute',
                'entity_attribute_collection' => 'customer/eav_attribute',
                'attributes' => array(
            'membernumber' => array(
            'label'     => 'Member No',
            'visible'   => true,
                        'sort_order'    => 65,
        ),
            ....
        );
    }
}

With newer version those fields are not visible (but added to eav_attribute) and I need to add an upgrade script like this:

$config->getAttribute('customer', 'membernumber' )
    ->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
    ->save();

I did the with other modules and it worked fine. Problem here is I don't have sql/customer_setup/mysql4.... here. Also it looks like the module does not show up in core_resource or I am not sure how it would be named. customer_setup feels right but that is already been used by Mage/Customer.

Question is: How do I add an upgrade script for this module?

4
  • Name your resource node dwi_customer_setup. and put the upgrade scripts in sql/dwi_customer_setup.
    – Marius
    Commented Jan 13, 2014 at 12:29
  • You put the resources tag inside the fieldsets. Move it one level higher
    – Marius
    Commented Jan 13, 2014 at 14:34
  • @Marius Thanks for you help. That worked! Can you post your comments as an answer so I can give you the bounty. Would be a waste otherwise ;) Commented Jan 13, 2014 at 14:53
  • Done. Yey.. for bounty points :)
    – Marius
    Commented Jan 13, 2014 at 15:03

1 Answer 1

3
+50

You can create the install script using the resource name dwi_customer_setup. In this case the upgrade scripts go under inside the folder sql/dwi_customer_setup of your extension.
This way you avoid the collision with the customer_setup resource.

In config.xml add the tag and changed version to 1.0.2.:

<global>
     <resources>
         <dwi_customer_setup>
             <setup>
                 <module>DWI_Customer</module>
             </setup>
         </dwi_customer_setup>
     </resources>
    ...
</global>

create DWI\Customer\sql\dwi_customer_setup\upgrade-1.0.1-1.0.2.php with

<?php

$this->startSetup();

Mage::getSingleton( 'eav/config' )
->getAttribute( 'customer', 'membernumber' )
->setData( 'used_in_forms', array( 'adminhtml_customer' ) )
->save();

$this->endSetup();

And very important as always: Clear your cache!

1
  • I feel kind of dirty for this answer. I only provided some suggestions. @PiTheNumber did the coding.
    – Marius
    Commented Jan 13, 2014 at 15:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.