Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- _init: function () {
- if (_.isEmpty(this.options.jsonConfig.images)) {
- this.options.useAjax = true;
- // creates debounced variant of _LoadProductMedia()
- // to use it in events handlers instead of _LoadProductMedia()
- this._debouncedLoadProductMedia = _.debounce(this._LoadProductMedia.bind(this), 500);
- }
- if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
- // store unsorted attributes
- this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
- this._sortAttributes();
- this._RenderControls();
- //this is additional code for select first attribute value
- if (this.options.jsonConfig.attributes.length > 0) {
- var selectswatch = this.element.find('.' + this.options.classes.attributeClass + ' .' + this.options.classes.attributeOptionsWrapper);
- $.each(selectswatch, function (index, item) {
- var swatchOption = $(item).find('div.swatch-option').first();
- if (swatchOption.length && !$(item).find('div.swatch-option').hasClass('selected')) {
- swatchOption.trigger('click');
- }
- });
- }
- this._setPreSelectedGallery();
- $(this.element).trigger('swatch.initialized');
- } else {
- console.log('SwatchRenderer: No input data received');
- }
- this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
- },
- <?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>
Add Comment
Please, Sign In to add comment