dou8mwz5079 2017-10-24 14:18
浏览 15
已采纳

通过UpgradeData.php更改商店名称

I'm new to Magento 2 and I was asked to write an update to change the name value of a store.

It looks like that :

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         |

And I need the "USA" value to be "English US".

Here's what I came up with :

<?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'
                );
            }
        }
    }
}

But it doesn't do anything when I php bin/magento setup:upgrade

Do you have any idea ?

EDIT : version comparaison in upgrade function + 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 data : 2.0.1

  • 写回答

1条回答 默认 最新

  • doushuo2834 2017-10-24 18:43
    关注

    I just checked your code and it works just fine. Therefore I assume that there is something wrong with the version of your module. Could you provide me with the content of etc/module.xml in module and version of data in setup_module table?

    I think that something is wrong with the version, either with the value in compare function or in module.xml

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序