zoukankan      html  css  js  c++  java
  • 麦进斗Magento2.1中设置默认配置选项

    此代码工作色板属性。

    使用下面的代码,第一样本被自动详情页页面加载后选定的,

    你必须重写文件到你的主题,

    应用程序/设计/前端/ PACKAGENAME / THEMENAME / Magento_Swatches /模板/产品/视图/ renderer.phtml

    <?php
    /**
     * Copyright © 2015 Magento. All rights reserved.
     * See COPYING.txt for license details.
     */
    ?>
    <?php /** @var $block MagentoSwatchesBlockProductRendererConfigurable */ ?>
    <div class="swatch-opt"></div>
    <script>
        require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
            $('.swatch-opt').SwatchRenderer({
                jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
                jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
                mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
            });
    
            //for selected option if only one value is exist....
            jQuery(document).ready(function(){
                //for swatches1
                var swatchLength = $('.swatch-attribute').length;
                if(swatchLength >= 1){
                    if($('.swatch-attribute').hasClass("color")){
                        $('.swatch-option').first().trigger('click');
                    }
                }
            });
    
        });
    </script>

    只需重写你的样本,renderer.js文件到您的themee和更改_init()功能下同,

    应用程序/设计/前端/供应商/ THEMENAME / Magento_Swatches / JS /样 - renderer.js

    _init: function () {
                if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
                    this._sortAttributes();
                    this._RenderControls();
    
                    //this is additional code for select first attribute value
                    if(this.options.jsonConfig.attributes.length == 1){
                        $('.swatch-attribute .swatch-attribute-options div.swatch-option').first().click();
                    }
    
                } else {
                    console.log('SwatchRenderer: No input data received');
                }
            },
    

      

     
  • 相关阅读:
    Scala课程01
    深入分析面向对象中的对象概念(转)
    代码审查时,发现功能实现的原因,而不仅仅是挑毛病(转)
    独立开发者复盘:手游研发犯过的8个错误(转)
    HTTPS背后的加密算法(转)
    How to recover from 'programmers burnout(转)
    数据流图的画法
    Filter及FilterChain的使用具体解释
    SimpleDateFormat使用具体解释
    TCP/IP协议,HTTP协议
  • 原文地址:https://www.cnblogs.com/magento-maijindou/p/5992764.html
Copyright © 2011-2022 走看看