سؤال

I am trying to run a installer script for Magento 1.8.x but I am unsure of how to execute it. Can anyone confirm if there are any issues with my files below and also how do I get Magento to actually execute this script and add this custom customer attribute?

Here is my folder structure (just included those I feel are valid for this):

\app\code\local\SS\Rapt\
\app\code\local\SS\Rapt\etc\config.xml
\app\code\local\SS\Rapt\sql\mysql4-install-0.0.1.php

My installer file is as follows:

$installer = $this;
$installer->startSetup();

$setup = new Mage_Eav_Model_Entity_Setup('core_setup');

$entityTypeId     = $setup->getEntityTypeId('customer');
$attributeSetId   = $setup->getDefaultAttributeSetId($entityTypeId);
$attributeGroupId = $setup->getDefaultAttributeGroupId($entityTypeId, $attributeSetId);

$setup->addAttribute('customer', 'organisation_id', array(
    'input'         => 'select', //or select or whatever you like
    'type'          => 'int', //or varchar or anything you want it
    'label'         => 'Organisation ID',
    'visible'       => 1,
    'required'      => 0, //mandatory? then 1
    'user_defined' => 1,
));

$setup->addAttributeToGroup(
    $entityTypeId,
    $attributeSetId,
    $attributeGroupId,
    'organisation_id',
    '100'
);

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

$setup->endSetup();

My config.xml is as follows:

<config>
<modules>
    <SS_Rapt>
        <version>0.0.1</version>
    </SS_Rapt>
</modules>
/** more here but left out as not applicable to this installer feature **/

هل كانت مفيدة؟

المحلول

MySQL4 isn't in use anymore. You should use resource setup model instead. First you should define resource in config.xml

<config>
    <modules>
        <SS_Rapt>
        <version>0.0.1</version>
    </SS_Rapt>
    </modules>

    <global>
        <resources>
            <rapt_setup>
                <setup>
                    <module>SS_Rapt</module>
                    <class>SS_Rapt_Model_Resource_Setup</class>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </rapt_setup>
        </resources>
    </global>

</config>

Then you need to create SS_Rapt_Model_Resource_Setup file in the following location:

SS/Rapt/Model/Resource/Setup.php

This class should contain just this:

<?php
class SS_Rapt_Model_Resource_Setup extends Mage_Eav_Model_Entity_Setup{

}

At the end, you need to create install script in this location: SS/Rapt/sql/rapt_setup/install-0.0.1.php

You don't need to put mysql4 at the beginning of the name of install script. That's it :)

نصائح أخرى

I finally worked it out - the sql directory needed to have a folder named 'rapt_setup' with the sql inside that!? Doh!

But as J.S provided so much help I still want him to receive the answer points :)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top