Pass extra class for stock in Swatch Magento2
-
17-01-2021 - |
Question
I want to pass an extra class to swatch class which is formed via swatch renderer js based on the stock. The reason is the swatches are not being hidden if they are out of stock. This is what I am trying to do -
$.each($widget.options.jsonConfig.product_information, function () {
var item = this;
inStock = item.is_in_stock;
if(inStock != true){
stockClass = 'hideStock';
} else{
stockClass = 'showStock';
}
});
attr =+
' id="' + controlId + '-item-' + id + '"' +
' aria-checked="false"' +
' aria-describedby="' + controlId + '"' +
' tabindex="0"' +
' option-type="' + type + '"' +
' option-id="' + id + '"' +
' option-label="' + label + '"' +
' aria-label="' + label + '"' +
' option-tooltip-thumb="' + thumb + '"' +
' option-tooltip-value="' + value + '"' +
' title="' + stockClass + '"' +
' class="' + stockClass + '"' +
' role="option"';
The title is coming in the div, but not class. But the title is not coming correctly too. Its somehow looping twice. or Giving incorrect result.
La solution
Solved my problem using - https://github.com/magento/magento2/commit/4c99f2895cee70e48bff093e083a408972d82a7d
Patch provided
Licencié sous: CC-BY-SA avec attribution
Non affilié à magento.stackexchange