1

モジュールを Magento で作成しましたが、すべての製品に追加の属性を割り当てる必要があります。インストール スクリプトを作成しましたが、機能しません。

<?php

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

$installer->run("
    INSERT IGNORE INTO `{$installer->getTable('eav/attribute')}` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_required`, `is_user_defined`, `default_value`, `is_unique`, `note`) VALUES
    SELECT 1 + coalesce((SELECT max(attribute_id) FROM `{$installer->getTable('eav/attribute')}`),0),4,`is_accepted`,NULL,NULL,`int`,NULL,NULL,`boolean`,`Accepted`,NULL,`eav/entity_attribute_source_boolean`,1,1,'0',0,NULL);
");

$installer->endSetup();

Config.xml ファイル:

<adminhtml>
<acl>
    <module_setup>
                    <setup>
                        <module>My_module</module>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </module_setup>

                <module_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </module_write>

                <module_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </module_read>
            </resources>
        </acl>
</adminhtml>

ここで何が問題なのですか?

4

2 に答える 2

6

まず、これは有効な config.xml ではありません。セットアップ クラスは次のように構成されます。

<config>
    ...
    <global>
        ...
        <resources>
            ...
            <your_module_setup>
                <setup>
                    <module>Your_Module</module>
                    <class>Mage_Eav_Model_Entity_Setup</class>
                </setup>
            </your_module_setup>
            ...
        </resources>
        ...
    </global>
    ...
</config>

Mage_Eav_Model_Entity_Setup の代わりに独自のセットアップ クラスを使用することもできますが、Mage_Eav_Model_Entity_Setup を継承する必要があるため、手動で SQL クエリを作成する代わりに addAttribute を使用できます。

次に、セットアップ スクリプトは次のようになります。

$installer = $this;
$installer->startSetup();
/*
 * adds product unit attribute to product
 */
$installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'productunit_id', array(
    'label' => Mage::helper('productunits')->__('Quantity Unit'),
    'type' => 'int',
    'input' => 'select',
    'source' => SGH_ProductUnits_Model_Entity_Attribute_Source_Units::MODEL,
    'backend' => SGH_ProductUnits_Model_Entity_Attribute_Backend_Units::MODEL,
    'required' => 1,
    'global' => 1,
    'note' => Mage::helper('productunits')->__('This will be displayed next to any Qty value.')
));
$installer->endSetup();

数量単位属性を追加するのは私のコードです。クラス定数の使用に混乱しないでください。これらは対応するクラス エイリアスにすぎません。

于 2012-07-05T08:46:28.393 に答える
3

あなたの<module_setup>ノードは、下config/global/resourcesではなく下にある必要がありconfig/adminhtml/aclます。

于 2012-07-05T08:36:05.417 に答える