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