Auto Select colour Swatch when configurable product page loadsAuto select option based on category ?Configurable Swatches on Listing Page: Show Multiple Color AttributesConfigurable product with multiple color variationsChange More product images on color swatch selectConfigurable swatch not working properlyIs there a way to automatically select the first colour swatch on the product page?Is there any way that one swatch is selected by default (magento configurable swatches)How to change image size on category page when click swatchHow to Auto Select The Color as Swatch Option for Products with Only One Color (on Magento 2.1 Product View)?Hide Configurable product images from details page when color swatch is selected

Revoked SSL certificate

Can you really stack all of this on an Opportunity Attack?

Codimension of non-flat locus

Cross compiling for RPi - error while loading shared libraries

Why do I get two different answers for this counting problem?

Is it inappropriate for a student to attend their mentor's dissertation defense?

NMaximize is not converging to a solution

How is it possible to have an ability score that is less than 3?

Did Shadowfax go to Valinor?

Can I ask the recruiters in my resume to put the reason why I am rejected?

Approximately how much travel time was saved by the opening of the Suez Canal in 1869?

How much RAM could one put in a typical 80386 setup?

Is it possible to run Internet Explorer on OS X El Capitan?

When a company launches a new product do they "come out" with a new product or do they "come up" with a new product?

What defenses are there against being summoned by the Gate spell?

How to determine what difficulty is right for the game?

How old can references or sources in a thesis be?

How does quantile regression compare to logistic regression with the variable split at the quantile?

LaTeX: Why are digits allowed in environments, but forbidden in commands?

Is it possible to do 50 km distance without any previous training?

I'm flying to France today and my passport expires in less than 2 months

Today is the Center

Convert two switches to a dual stack, and add outlet - possible here?

Maximum likelihood parameters deviate from posterior distributions



Auto Select colour Swatch when configurable product page loads


Auto select option based on category ?Configurable Swatches on Listing Page: Show Multiple Color AttributesConfigurable product with multiple color variationsChange More product images on color swatch selectConfigurable swatch not working properlyIs there a way to automatically select the first colour swatch on the product page?Is there any way that one swatch is selected by default (magento configurable swatches)How to change image size on category page when click swatchHow to Auto Select The Color as Swatch Option for Products with Only One Color (on Magento 2.1 Product View)?Hide Configurable product images from details page when color swatch is selected






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I have a configurable product with one colour and different sizes, both these are set as required fields.



I've set the colour attribute as not required, but then it wont show up when I create a configurable product and wont show on the product page.



How do I get the colour swatch to be automatically selected when the product page loads?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What is your question?

    – Robbie Averill
    Jun 27 '16 at 12:05











  • How do I get the colour swatch to be automatically selected when the product page loads?

    – user2240778
    Jun 27 '16 at 13:21

















2















I have a configurable product with one colour and different sizes, both these are set as required fields.



I've set the colour attribute as not required, but then it wont show up when I create a configurable product and wont show on the product page.



How do I get the colour swatch to be automatically selected when the product page loads?










share|improve this question
















bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • What is your question?

    – Robbie Averill
    Jun 27 '16 at 12:05











  • How do I get the colour swatch to be automatically selected when the product page loads?

    – user2240778
    Jun 27 '16 at 13:21













2












2








2








I have a configurable product with one colour and different sizes, both these are set as required fields.



I've set the colour attribute as not required, but then it wont show up when I create a configurable product and wont show on the product page.



How do I get the colour swatch to be automatically selected when the product page loads?










share|improve this question
















I have a configurable product with one colour and different sizes, both these are set as required fields.



I've set the colour attribute as not required, but then it wont show up when I create a configurable product and wont show on the product page.



How do I get the colour swatch to be automatically selected when the product page loads?







magento-1.9 configurable-product javascript color-swatches






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 27 '16 at 13:21







user2240778

















asked Jun 27 '16 at 12:03









user2240778user2240778

298315




298315





bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







bumped to the homepage by Community yesterday


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.














  • What is your question?

    – Robbie Averill
    Jun 27 '16 at 12:05











  • How do I get the colour swatch to be automatically selected when the product page loads?

    – user2240778
    Jun 27 '16 at 13:21

















  • What is your question?

    – Robbie Averill
    Jun 27 '16 at 12:05











  • How do I get the colour swatch to be automatically selected when the product page loads?

    – user2240778
    Jun 27 '16 at 13:21
















What is your question?

– Robbie Averill
Jun 27 '16 at 12:05





What is your question?

– Robbie Averill
Jun 27 '16 at 12:05













How do I get the colour swatch to be automatically selected when the product page loads?

– user2240778
Jun 27 '16 at 13:21





How do I get the colour swatch to be automatically selected when the product page loads?

– user2240778
Jun 27 '16 at 13:21










2 Answers
2






active

oldest

votes


















0














Open this file from appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml



Now add the below javascript code :-



 function fireEvent(element,event)
if (document.createEventObject)
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)

else
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);


Event.observe(window, 'load', function()
spConfig.settings[0].selectedIndex = 1;
obj = spConfig.settings[0]; // this grabs the first select item
Event.observe(obj,'change',function());
fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
);


