需要在新类型的产品中创建新属性

时间:2015-05-14 13:03:37

标签: magento

我正在创建一个模块,用于在我的商店中插入新属性和新类型的产品。作为模板,我使用虚拟产品类型的相同注册屏幕,并且仅包括此类产品的新选项。 为此,在我的config.xml中,我使用了:

<catalog>
            <product>
                <type>
                    <incomm_virtual translate="label" module="incomm">
                        <label>Incomm Virtual</label>
                        <model>incomm/product_type</model>
                        <price_model>incomm/product_price</price_model>
                        <is_qty>1</is_qty>
                        <composite>0</composite>
                        <can_use_qty_decimals>0</can_use_qty_decimals>
                    </incomm_virtual>
                </type>
            </product>
        </catalog>

并使用相同config.xml中的sql配置安装:

<resources>
    <abc_incommproduct_setup>
        <setup>
            <module>ABC_Incomm</module>
            <class>Mage_Catalog_Model_Resource_Setup</class>
        </setup>
    </abc_incommproduct_setup>
</resources>

下一个文件使用mymodule / model / product / type.php,其中包含:

class ABC_Incomm_Model_Product_Type
        extends Mage_Catalog_Model_Product_Type_Virtual
{
    const TYPE_INCOMM          = 'incomm';
    const XML_PATH_AUTHENTICATION = 'catalog/incomm/authentication';

    protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode)
    {
        if ($this->_isStrictProcessMode($processMode)) {
            return Mage::helper('ABC_Incomm_Helper_Data')->__(
                'Incomm product %s cannot be added to cart. ' .
                ' On the product detail page click the "Go to parent site"'.
                ' button to access the product.',
                $product->getName()
            );
        }
        return parent::_prepareProduct($buyRequest, $product, $processMode);
    }
}

在同一文件夹中,virtual.php:

class ABC_Incomm_Model_Product_Virtual extends Mage_Catalog_Model_Product_Type_Virtual {   
}

最后,sql文件夹中的SQL安装文件/ abc_incommproduct_setup / mysql-install-4-0.1.0.php

$this->startSetup();

$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'terms_of_use', array(
    'group'         => 'General',
    'input'         => 'textarea',
    'type'          => 'text',
    'sort_order' => 4,
    'label'         => 'Terms of use',
    'backend'       => '',
    'visible'       => true,
    'required'      => true,
    'wysiwyg_enabled' => true,
    'visible_on_front' => true,
    'apply_to'                => 'incomm', //only in this type of product
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

$this->endSetup();

我的问题是,在禁用magento中的缓存后,清除缓存并包含一种新类型的产品,在Product Types列表中出现我的新产品类型,但是选项不加载通过sql插入的新属性,发生了什么?我的sqlinstall.php没有运行??

2 个答案:

答案 0 :(得分:1)

可能是因为incomm_virtual中指定的新产品类型为config.xml而非incomm。尝试使用'apply_to' => 'incomm'编辑'apply_to' => 'incomm_virtual'并重新运行安装程序

答案 1 :(得分:0)

如果您升级脚本,请遵循与安装升级脚本类似的模式,但文件名现在是data-upgrade- {old-version} - {new-version} .php,它们位于数据文件夹下。

如果您不想升级脚本并进行更改。不要忘记从core_resource表中删除youmodule_setup代码的现有条目。它只能立即加载。如果你不删除你的脚本就不会被加载。