Preconditions
- Magento 2.1.5 (but it exists in all versions)
Steps to reproduce
- Go to a product page that has swatches, e.g. http://magento2-demo.nexcess.net/caesar-warm-up-pant.html
- Right-click and Inspect a swatch
Expected result
- The HTML for the swatch should be valid.
Actual result
- The swatch HTML is invalid (
"=""):
<div class="swatch-option image selected" option-type="2"
option-id="887"
option-label="Mossy Oak Break-up Country"
option-tooltip-thumb="https://muckbootusuat.specom.io/pub/media/attribute/swatch/swatch_thumb/110x90/s/w/swatch_realtree-apg.png"
option-tooltip-value="https://muckbootusuat.specom.io/pub/media/attribute/swatch/swatch_image/30x20/s/w/swatch_realtree-apg.png"
"=""
style="background: url("https://muckbootusuat.specom.io/pub/media/attribute/swatch/swatch_thumb/110x90/s/w/swatch_realtree-apg.png") center center no-repeat;"></div>
The root cause is in vendor/magento/module-swatches/view/frontend/web/js/swatch-renderer.js starting at around line 408:
} else if (type === 1) {
// Color
html += '<div class="' + optionClass + ' color" ' + attr +
'" style="background: ' + value +
' no-repeat center; background-size: initial;">' + '' +
'</div>';
} else if (type === 2) {
// Image
html += '<div class="' + optionClass + ' image" ' + attr +
'" style="background: url(' + value + ') no-repeat center; background-size: initial;">' + '' +
'</div>';
} else if (type === 3) {
To fix this, you need to remove the extra " before the style attribute:
} else if (type === 1) {
// Color
html += '<div class="' + optionClass + ' color" ' + attr +
' style="background: ' + value +
' no-repeat center; background-size: initial;">' + '' +
'</div>';
} else if (type === 2) {
// Image
html += '<div class="' + optionClass + ' image" ' + attr +
' style="background: url(' + value + ') no-repeat center; background-size: initial;">' + '' +
'</div>';
} else if (type === 3) {
Preconditions
Steps to reproduce
Expected result
Actual result
"=""):The root cause is in vendor/magento/module-swatches/view/frontend/web/js/swatch-renderer.js starting at around line 408:
To fix this, you need to remove the extra
"before thestyleattribute: