cancel
Showing results for 
Search instead for 
Did you mean: 

Current article (color) not pre-selected on product page

0 Kudos

Current article (color) not pre-selected on product page

Feature request from thdoan, posted on GitHub Jul 15, 2016

Steps to reproduce

  1. Install Magento from develop branch.
  2. Go to /caesar-warm-up-pant.html

Expected result

  1. The current article (gray in this case) should be pre-selected on initial page load.

Actual result

  1. None of the color swatches is selected by default.
2 Comments
apiuser
New Member

Comment from andimov, posted on GitHub Aug 03, 2016

screenshot_20160803_193631

apiuser
New Member

Comment from thdoan, posted on GitHub Aug 05, 2016

FYI for the time being I've patched it with this code:

Magento_Swatches/templates/product/view/renderer.phtml

// Select default color (article)
var sActiveImage = fotorama.activeFrame.img.replace(/^.+\/([^\/]+)/, '$1'),
  sActiveColorId;
for (var attributeId in oJsonConfig.attributes) {
  var oAttribute = oJsonConfig.attributes[attributeId];
  if (oAttribute.code==='color') {
    for (var i=0; i<oAttribute.options.length; ++i) {
      var oOptions = oAttribute.options[i],
        aImages = oJsonConfig.images[oOptions.products[0]];
      for (var j=0; j<aImages.length; ++j) {
        if (aImages[j].isMain && aImages[j].img.indexOf(sActiveImage)>-1) {
          // Main image (first position)
          sActiveColorId = oOptions.id;
          break;
        }
      }
      if (sActiveColorId) break;
    }
    break;
  }
}
// Click on the active color swatch
$('[option-id=' + sActiveColorId + ']').click();