Question

i want to update the store configuration value using Data Patch.

Note: please do not suggest install and upgrade script.

i tried below code but its not working:

   <?php
 /**
  * Copyright ©  All rights reserved.
  * See COPYING.txt for license details.
  */
declare(strict_types=1);

namespace Vendor\Modulename\Setup\Patch\Data;

use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\App\Config\MutableScopeConfigInterface;

class SetupConfigData implements DataPatchInterface
{

const XML_PATH_STORE_TELEPHONE = 'customer/address/telephone_show';

const SCOPE_STORE = 'store';

/**
 * @var \Magento\Framework\App\Config\MutableScopeConfigInterface
 */
private $mutableScopeConfig;

/**
 * @var ModuleDataSetupInterface
 */
private $moduleDataSetup;

public function __construct(
    ModuleDataSetupInterface $moduleDataSetup,
    MutableScopeConfigInterface $mutableScopeConfig
)
{

    $this->moduleDataSetup = $moduleDataSetup;
    $this->mutableScopeConfig = $mutableScopeConfig;
}

public function apply()
{
    $this->moduleDataSetup->startSetup();
    $this->mutableScopeConfig->setValue(self::XML_PATH_STORE_TELEPHONE, 'opt', self::SCOPE_STORE);
    $this->moduleDataSetup->endSetup();
}

public function getAliases()
{
    return [];
}

public static function getDependencies()
{
    return [];
}
}

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top