【问题标题】:Enable Custom Module Store Specifically Magento 2 not working启用自定义模块存储,特别是 Magento 2 不起作用
【发布时间】:2020-09-11 07:15:27
【问题描述】:

我正在尝试仅为单个商店视图启用我的自定义模块,但该功能仍然适用于所有商店视图。

我有以下配置: 主网站 >(默认商店视图,B2B 商店视图) 我只想为 B2B 商店视图启用我的模块。

我尝试使用 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>

布局文件:

<?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);
    }
}

请说明代码有什么问题?

【问题讨论】:

    标签: php magento magento2


    【解决方案1】:

    我认为您为以下属性(system.xml)设置了错误的值:

    • 默认显示
    • showInWebsite
    • showInStore

    根据您的要求,您希望按商店提供功能。所以你必须像这样设置这些属性:

    • showInDefault="0"
    • showInWebsite="0"
    • showInStore="1"

    使用此功能,您的配置设置仅显示在商店视图中。

    您还分配了默认值 = 1 (config.xml)

    你应该默认使用这个: &lt;view_list&gt;0&lt;/view_list&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-01
      • 2013-06-17
      • 2012-06-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多