Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thdoan opened this issue Jul 15, 2016 · 3 comments
Closed

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

thdoan opened this issue Jul 15, 2016 · 3 comments

Comments

@thdoan
Copy link

thdoan commented 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.
@andimov
Copy link
Contributor

andimov commented Aug 3, 2016

screenshot_20160803_193631

@thdoan
Copy link
Author

thdoan commented Aug 5, 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();

@piotrekkaminski
Copy link
Contributor

Thank you for your submission.

We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues.

Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here).

We are closing this GitHub ticket and have moved your request to the new forum.

slavvka pushed a commit that referenced this issue May 8, 2020
[Trigger] Fixes for Web-Api tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants