Magento 2 - Как добавить пользовательскую конфигурацию магазина в существующую вкладку?
2 answers
Да, мы можем это сделать.
Мы должны взглянуть:
vendor/magento/module-payment/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="payment" translate="label" type="text" sortOrder="400" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Payment Methods</label>
<tab>sales</tab>
<resource>Magento_Payment::payment</resource>
</section>
</system>
</config>
Вкладка sales
была определена из vendor/magento/module-sales/etc/adminhtml/system.xml
. Поэтому, когда мы хотим создать новый раздел на вкладке ПРОДАЖИ, мы создаем новый раздел с узлом <tab>sales</tab>
.
app/code/Vendor1/Module1/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="custom_tab1" translate="label" type="text" sortOrder="401" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Your custom tab 1</label>
<tab>sales</tab>
<resource>Vendor_Module::custom</resource>
</section>
</system>
</config>
Или, если мы хотим добавить пользовательское поле в существующий раздел - custom_tab1
. Объявите наш обычай поля внутри этого раздела.
app/code/Vendor2/Module2/etc/adminhtml/system.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
<section id="custom_tab1">
<group id="custom_group1" translate="label" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Custom Group1</label>
<field id="custom_field1" type="text" translate="label comment" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Custom Field 1</label>
</field>
</group>
</section>
</system>
Вы можете создать новую вкладку в разделе Конфигурация продаж Следующим образом:
Vendor/Modulename/etc/adminhtml/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>
<section id="orderprocessing" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
<class>separator-top</class>
<label>Order Processing</label>
<tab>sales</tab>
<resource>TrainingJaymin_OrderProcessingFee::helloworld_config</resource>
<group id="general" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Order Process Fee Configuration</label>
<field id="enable" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Module Enable</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="display_text" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Display Text</label>
<comment>This text will display on the frontend.</comment>
</field>
</group>
</section>
</system>
</config>
Чтобы определить его правила:
Vendor/Modulename/etc/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>
<helloworld>
<general>
<enable>1</enable>
<display_text>Hello World</display_text>
</general>
</helloworld>
</default>
</config>
Теперь это создаст новую вкладку с именем Вкладка Обработка заказов в разделе Продажи с 2 полями, одно из которых является раскрывающимся списком, а другое - текстом.