Skip to content

Commit 3896634

Browse files
committed
BUG#AC-2877: Product with Salable Qty of 0 shows In Stock on product page - issue fixed
1 parent 9be1703 commit 3896634

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

app/code/Magento/Swatches/view/base/web/js/swatch-renderer.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -459,20 +459,7 @@ define([
459459
'</div>' + input +
460460
'</div>'
461461
);
462-
463-
if ($widget.options.jsonConfig.canDisplayShowOutOfStockStatus) {
464-
let salableProd = $widget.options.jsonConfig.salable[item.id],
465-
swatchOptions = container.find('.swatch-option');
466-
467-
swatchOptions.each(function (key, value) {
468-
let optionId = $(value).data('option-id');
469-
470-
if (!salableProd.hasOwnProperty(optionId)) {
471-
$(value).attr('disabled', true).addClass('disabled');
472-
}
473-
});
474-
}
475-
462+
476463
$widget.optionsMap[item.id] = {};
477464

478465
// Aggregate options array to hash (key => value)
@@ -503,11 +490,35 @@ define([
503490
// Handle events like click or change
504491
$widget._EventListener();
505492

493+
// Rewind options
494+
$widget._Rewind(container);
495+
506496
//Emulate click on all swatches from Request
507497
$widget._EmulateSelected($.parseQuery());
508498
$widget._EmulateSelected($widget._getSelectedAttributes());
509499
},
510500

501+
disableSwatchForOutOfStockProducts: function () {
502+
let $widget = this, container = this.element;
503+
504+
$.each(this.options.jsonConfig.attributes, function () {
505+
let item = this;
506+
507+
if ($widget.options.jsonConfig.canDisplayShowOutOfStockStatus) {
508+
let salableProd = $widget.options.jsonConfig.salable[item.id],
509+
swatchOptions = container.find('.swatch-option');
510+
511+
swatchOptions.each(function (key, value) {
512+
let optionId = $(value).data('option-id');
513+
514+
if (!salableProd.hasOwnProperty(optionId)) {
515+
$(value).attr('disabled', true).addClass('disabled');
516+
}
517+
});
518+
}
519+
});
520+
},
521+
511522
/**
512523
* Render swatch options by part of config
513524
*
@@ -898,6 +909,7 @@ define([
898909
.attr('disabled', true)
899910
.addClass('disabled')
900911
.attr('tabindex', '-1');
912+
this.disableSwatchForOutOfStockProducts();
901913
},
902914

903915
/**

0 commit comments

Comments
 (0)