Question

I tried to add Home Page URL key programmatically using Recurring.php

Normally from Magento Admin backend:

STORES -> GENERAL -> Web -> Default Pages -> Default Web URL:

enter image description here

I tried using

Vendor/Module/Setup/Recurring.php

<?php

namespace Vendor\Module\Setup;

use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;


class Recurring implements InstallSchemaInterface
{   
    const default_web_url  = 'cms';
    protected $_configInterface;

        /**
     *  @var \Magento\Framework\App\Config\Storage\WriterInterface
     */
    protected $configWriter;

    /**
     *
     * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
     */
    public function __construct(
        \Magento\Framework\App\Config\Storage\WriterInterface $configWriter
    ) {
         $this->configWriter = $configWriter;
      }

    public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
       $value = self::default_web_url;
       $this->configWriter->save('web/default/front',  $value, $scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeId = 0);

    }
}

In my local, this value is storing for all store view scopes($scopeId = 0) but in our server, it's setting value for only one store view.

This is the issue I am facing here if anyone having any idea please guide me.

Thanks in Advance !!!!.

Was it helpful?

Solution

It seems like you didn't set sequence in module.xml file :

Replace this below code with your module.xml file

<?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="VendorName_ModuleName" setup_version="1.0.0">
        <sequence>
            <module name="Magento_Backend"/>
        </sequence>
    </module>
</config>

I checked your code and testing. Rest of all your code working.

Hope it maybe helpful for you.

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