Skip to content

Commit 11a67d0

Browse files
authored
ENGCOM-6750: #26240: Fixed logic for getting option price index for selected swatch option #26241
2 parents 1ce92f7 + edd003f commit 11a67d0

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ define([
759759

760760
$(document).trigger('updateMsrpPriceBlock',
761761
[
762-
_.findKey($widget.options.jsonConfig.index, $widget.options.jsonConfig.defaultValues),
762+
this._getSelectedOptionPriceIndex(),
763763
$widget.options.jsonConfig.optionPrices
764764
]);
765765

@@ -770,6 +770,22 @@ define([
770770
$input.trigger('change');
771771
},
772772

773+
/**
774+
* Get selected option price index
775+
*
776+
* @return {String|undefined}
777+
* @private
778+
*/
779+
_getSelectedOptionPriceIndex: function () {
780+
var allowedProduct = this._getAllowedProductWithMinPrice(this._CalcProducts());
781+
782+
if (_.isEmpty(allowedProduct)) {
783+
return undefined;
784+
}
785+
786+
return allowedProduct;
787+
},
788+
773789
/**
774790
* Get human readable attribute code (eg. size, color) by it ID from configuration
775791
*

dev/tests/js/jasmine/tests/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,37 @@ define([
9898
widget._UpdatePrice();
9999
expect(productPriceMock.find().find.calls.count()).toBe(1);
100100
});
101+
102+
it('check getSelectedOptionPriceIndex', function () {
103+
var optionMock = '<div class="swatch-attribute" attribute-id="2" option-selected="4"></div>',
104+
element = $('<div class="' + widget.options.tooltipClass +
105+
'"><div class="image"></div><div class="title"></div><div class="corner"></div>' +
106+
optionMock + '</div>'
107+
),
108+
optionPricesMock = {
109+
optionPrices: {
110+
p: {
111+
finalPrice: {
112+
amount: 12
113+
}
114+
}
115+
}
116+
};
117+
118+
widget.element = element;
119+
widget.options.classes.attributeClass = 'swatch-attribute';
120+
widget.options.jsonConfig = optionPricesMock;
121+
widget.optionsMap = {
122+
2: {
123+
4: {
124+
products: 'p'
125+
},
126+
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
127+
},
128+
hasOwnProperty: jasmine.createSpy().and.returnValue(true)
129+
};
130+
131+
expect(widget._getSelectedOptionPriceIndex()).toBe('p');
132+
});
101133
});
102134
});

0 commit comments

Comments
 (0)