如何解决专门启用自定义模块存储Magento 2无法正常工作
我试图仅对单个商店视图启用自定义模块,但该功能仍适用于所有商店视图。
我有以下配置: 主网站>(默认商店视图,B2B商店视图) 我只想为B2B商店视图启用我的模块。
<?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>
布局文件:
<?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>
帮助文件:
<?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);
}
}
请指定代码出了什么问题?
谢谢, 拉什
解决方法
我认为您为以下属性(system.xml)设置了错误的值:
- showInDefault
- showInWebsite
- showInStore
根据您的要求,您需要按商店分类的功能。因此,您必须像这样设置这些属性:
- showInDefault =“ 0”
- showInWebsite =“ 0”
- showInStore =“ 1”
使用此设置,您的配置设置仅显示在商店视图上。
您还分配了默认值= 1(config.xml)
默认情况下,您应该使用以下命令:
<view_list>0</view_list>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。