通过UpgradeData.php更改商店名称

时间:2017-10-24 14:18:47

标签: php magento magento2

我是Magento 2的新手,我被要求编写更新以更改商店的名称值。

看起来像是:

store_id |code  |website_id |group_id |name       |sort_order |is_active |
---------|------|-----------|---------|-----------|-----------|----------|
0        |admin |0          |0        |Admin      |0          |1         |
1        |fr    |1          |1        |French     |0          |1         |
2        |en    |1          |1        |English    |0          |1         |
3        |de    |1          |1        |Deutsch    |0          |1         |
4        |en_us |2          |2        |USA        |0          |1         |

我需要" USA"价值是"英语美国"。

这是我想出的:

<?php

namespace Dnd\Store\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

/**
 * Class UpgradeData
 *
 */
class UpgradeData implements UpgradeDataInterface
{

    /**
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     */
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $installer = $setup;
        if (version_compare($context->getVersion(), '2.0.1', '<=')) {
            if ($installer->getTableRow($installer->getTable('store'), 'store_id', 4)) {
                $installer->updateTableRow(
                    $installer->getTable('store'),
                    'store_id',
                    4,
                    'name',
                    'English US'
                );
            }
        }
    }
}

但是当我php bin/magento setup:upgrade

时,它没有做任何事情

你有什么想法吗?

编辑:升级功能+ 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="Dnd_Store" setup_version="2.0.1">
        <sequence>
            <module name="Magento_Store"/>
        </sequence>
    </module>
</config>

setup_module数据:2.0.1

1 个答案:

答案 0 :(得分:1)

我刚刚检查了你的代码,它运行得很好。因此,我认为您的模块版本有问题。你能在setup_module表的模块和数据版本中向我提供etc / module.xml的内容吗?

我认为版本有问题,无论是使用compare函数还是使用module.xml

相关问题