after this code :-



var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


and flush magento cache and check.






share|improve this answer






























    0














    If you want to go with jQuery in magento
    so you can trigger with click on color swatches on document ready



    jQuery("document").ready(function() 
    setTimeout(function()
    jQuery("#configurable_swatch li:last-child a span").trigger('click');
    ,100);
    );





    share|improve this answer























      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%2f122954%2fauto-select-colour-swatch-when-configurable-product-page-loads%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Open this file from appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml



      Now add the below javascript code :-



       function fireEvent(element,event)
      if (document.createEventObject)
      // dispatch for IE
      var evt = document.createEventObject();
      return element.fireEvent('on'+event,evt)

      else
      // dispatch for firefox + others
      var evt = document.createEvent("HTMLEvents");
      evt.initEvent(event, true, true ); // event type,bubbling,cancelable
      return !element.dispatchEvent(evt);


      Event.observe(window, 'load', function()
      spConfig.settings[0].selectedIndex = 1;
      obj = spConfig.settings[0]; // this grabs the first select item
      Event.observe(obj,'change',function());
      fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
      spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
      );


      after this code :-



      var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


      and flush magento cache and check.






      share|improve this answer



























        0














        Open this file from appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml



        Now add the below javascript code :-



         function fireEvent(element,event)
        if (document.createEventObject)
        // dispatch for IE
        var evt = document.createEventObject();
        return element.fireEvent('on'+event,evt)

        else
        // dispatch for firefox + others
        var evt = document.createEvent("HTMLEvents");
        evt.initEvent(event, true, true ); // event type,bubbling,cancelable
        return !element.dispatchEvent(evt);


        Event.observe(window, 'load', function()
        spConfig.settings[0].selectedIndex = 1;
        obj = spConfig.settings[0]; // this grabs the first select item
        Event.observe(obj,'change',function());
        fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
        spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
        );


        after this code :-



        var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


        and flush magento cache and check.






        share|improve this answer

























          0












          0








          0







          Open this file from appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml



          Now add the below javascript code :-



           function fireEvent(element,event)
          if (document.createEventObject)
          // dispatch for IE
          var evt = document.createEventObject();
          return element.fireEvent('on'+event,evt)

          else
          // dispatch for firefox + others
          var evt = document.createEvent("HTMLEvents");
          evt.initEvent(event, true, true ); // event type,bubbling,cancelable
          return !element.dispatchEvent(evt);


          Event.observe(window, 'load', function()
          spConfig.settings[0].selectedIndex = 1;
          obj = spConfig.settings[0]; // this grabs the first select item
          Event.observe(obj,'change',function());
          fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
          spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
          );


          after this code :-



          var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


          and flush magento cache and check.






          share|improve this answer













          Open this file from appdesignfrontend[your package][your theme]templatecatalogproductviewtypeoptionsconfigurable.phtml



          Now add the below javascript code :-



           function fireEvent(element,event)
          if (document.createEventObject)
          // dispatch for IE
          var evt = document.createEventObject();
          return element.fireEvent('on'+event,evt)

          else
          // dispatch for firefox + others
          var evt = document.createEvent("HTMLEvents");
          evt.initEvent(event, true, true ); // event type,bubbling,cancelable
          return !element.dispatchEvent(evt);


          Event.observe(window, 'load', function()
          spConfig.settings[0].selectedIndex = 1;
          obj = spConfig.settings[0]; // this grabs the first select item
          Event.observe(obj,'change',function());
          fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
          spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
          );


          after this code :-



          var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);


          and flush magento cache and check.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered May 10 '17 at 13:28









          Jaimin PatelJaimin Patel

          255




          255























              0














              If you want to go with jQuery in magento
              so you can trigger with click on color swatches on document ready



              jQuery("document").ready(function() 
              setTimeout(function()
              jQuery("#configurable_swatch li:last-child a span").trigger('click');
              ,100);
              );





              share|improve this answer



























                0














                If you want to go with jQuery in magento
                so you can trigger with click on color swatches on document ready



                jQuery("document").ready(function() 
                setTimeout(function()
                jQuery("#configurable_swatch li:last-child a span").trigger('click');
                ,100);
                );





                share|improve this answer

























                  0












                  0








                  0







                  If you want to go with jQuery in magento
                  so you can trigger with click on color swatches on document ready



                  jQuery("document").ready(function() 
                  setTimeout(function()
                  jQuery("#configurable_swatch li:last-child a span").trigger('click');
                  ,100);
                  );





                  share|improve this answer













                  If you want to go with jQuery in magento
                  so you can trigger with click on color swatches on document ready



                  jQuery("document").ready(function() 
                  setTimeout(function()
                  jQuery("#configurable_swatch li:last-child a span").trigger('click');
                  ,100);
                  );






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 1 '18 at 13:02









                  Pradip GarcharPradip Garchar

                  12114




                  12114



























                      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%2f122954%2fauto-select-colour-swatch-when-configurable-product-page-loads%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

                      Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

                      Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                      Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form