Magento 2为什么这个UpgradeData.php代码不起作用

时间:2018-06-05 18:50:11

标签: php attributes magento2 categories

我想添加一些新的类别属性以及一个新的类别属性组,将它们全部分组。

升级正在运行,没有错误,但它似乎没有运行代码,即使它看起来很完美。我错过了什么吗?

UpgradeData.php

class UpgradeData implements UpgradeDataInterface
{
    private $eavSetupFactory;

    public function __construct(EavSetupFactory $eavSetupFactory) {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(ModuleDataSetupInterface $setup,ModuleContextInterface $context)
    {
        $setup->startSetup();

        if (version_compare($context->getVersion(), '1.0.4', '<')) {

            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

            $eavSetup->addAttributeGroup(
                Category::ENTITY,
                $eavSetup->getDefaultAttributeSetId(Category::ENTITY),
                'Thirdlight Settings',
                99
            );

            $eavSetup->addAttribute(\Magento\Catalog\Model\Category::ENTITY, 'thirdlight_banner', [
                'type'     => 'string',
                'label'    => 'Thirdlight Banner',
                'input'    => 'text',
                'source'   => '',
                'visible'  => true,
                'default'  => '',
                'required' => false,
                'global'   => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                'group'    => 'Thirdlight Settings',
            ]);

        $setup->endSetup();
    }

Module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="Avery_Orderattribs" setup_version="1.0.4">
        <sequence>
            <module name="Magento_Sales"/>
        </sequence>
    </module>
</config>

1 个答案:

答案 0 :(得分:1)

您是否检查了data_version数据库表中的模块setup_module列是否更新为1.0.4?