1

I am following a tutorial from the book of Roman Zenner & Vinai Kopp called "Magento - The Handbook for Developers" (german: Magento - Das Handbuch für Entwickler).

Snippet from config.xml

<config>
    <modules>
        <WR_EPO>
            <version>1.0.0.12</version>
        </WR_EPO>
    </modules>
    <global>
        <resources>
            <wr_epo_setup>
                <setup>
                    <module>WR_EPO</module>
                </setup>
            </wr_epo_setup>
            ...

It says that I need this setup script: The script is in (app/code/local/WR/EPO/sql/wr_epo_setup/upgrade-1.0.0.11-1.0.0.12):

<?php
/**
 * @var Mage_Sales_Model_Mysql4_Setup $installer
 */

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

Mage::Log("Setup Script is getting executed.", 7, "setup.log");

$installer->addAttribute('quote_item', 'shipping_surcharge', array(
        'label' => 'Versandkostenaufpreis'
        ,'type' => 'decimal'
    )
);

$installer->endSetup();

But I get a 500 Status Code Error and the error Call to undefined method Mage_Core_Model_Resource_Setup::addAttribute() is getting logged.


I also tried this:

Snippet from config.xml

<config>
    <modules>
        <WR_EPO>
            <version>1.0.0.12</version>
        </WR_EPO>
    </modules>
    <global>
        <resources>
            <wr_epo_setup>
                <setup>
                    <module>WR_EPO</module>
                </setup>
            </wr_epo_setup>
            <wr_epo_sales_setup>
                <setup>
                    <module>WR_EPO</module>
                    <class>Mage_Sales_Model_Mysql4_Setup</class>
                </setup>
            </wr_epo_sales_setup>
            ...

... and moved the setup script from app/code/local/WR/EPO/sql/wr_epo_setup/upgrade-1.0.0.11-1.0.0.12 to app/code/local/WR/EPO/sql/wr_epo_sales_setup/upgrade-1.0.0.11-1.0.0.12 but now the setup script is not getting executed at all, I already removed the entry in the core_resources table and reloaded the site.

Is the tutorial outdated? How to do it right?

3

The issue isn't with your setup script. You aren't using the proper setup resource in your config.xml.

You need to use the Mage_Sales_Model_Resource_Setup model, not the default setup model.

Example from Magento Sales module:

<config>
    <modules>
        <Mage_Sales>
            <version>1.0.0</version>
        </Mage_Sales>
    </modules>
    <global>
        <resources>
            <sales_setup>
                <setup>
                    <module>Mage_Sales</module>
                    <class>Mage_Sales_Model_Resource_Setup</class>
                </setup>
            </sales_setup>
        </resources>
    </global>
</config>
  • I tried it with the class <class>Mage_Sales_Model_Resource_Setup</class> but now my setup script is not getting executed at all. – Black Jan 16 '19 at 11:23
  • My fault, I just copied the script from wr_epo_setup to wr_epo_sales_setup and none of them where executed because they are both doing the same. If I comment one of them out, then it works and the setup script log entry is created. Now I have to check if the attribute was really added. Thx! – Black Jan 16 '19 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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