I am trying to enable my custom module only for a single store view but the functionality is still working for all store views.
I have the following configuration : Main Website > (Default store view, B2B Store view) I want to enable my module only for the B2B Store view.
I tried to did this using system.xml: Code is :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<tab id="customrfq" translate="label" sortOrder="1000">
<label>Request For Quote</label>
</tab>
<section id="customrfq" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ</label>
<tab>customrfq</tab>
<resource>CustomB2BRFQ_Module::rfq</resource>
<group id="department" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>RFQ configuration</label>
<field id="view_list" translate="label comment" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Show Quotes</label>
<comment>Show request for quotes</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
</group>
</section>
</system>
</config>
Config.xml :
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
<default>
<customrfq>
<department>
<view_list>1</view_list>
</department>
</customrfq>
</default>
</config>
Layout file :
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="CustomB2BRFQ\Module\Block\RequestForQuoteForm" name="custom_module_form"
template="CustomB2BRFQ_Module::rfq.phtml" ifconifg="customrfq/department/view_list" cacheable="false"/>
<arguments>
<argument name="path" xsi:type="helper" helper="CustomB2BRFQ\Module\Helper\Data::getPath" translate="true" />
</arguments>
</referenceContainer>
</body>
</page>
Helper File :
<?php
/**
* Created By : Rashi Goyal
*/
namespace CustomB2BRFQ\Module\Helper;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const PATH_FIELD = 'customrfq/department/view_list';
/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $scopeConfig;
/**
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
){
$this->scopeConfig = $scopeConfig;
parent::__construct($context);
}
public function getPath()
{
return $this->scopeConfig->getValue(self::PATH_FIELD,\Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}
}
Please specify what's wrong with the code?
Thanks, Rashi
I think you have set wrong values for following properties (system.xml):
According to your requirement, you want functionality by store. So you have to set these properties like this:
Using this, your configuration setting display only on store view.
Also You have assigned default value = 1 (config.xml)
You should use by default this: <view_list>0</view_list>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.