how to set default color configurable productSet default configurable selection in Magento 2.1Magento 2 can't get the selected color swatch value in options.phtml fileHow to Auto Select The Color as Swatch Option for Products with Only One Color (on Magento 2.1 Product View)?Default selected simple product in configurable productDisplay one color (of a configurable product) on its ownProduct image according to selected color option on cart page MagentoChange More product images on color swatch selectConfigurable product with color swatchesConfigurable Product Sizes with Image ColorMagento : Configurable product option selectedmagento 2 configurable product highest price product default selectedSet first configurable product as default imageHow to add default value for attribute of configurable product

What is a Samsaran Word™?

How to stretch the corners of this image so that it looks like a perfect rectangle?

How to remove border from elements in the last row?

What is an equivalently powerful replacement spell for the Yuan-Ti's Suggestion spell?

What exactly is ineptocracy?

Notepad++ delete until colon for every line with replace all

How does a dynamic QR code work?

Venezuelan girlfriend wants to travel the USA to be with me. What is the process?

meaning of 腰を落としている

ssTTsSTtRrriinInnnnNNNIiinngg

Why was the shrink from 8″ made only to 5.25″ and not smaller (4″ or less)

Description list Formatting using enumitem

How much mains leakage does an Ethernet connection to a PC induce, and what is the operating leakage path?

Unlock My Phone! February 2018

What's the meaning of "Sollensaussagen"?

Was the old ablative pronoun "med" or "mēd"?

How to travel to Japan while expressing milk?

How to Prove P(a) → ∀x(P(x) ∨ ¬(x = a)) using Natural Deduction

How to prevent "they're falling in love" trope

Does int main() need a declaration on C++?

GFCI outlets - can they be repaired? Are they really needed at the end of a circuit?

What is the most common color to indicate the input-field is disabled?

Car headlights in a world without electricity

Was the Stack Exchange "Happy April Fools" page fitting with the '90's code?



how to set default color configurable product


Set default configurable selection in Magento 2.1Magento 2 can't get the selected color swatch value in options.phtml fileHow to Auto Select The Color as Swatch Option for Products with Only One Color (on Magento 2.1 Product View)?Default selected simple product in configurable productDisplay one color (of a configurable product) on its ownProduct image according to selected color option on cart page MagentoChange More product images on color swatch selectConfigurable product with color swatchesConfigurable Product Sizes with Image ColorMagento : Configurable product option selectedmagento 2 configurable product highest price product default selectedSet first configurable product as default imageHow to add default value for attribute of configurable product













3















When I go to a product page, it does not have the default color - but I want to set the default color for a configurable product.



enter image description here










share|improve this question
























  • you want to select first swatch each time when page load?

    – Rakesh Jesadiya
    Aug 3 '16 at 8:42











  • Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

    – Kudo Yukiko
    Aug 4 '16 at 2:03
















3















When I go to a product page, it does not have the default color - but I want to set the default color for a configurable product.



enter image description here










share|improve this question
























  • you want to select first swatch each time when page load?

    – Rakesh Jesadiya
    Aug 3 '16 at 8:42











  • Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

    – Kudo Yukiko
    Aug 4 '16 at 2:03














3












3








3


1






When I go to a product page, it does not have the default color - but I want to set the default color for a configurable product.



enter image description here










share|improve this question
















When I go to a product page, it does not have the default color - but I want to set the default color for a configurable product.



enter image description here







magento2 configurable-product magento-2.0.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 3 '16 at 20:49









Fabian Schmengler

55.1k21137353




55.1k21137353










asked Aug 3 '16 at 8:33









Kudo YukikoKudo Yukiko

2315




2315












  • you want to select first swatch each time when page load?

    – Rakesh Jesadiya
    Aug 3 '16 at 8:42











  • Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

    – Kudo Yukiko
    Aug 4 '16 at 2:03


















  • you want to select first swatch each time when page load?

    – Rakesh Jesadiya
    Aug 3 '16 at 8:42











  • Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

    – Kudo Yukiko
    Aug 4 '16 at 2:03

















you want to select first swatch each time when page load?

– Rakesh Jesadiya
Aug 3 '16 at 8:42





you want to select first swatch each time when page load?

– Rakesh Jesadiya
Aug 3 '16 at 8:42













Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

– Kudo Yukiko
Aug 4 '16 at 2:03






