浏览文章
文章信息
Magento2后台配置自定义下拉选择
13769
1、配置文件
/app/code/Aiweline/Demo/etc/system.xml
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_SalesAgreement:etc/system_file.xsd"> <system> <tab id="Aiweline" translate="label" sortOrder="10"> <label>Aiweline_Demo标签名字随意</label> </tab> <section id="Aiweline_Demo_admin" translate="label" sortOrder="0" showInDefault="1" showInWebsite="1" showInStore="1"> <class>separator-top</class> <label>Demo样本</label> <tab>Aiweline</tab><!--指定粘贴在哪个tab上,我们的tab是Aiweline--> <resource>Aiweline_Config::config</resource> <group id="general" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="1" translate="label"> <attribute type="expanded">1</attribute> <label>基本配置</label> <field id="DemoType" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0"> <label>下拉选择</label> <source_model>Mjd\JiujiuApiyiliubabaProductImport\Model\Config\Source\DemoType</source_model> </field> </group> </section> </system> </config>2、类model
/app/code/Aiweline/Demo/Model/Config/Source/DemoType.php
<?php /** * Created by PhpStorm. * User: 秋枫雁飞 * Date: 2019/11/14 * Time: 10:02 * Web:www.aiweline.com * Copyright © 2016 Aiweline. All rights reserved. * See COPYING.txt for license details. */ namespace Mjd\JiujiuApiyiliubabaProductImport\Model\Config\Source; /** * @api * @since 100.0.2 */ class DemoType implements \Magento\Framework\Option\ArrayInterface { /** * Options getter * * @return array */ public function toOptionArray() { /* normal(综合),va_rmdarkgmv30rt(成交额),price-asc(价格从低到高),price-desc(价格从高到低)*/ return [ ['value' => '1', 'label' => __('demo 1')], ['value' => '2', 'label' => __('demo 2')], ['value' => '3', 'label' => __('demo 3')] } /** * Get options in "key-value" format * * @return array */ public function toArray() { return [0 => 'demo1', 1 => 'demo2', 2=> 'demo3']; } }
3、模块创建自行了解