在 Magento PHP 脚本中正确定义 $this 变量

Define $this variable correct in Magento PHP script

我有一个不可更改的脚本,但它不起作用。但是可以在开头或结尾添加代码。

这是脚本:

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

$installer->setConfigData('general/country/default', 'DE');
$installer->setConfigData('general/country/allow','BE,BG,DK,DE,CY');
$installer->setConfigData('general/country/optional_zip_countries','IE');
$installer->setConfigData('general/country/eu_countries','BE,CY');

$installer->endSetup();

如果我将脚本的开头更改为:

$installer = $this;
$installer = Mage::getModel("eav/entity_setup", "core_setup");
$installer->startSetup();

它会起作用,但正如我所说,它不可能写在脚本中。我收到的错误是:

Fatal error: Call to a member function startSetup() on a non-object

有没有办法使该脚本正常工作?

这是一个用于导入系统配置的 Magento 脚本。

提前致谢!

您可以在模块的 config.xml 中定义设置(又名 $this)要使用的 class,如下所示:

<?xml version="1.0"?>
<config>
    <global>
        <!--other definitions-->
        <resources>
            <namespace_module_setup>
                <setup>
                    <module>Namespace_Module</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </namespace_module_setup>
        </resources>
        <!--other definitions-->
    </global>
    <!--other definitions-->
</config>