• 配置文件进行编辑


    1.以下是system.xml文件

    <config>
        <sections>
            <shopcore translate="label" module="shopcore">
                <class>separator-top</class>
                <label>商城/专区设置</label>
                <tab>sales</tab>
                <frontend_type>text</frontend_type>
                <sort_order>100</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>0</show_in_store>
                <groups>
                    <restriction translate="label" module="shopcore">
                        <label>限购逻辑</label>
                        <frontend_type>text</frontend_type>
                        <sort_order>100</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>0</show_in_store>
                        <fields>
                            <blocked_period_mapping translate="label">
                                <label><![CDATA[限制时间段]]></label>
                                <comment><![CDATA[
                                        限制类型填数值:壹风暴=100,蜂速购=110,蜜好货=120,蚂实惠=130<br/>
                                        时间段格式:07:00-09:00,20:00-22:00<br/>
                                        时间段请勿跨越子夜,请不要填写诸如23:00-03:00的时间段
                                ]]></comment>
                                <frontend_model>hpservice/adminhtml_system_config_form_field_json</frontend_model>-----------------------这里调的文件中是在Black里面
                                <frontend_json_structure>map</frontend_json_structure> <!-- map or list -->
                                <frontend_json_key_label>限制类型</frontend_json_key_label>
                                <frontend_json_value_label>时间段</frontend_json_value_label>
                                <sort_order>300</sort_order>
                                <show_in_default>1</show_in_default>
                                <show_in_website>1</show_in_website>
                                <show_in_store>0</show_in_store>
                            </blocked_period_mapping>
                        </fields>
                    </restriction>

                  </groups>
            </shopcore>

         </sections>
    </config>

    2.hpservice/adminhtml_system_config_form_field_json文件的内容如下:

    class Harapartners_HpService_Block_Adminhtml_System_Config_Form_Field_Json extends Mage_Adminhtml_Block_System_Config_Form_Field {
        
        /*
         * 特殊类型的system config,将列表内容变成JSON保存
         * 缺省支持两种类型:
         * >> list结构,只保存值value,不保存key,没有值时缺省为[]
         * >> map结构,保存键key与键值value,没有值时缺省为{}
         */
        protected function _toHtml() {
            $element = $this->getData('element');
            $elementFieldConfig = $element->getFieldConfig();
            $elementJsonConfig = array(
                    'structure'        => (string)$elementFieldConfig->frontend_json_structure,
                    'key_label'        => (string)$elementFieldConfig->frontend_json_key_label,
                    'value_label'    => (string)$elementFieldConfig->frontend_json_value_label,
            );
            
            // 键值从已知常量中选取中选取
            $rendererClassName = (string)$elementFieldConfig->frontend_json_key_option_renderer;
            if(!empty($rendererClassName)){
                $optionRenderer = Mage::getModel($rendererClassName);
                foreach($optionRenderer->getAllOptions() as $optionValue => $optionLabel){
                    $keyOptionHtml .= "<option value='{$optionValue}'>{$optionLabel}</option>";
                }
                $elementJsonConfig['key_option_html'] = $keyOptionHtml;
            }
            
            $elementData = $this->_prepareElementData($element, $elementJsonConfig);
            $elementJsonConfig = json_encode($elementJsonConfig);

            $htmlContent = <<< HTML_CONTENT
    <input type="hidden" id="{$element->getHtmlId()}" name="{$element->getName()}" value="{$element->getEscapedValue()}" {$this->serialize($element->getHtmlAttributes())}/>
    <div id="{$element->getHtmlId()}_json_config_widget" class="json_config_widget_container"></div>
    <script type="text/javascript">
        var {$element->getHtmlId()} = new JsonConfigWidget();
        {$element->getHtmlId()}.init("{$element->getHtmlId()}", $elementData, $elementJsonConfig);
    </script>
    HTML_CONTENT;
            return $htmlContent;
        }
        
        protected function _prepareElementData($element){
            $elementFieldConfig = $element->getFieldConfig();
            $elementJsonConfig = array(
                    'structure'        => (string)$elementFieldConfig->frontend_json_structure,
                    'key_label'        => (string)$elementFieldConfig->frontend_json_key_label,
                    'value_label'    => (string)$elementFieldConfig->frontend_json_value_label,
            );
            $elementData = (string)$element->getValue();
            
            //Try to decode to validate the data, if not validate, use empty placeholders
            $jsonValidateData = json_decode(trim($element->getValue()), true);
            if(!$jsonValidateData){
                if(isset($elementJsonConfig['structure']) && $elementJsonConfig['structure'] == 'list'){
                    $elementData = "[]";
                }else{
                    $elementData = "{}";
                }
            }
            
            return $elementData;
        }

        protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element){
            $this->addData(array(
                'element' => $element
            ));
            return $this->_toHtml();
        }
        
    }

    3.调取这里的值的方法是:

    $prizePoolConfig = json_decode(Mage::getStoreConfig('shopcore/restriction_product_number/blocked_day_mapping'), 1);//因为调取的数据为json数据所以转成数组.

  • 相关阅读:
    Python机器学习笔记:使用sklearn做特征工程和数据挖掘
    Python numpy中矩阵的用法总结
    Python机器学习笔记:K-近邻(KNN)算法
    Python机器学习笔记:Logistic Regression
    python机器学习笔记:ID3决策树算法实战
    Mysql 多表查询详解
    JavaScript cookie操作实现点赞功能
    js操作cookie
    【IntelliJ IDEA】idea上提交代码到GitHub,已经提交了 但是GitHub上却没有的解决办法
    Mybatis分页插件PageHelper的配置和使用方法
  • 原文地址:https://www.cnblogs.com/sqsnbrdcwlcfzj/p/6279450.html
Copyright © 2020-2023  润新知