Thank you for your comment. Yes, I want select product default when page load. Can you help me, please.

– Kudo Yukiko
Aug 4 '16 at 2:03











4 Answers
4






active

oldest

votes


















5














This code is working for color swatch attribute.



Using below code, first swatch are automatically selected after page load in details page,



you have to override file into your theme,



app/design/frontend/Packagename/themename/Magento_Swatches/templates/product/view/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>





share|improve this answer























  • Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

    – Kudo Yukiko
    Aug 5 '16 at 2:17












  • @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

    – Ramesh
    Jun 29 '17 at 8:05












  • this is the issue magento.stackexchange.com/questions/181255/…

    – Ramesh
    Jun 29 '17 at 8:33


















6














A better answer is below. The other answer I couldn't get to work on 2.1.4, the JS was running but it didn't do anything, not sure why? The solution below works perfectly and runs right after the options are rendered which may have been the problem with the other solution for me? It was running too early? :



Just Override your swatch-renderer.js file into your themee and change _init() function same as below: (approx. line 209)



app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-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');

,





share|improve this answer























  • But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

    – Jason Diehl
    Feb 2 '18 at 21:33











  • Try this answer magento.stackexchange.com/a/215803/46716

    – Gediminas
    May 9 '18 at 9:41


















0














Create in own theme file Magento_Swatches/templates/product/view/renderer.phtml



add the next code like



require([
'jquery'
], function ($)
$('[data-role="swatch-options"]').on('swatch.initialized', function ()
$(this).find('.swatch-attribute.color .swatch-option').first().click();
);
);





