[英]Enable Custom Module Store Specifically Magento 2 not working
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.我有以下配置:主网站 >(默认商店视图,B2B 商店视图)我只想为 B2B 商店视图启用我的模块。
I tried to did this using system.xml: Code is :我尝试使用 system.xml 做到这一点:代码是:
<?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):我认为您为以下属性 (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)您还分配了默认值 = 1 (config.xml)
You should use by default this: <view_list>0</view_list>
默认情况下,您应该使用:
<view_list>0</view_list>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.