magento 2 system.xml 用法解析

本文内容来自QQ群大佬陈伟明(一叶知秋)的学习分享

 

system.xml后台设置选项的位置

对应的表是 core_config_data

<?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="payment"><!--在哪一部分-->
<!--group 用来分组-->
<group id="aune_stripe" translate="label comment" type="text" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Aune - Stripe</label>
<comment><![CDATA[Accept credit/debit cards in your Magento store via Stripe.]]></comment>
<!--field 显示要配置的字段 下面这个字段会存在 core_config_data 表 ,path 是 payment/aune_stripe/active -->
<field id="active" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable this Solution</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
//系统下的source_model,都在 Magento\Config\Model\Config\Source下面,类里面主要看 public function toOptionArray()方法
</field>
<field id="title" translate="label" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Title</label>
<depends> <!--指出依赖条件-->
<field id="active">1</field>
</depends>
</field>
<field id="payment_action" translate="label" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Payment Action</label>
<source_model>Aune\Stripe\Model\Adminhtml\Source\PaymentAction</source_model>
//自定义的 source_model 一般也是后台会用到 Vendor\Module\Model\Adminhtml\Source 下面
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="publishable_key" translate="label" type="text" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Publishable key</label>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="secret_key" translate="label" type="obscure" sortOrder="50" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Secret Key</label>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="store_customer" translate="label" type="select" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Store Customer</label>
<comment>Create customer entity in Stripe (mandatory to enable the vault).</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<depends>
<field id="active">1</field>
</depends>
</field>
<field id="store_future_usage" translate="label" type="select" sortOrder="70" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Future Usage</label>
<comment>Use On Session if you intend to only reuse the payment method when your customer is present in your checkout flow. Use Off Session if your customer may or may not be in your checkout flow.</comment>
<source_model>Aune\Stripe\Model\Adminhtml\Source\FutureUsage</source_model>
<depends>
<field id="active">1</field>
<field id="store_customer">1</field>
</depends>
</field>
<field id="debug" translate="label" type="select" sortOrder="80" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Enable Debug</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="aune_stripe_vault_active" translate="label" type="select" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="0">
<label>Vault Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<config_path>payment/aune_stripe_vault/active</config_path>
<depends>
<field id="active">1</field>
</depends>
</field>
</group>
</section>
</system>
</config>

 

发表评论