Guest User

Untitled

a guest
May 28th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. _init: function () {
  2. if (_.isEmpty(this.options.jsonConfig.images)) {
  3. this.options.useAjax = true;
  4. // creates debounced variant of _LoadProductMedia()
  5. // to use it in events handlers instead of _LoadProductMedia()
  6. this._debouncedLoadProductMedia = _.debounce(this._LoadProductMedia.bind(this), 500);
  7. }
  8.  
  9. if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
  10. // store unsorted attributes
  11. this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
  12. this._sortAttributes();
  13. this._RenderControls();
  14.  
  15. //this is additional code for select first attribute value
  16. if (this.options.jsonConfig.attributes.length > 0) {
  17. var selectswatch = this.element.find('.' + this.options.classes.attributeClass + ' .' + this.options.classes.attributeOptionsWrapper);
  18. $.each(selectswatch, function (index, item) {
  19. var swatchOption = $(item).find('div.swatch-option').first();
  20. if (swatchOption.length && !$(item).find('div.swatch-option').hasClass('selected')) {
  21. swatchOption.trigger('click');
  22. }
  23. });
  24. }
  25.  
  26. this._setPreSelectedGallery();
  27. $(this.element).trigger('swatch.initialized');
  28. } else {
  29. console.log('SwatchRenderer: No input data received');
  30. }
  31. this.options.tierPriceTemplate = $(this.options.tierPriceTemplateSelector).html();
  32. },
  33.  
  34. <?php
  35. /**
  36. * Copyright © 2015 Magento. All rights reserved.
  37. * See COPYING.txt for license details.
  38. */
  39. ?>
  40. <?php /** @var $block MagentoSwatchesBlockProductRendererConfigurable */ ?>
  41. <div class="swatch-opt"></div>
  42. <script>
  43. require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
  44. $('.swatch-opt').SwatchRenderer({
  45. jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
  46. jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
  47. mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
  48. });
  49.  
  50. //for selected option if only one value is exist....
  51. jQuery(document).ready(function(){
  52. //for swatches1
  53. var swatchLength = $('.swatch-attribute').length;
  54. if(swatchLength >= 1){
  55. if($('.swatch-attribute').hasClass("color")){
  56. $('.swatch-option').first().trigger('click');
  57. }
  58. }
  59. });
  60.  
  61. });
  62. </script>
Add Comment
Please, Sign In to add comment