share|improve this answer






























    0














    Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
    to your theme

    your theme file location will be:

    app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js



    change _RenderControls() function



    just wrinte below code at the end of this function



    var swatchLength = $('.swatch-attribute').length;
    if(swatchLength >= 1)
    if($('.swatch-attribute').hasClass("size"))
    $('.swatch-option').first().trigger('click');




    http://prntscr.com/n6qo62





    share























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "479"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f128710%2fhow-to-set-default-color-configurable-product%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      5














      This code is working for color swatch attribute.



      Using below code, first swatch are automatically selected after page load in details page,



      you have to override file into your theme,



      app/design/frontend/Packagename/themename/Magento_Swatches/templates/product/view/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>





      share|improve this answer























      • Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

        – Kudo Yukiko
        Aug 5 '16 at 2:17












      • @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

        – Ramesh
        Jun 29 '17 at 8:05












      • this is the issue magento.stackexchange.com/questions/181255/…

        – Ramesh
        Jun 29 '17 at 8:33















      5














      This code is working for color swatch attribute.



      Using below code, first swatch are automatically selected after page load in details page,



      you have to override file into your theme,



      app/design/frontend/Packagename/themename/Magento_Swatches/templates/product/view/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>





      share|improve this answer























      • Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

        – Kudo Yukiko
        Aug 5 '16 at 2:17












      • @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

        – Ramesh
        Jun 29 '17 at 8:05












      • this is the issue magento.stackexchange.com/questions/181255/…

        – Ramesh
        Jun 29 '17 at 8:33













      5












      5








      5







      This code is working for color swatch attribute.



      Using below code, first swatch are automatically selected after page load in details page,



      you have to override file into your theme,



      app/design/frontend/Packagename/themename/Magento_Swatches/templates/product/view/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>





      share|improve this answer













      This code is working for color swatch attribute.



      Using below code, first swatch are automatically selected after page load in details page,



      you have to override file into your theme,



      app/design/frontend/Packagename/themename/Magento_Swatches/templates/product/view/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>






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Aug 4 '16 at 6:38









      Rakesh JesadiyaRakesh Jesadiya

      30.1k1576124




      30.1k1576124












      • Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

        – Kudo Yukiko
        Aug 5 '16 at 2:17












      • @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

        – Ramesh
        Jun 29 '17 at 8:05












      • this is the issue magento.stackexchange.com/questions/181255/…

        – Ramesh
        Jun 29 '17 at 8:33

















      • Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

        – Kudo Yukiko
        Aug 5 '16 at 2:17












      • @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

        – Ramesh
        Jun 29 '17 at 8:05












      • this is the issue magento.stackexchange.com/questions/181255/…

        – Ramesh
        Jun 29 '17 at 8:33
















      Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

      – Kudo Yukiko
      Aug 5 '16 at 2:17






      Thank you very much. It working but different file I edit code this on vendor/magento/module-swatches/view/frontend/templates/product/view/renderer.phtml

      – Kudo Yukiko
      Aug 5 '16 at 2:17














      @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

      – Ramesh
      Jun 29 '17 at 8:05






      @Rakesh, when am i trying to capture this events in options.phtml (module-catalog/view/frontend/template/product/view/options.phtml) its not triggered.

      – Ramesh
      Jun 29 '17 at 8:05














      this is the issue magento.stackexchange.com/questions/181255/…

      – Ramesh
      Jun 29 '17 at 8:33





      this is the issue magento.stackexchange.com/questions/181255/…

      – Ramesh
      Jun 29 '17 at 8:33













      6














      A better answer is below. The other answer I couldn't get to work on 2.1.4, the JS was running but it didn't do anything, not sure why? The solution below works perfectly and runs right after the options are rendered which may have been the problem with the other solution for me? It was running too early? :



      Just Override your swatch-renderer.js file into your themee and change _init() function same as below: (approx. line 209)



      app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-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');

      ,





      share|improve this answer























      • But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

        – Jason Diehl
        Feb 2 '18 at 21:33











      • Try this answer magento.stackexchange.com/a/215803/46716

        – Gediminas
        May 9 '18 at 9:41















      6














      A better answer is below. The other answer I couldn't get to work on 2.1.4, the JS was running but it didn't do anything, not sure why? The solution below works perfectly and runs right after the options are rendered which may have been the problem with the other solution for me? It was running too early? :



      Just Override your swatch-renderer.js file into your themee and change _init() function same as below: (approx. line 209)



      app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-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');

      ,





      share|improve this answer























      • But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

        – Jason Diehl
        Feb 2 '18 at 21:33











      • Try this answer magento.stackexchange.com/a/215803/46716

        – Gediminas
        May 9 '18 at 9:41













      6












      6








      6







      A better answer is below. The other answer I couldn't get to work on 2.1.4, the JS was running but it didn't do anything, not sure why? The solution below works perfectly and runs right after the options are rendered which may have been the problem with the other solution for me? It was running too early? :



      Just Override your swatch-renderer.js file into your themee and change _init() function same as below: (approx. line 209)



      app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-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');

      ,





      share|improve this answer













      A better answer is below. The other answer I couldn't get to work on 2.1.4, the JS was running but it didn't do anything, not sure why? The solution below works perfectly and runs right after the options are rendered which may have been the problem with the other solution for me? It was running too early? :



      Just Override your swatch-renderer.js file into your themee and change _init() function same as below: (approx. line 209)



      app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-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');

      ,






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Mar 22 '17 at 19:54









      Jason DiehlJason Diehl

      340311




      340311












      • But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

        – Jason Diehl
        Feb 2 '18 at 21:33











      • Try this answer magento.stackexchange.com/a/215803/46716

        – Gediminas
        May 9 '18 at 9:41

















      • But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

        – Jason Diehl
        Feb 2 '18 at 21:33











      • Try this answer magento.stackexchange.com/a/215803/46716

        – Gediminas
        May 9 '18 at 9:41
















      But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

      – Jason Diehl
      Feb 2 '18 at 21:33





      But this apparently doesn't seem to work on 2.2.1 anymore. Ugh

      – Jason Diehl
      Feb 2 '18 at 21:33













      Try this answer magento.stackexchange.com/a/215803/46716

      – Gediminas
      May 9 '18 at 9:41





      Try this answer magento.stackexchange.com/a/215803/46716

      – Gediminas
      May 9 '18 at 9:41











      0














      Create in own theme file Magento_Swatches/templates/product/view/renderer.phtml



      add the next code like



      require([
      'jquery'
      ], function ($)
      $('[data-role="swatch-options"]').on('swatch.initialized', function ()
      $(this).find('.swatch-attribute.color .swatch-option').first().click();
      );
      );





      share|improve this answer



























        0














        Create in own theme file Magento_Swatches/templates/product/view/renderer.phtml



        add the next code like



        require([
        'jquery'
        ], function ($)
        $('[data-role="swatch-options"]').on('swatch.initialized', function ()
        $(this).find('.swatch-attribute.color .swatch-option').first().click();
        );
        );





        share|improve this answer

























          0












          0








          0







          Create in own theme file Magento_Swatches/templates/product/view/renderer.phtml



          add the next code like



          require([
          'jquery'
          ], function ($)
          $('[data-role="swatch-options"]').on('swatch.initialized', function ()
          $(this).find('.swatch-attribute.color .swatch-option').first().click();
          );
          );





          share|improve this answer













          Create in own theme file Magento_Swatches/templates/product/view/renderer.phtml



          add the next code like



          require([
          'jquery'
          ], function ($)
          $('[data-role="swatch-options"]').on('swatch.initialized', function ()
          $(this).find('.swatch-attribute.color .swatch-option').first().click();
          );
          );






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 26 '18 at 10:15









          user2483213user2483213

          1




          1





















              0














              Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
              to your theme

              your theme file location will be:

              app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js



              change _RenderControls() function



              just wrinte below code at the end of this function



              var swatchLength = $('.swatch-attribute').length;
              if(swatchLength >= 1)
              if($('.swatch-attribute').hasClass("size"))
              $('.swatch-option').first().trigger('click');




              http://prntscr.com/n6qo62





              share



























                0














                Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
                to your theme

                your theme file location will be:

                app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js



                change _RenderControls() function



                just wrinte below code at the end of this function



                var swatchLength = $('.swatch-attribute').length;
                if(swatchLength >= 1)
                if($('.swatch-attribute').hasClass("size"))
                $('.swatch-option').first().trigger('click');




                http://prntscr.com/n6qo62





                share

























                  0












                  0








                  0







                  Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
                  to your theme

                  your theme file location will be:

                  app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js



                  change _RenderControls() function



                  just wrinte below code at the end of this function



                  var swatchLength = $('.swatch-attribute').length;
                  if(swatchLength >= 1)
                  if($('.swatch-attribute').hasClass("size"))
                  $('.swatch-option').first().trigger('click');




                  http://prntscr.com/n6qo62





                  share













                  Override vendormagentomodule-swatchesviewfrontendwebjsswatch-renderer.js
                  to your theme

                  your theme file location will be:

                  app/design/frontend/Vendor/themename/Magento_Swatches/web/js/swatch-renderer.js



                  change _RenderControls() function



                  just wrinte below code at the end of this function



                  var swatchLength = $('.swatch-attribute').length;
                  if(swatchLength >= 1)
                  if($('.swatch-attribute').hasClass("size"))
                  $('.swatch-option').first().trigger('click');




                  http://prntscr.com/n6qo62






                  share











                  share


                  share










                  answered 8 mins ago









                  Jigs ParmarJigs Parmar

                  1,132423




                  1,132423



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Magento Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f128710%2fhow-to-set-default-color-configurable-product%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Can not update quote_id field of “quote_item” table magento 2Magento 2.1 - We can't remove the item. (Shopping Cart doesnt allow us to remove items before becomes empty)Add value for custom quote item attribute using REST apiREST API endpoint v1/carts/cartId/items always returns error messageCorrect way to save entries to databaseHow to remove all associated quote objects of a customer completelyMagento 2 - Save value from custom input field to quote_itemGet quote_item data using quote id and product id filter in Magento 2How to set additional data to quote_item table from controller in Magento 2?What is the purpose of additional_data column in quote_item table in magento2Set Custom Price to Quote item magento2 from controller

                      How to solve knockout JS error in Magento 2 Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?(Magento2) knockout.js:3012 Uncaught ReferenceError: Unable to process bindingUnable to process binding Knockout.js magento 2Cannot read property `scopeLabel` of undefined on Product Detail PageCan't get Customer Data on frontend in Magento 2Magento2 Order Summary - unable to process bindingKO templates are not loading in Magento 2.1 applicationgetting knockout js error magento 2Product grid not load -— Unable to process binding Knockout.js magento 2Product form not loaded in magento2Uncaught ReferenceError: Unable to process binding “if: function()return (isShowLegend()) ” magento 2

                      Nissan Patrol Зміст Перше покоління — 4W60 (1951-1960) | Друге покоління — 60 series (1960-1980) | Третє покоління (1980–2002) | Четверте покоління — Y60 (1987–1998) | П'яте покоління — Y61 (1997–2013) | Шосте покоління — Y62 (2010- ) | Посилання | Зноски | Навігаційне менюОфіційний український сайтТест-драйв Nissan Patrol 2010 7-го поколінняNissan PatrolКак мы тестировали Nissan Patrol 2016рвиправивши або дописавши її