2

我在模块设置文件中使用此函数创建了一个属性:

$this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'outofstock_date', array(
    'group'         => 'Inventory',
    'input'         => 'text',
    'type'          => 'int',
    'label'         => 'Out of Stock Date',
    'visible'       => 0,
    'required'      => 0,
    'user_defined'  => 1,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
    ));

我知道该属性的创建是有效的,因为我可以使用以下查询在数据库中找到它:

select * from eav_attribute where attribute_code like '%stock%';

但是,我在后端找不到它。它没有出现在编辑产品页面上,我看不到它在属性管理屏幕和属性集之一中列出。创建它时我做错了什么?为什么我在后台找不到?

另外:以上内容在 mysql4-install-0.1.0.php 安装文件中,触发它的配置文件部分是这样的:

    <resources>
        <giftlab_inventory_setup>
            <setup>
                <module>Giftlab_Inventory</module>
                <class>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup</class>
            </setup>
        </giftlab_inventory_setup>
    </resources>
4

1 回答 1

0

固定安装程序脚本:

<?php
    $installer = $this;
    $installer->startSetup();
    $installer->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'outofstock_date', array(
        'group'         => 'Inventory',
        'input' => 'date',
        'type' => 'datetime',
        'label'         => 'Out of Stock Date',
        'visible'       => 1,
        'required'      => 0,
        'user_defined'  => 1,
        'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
        'backend' => 'eav/entity_attribute_backend_datetime',
    ));

    $installer->endSetup();

但是请记住,组通常会添加另一个“库存”组,因此您最终可能会得到两个,但由于这个问题是关于后端缺乏可见性,所以答案也是如此。尝试使用 addAttributeToGroup() 也许。

于 2013-03-08T11:45:18.180 回答