Skip to content

Commit 73b1515

Browse files
committed
Merge branch 'ACP2E-2308' of https://github.com/magento-l3/magento2ce into Tier4-PR-10-30-2023
2 parents b8d8c7a + 3a31d15 commit 73b1515

File tree

4 files changed

+105
-32
lines changed

4 files changed

+105
-32
lines changed

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ define([
2222
options: {
2323
superSelector: '.super-attribute-select',
2424
selectSimpleProduct: '[name="selected_configurable_option"]',
25+
26+
/**
27+
* @deprecated Not used anymore
28+
* @see selectorProductPrice
29+
*/
2530
priceHolderSelector: '.price-box',
2631
spConfig: {},
2732
state: {},
@@ -86,7 +91,7 @@ define([
8691
_initializeOptions: function () {
8792
var options = this.options,
8893
gallery = $(options.mediaGallerySelector),
89-
priceBoxOptions = $(this.options.priceHolderSelector).priceBox('option').priceConfig || null;
94+
priceBoxOptions = this._getPriceBoxElement().priceBox('option').priceConfig || null;
9095

9196
if (priceBoxOptions && priceBoxOptions.optionTemplate) {
9297
options.optionTemplate = priceBoxOptions.optionTemplate;
@@ -100,7 +105,7 @@ define([
100105

101106
options.settings = options.spConfig.containerId ?
102107
$(options.spConfig.containerId).find(options.superSelector) :
103-
$(options.superSelector);
108+
this.element.parents(this.options.selectorProduct).find(options.superSelector);
104109

105110
options.values = options.spConfig.defaultValues || {};
106111
options.parentImage = $('[data-role=base-image-container] img').attr('src');
@@ -580,7 +585,7 @@ define([
580585
* configurable product's option selections.
581586
*/
582587
_reloadPrice: function () {
583-
$(this.options.priceHolderSelector).trigger('updatePrice', this._getPrices());
588+
this._getPriceBoxElement().trigger('updatePrice', this._getPrices());
584589
},
585590

586591
/**
@@ -654,7 +659,7 @@ define([
654659
* @private
655660
*/
656661
_calculatePrice: function (config) {
657-
var displayPrices = $(this.options.priceHolderSelector).priceBox('option').prices,
662+
var displayPrices = this._getPriceBoxElement().priceBox('option').prices,
658663
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)] || {};
659664

660665
_.each(displayPrices, function (price, code) {
@@ -702,8 +707,7 @@ define([
702707
*/
703708
_displayRegularPriceBlock: function (optionId) {
704709
var shouldBeShown = true,
705-
$priceBox = this.element.parents(this.options.selectorProduct)
706-
.find(this.options.selectorProductPrice);
710+
$priceBox = this._getPriceBoxElement();
707711

708712
_.each(this.options.settings, function (element) {
709713
if (element.value === '') {
@@ -785,6 +789,18 @@ define([
785789
} else {
786790
$(this.options.tierPriceBlockSelector).hide();
787791
}
792+
},
793+
794+
/**
795+
* Returns the price container element
796+
*
797+
* @returns {*}
798+
* @private
799+
*/
800+
_getPriceBoxElement: function () {
801+
return this.element
802+
.parents(this.options.selectorProduct)
803+
.find(this.options.selectorProductPrice);
788804
}
789805
});
790806

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ define([
280280
// tier prise selectors end
281281

282282
// A price label selector
283-
normalPriceLabelSelector: '.product-info-main .normal-price .price-label',
283+
normalPriceLabelSelector: '.normal-price .price-label',
284284
qtyInfo: '#qty'
285285
},
286286

@@ -1039,18 +1039,18 @@ define([
10391039
$(this.options.tierPriceBlockSelector).hide();
10401040
}
10411041

1042-
$(this.options.normalPriceLabelSelector).hide();
1042+
$product.find(this.options.normalPriceLabelSelector).hide();
10431043

1044-
_.each($('.' + this.options.classes.attributeOptionsWrapper), function (attribute) {
1044+
_.each(this.element.find('.' + this.options.classes.attributeOptionsWrapper), function (attribute) {
10451045
if ($(attribute).find('.' + this.options.classes.optionClass + '.selected').length === 0) {
10461046
if ($(attribute).find('.' + this.options.classes.selectClass).length > 0) {
10471047
_.each($(attribute).find('.' + this.options.classes.selectClass), function (dropdown) {
10481048
if ($(dropdown).val() === '0') {
1049-
$(this.options.normalPriceLabelSelector).show();
1049+
$product.find(this.options.normalPriceLabelSelector).show();
10501050
}
10511051
}.bind(this));
10521052
} else {
1053-
$(this.options.normalPriceLabelSelector).show();
1053+
$product.find(this.options.normalPriceLabelSelector).show();
10541054
}
10551055
}
10561056
}.bind(this));

dev/tests/js/jasmine/tests/app/code/Magento/ConfigurableProduct/view/frontend/js/configurable.test.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ define([
6767
'salable': []
6868
}
6969
},
70-
blockHtml = '<form id="cart"/>'
71-
+ '<select name=\'super_attribute[93]\'' +
70+
blockHtml = '<div class="product-info-main">' +
71+
'<div class="product-info-price">' +
72+
'<div class="price-box price-final_price" data-role="priceBox">' +
73+
'</div>' +
74+
'</div>' +
75+
'<div class="product-add-form">' +
76+
'<form id="cart"/>' +
77+
'<select name=\'super_attribute[93]\'' +
7278
' data-selector=\'super_attribute[93]\'' +
7379
' data-validate=\'{required:true}\'' +
7480
' id=\'attribute93\'' +
@@ -78,7 +84,9 @@ define([
7884
'<option value=\'15\'>beige</option>' +
7985
'</select>' +
8086
'<input id="qty"/>' +
81-
'</form>',
87+
'</form>' +
88+
'</div>' +
89+
'</div>',
8290
selectElement,
8391
qtyElement,
8492
formElement;
@@ -89,13 +97,22 @@ define([
8997
selectElement = $('#attribute93');
9098
qtyElement = $('#qty');
9199
formElement = $('#cart');
92-
widget = new Configurable($.extend(true, {}, options), formElement);
93100
$.fn.trigFunc = $.fn.trigger;
101+
$.fn.priceBoxFunc = $.fn.priceBox;
102+
$.fn.priceBox = function () {
103+
return {
104+
prices: $.extend(true, {}, this.data('price-box'))
105+
};
106+
};
107+
$('body').find('[data-role=priceBox]').data('price-box', $.extend(true, {}, options.spConfig.prices));
108+
widget = new Configurable($.extend(true, {}, options), formElement);
94109
});
95110
afterEach(function () {
96111
formElement.remove();
97112
$.fn.trigger = $.fn.trigFunc;
113+
$.fn.priceBox = $.fn.priceBoxFunc;
98114
delete $.fn.trigFunc;
115+
delete $.fn.priceBoxFunc;
99116
});
100117
it('check if attribute value is possible to be set as configurable option', function () {
101118
expect($.mage.configurable).toBeDefined();
@@ -112,17 +129,6 @@ define([
112129
it('check if widget will return correct price values in case option is selected or not.', function () {
113130
var result;
114131

115-
spyOn($.fn, 'priceBox').and.callFake(function () {
116-
return {
117-
prices: {
118-
'baseOldPrice': {'amount': 10},
119-
'oldPrice': {'amount': 10},
120-
'basePrice': {'amount': 10},
121-
'finalPrice': {'amount': 10},
122-
'msrpPrice': {'amount': 0}
123-
}
124-
};
125-
});
126132
result = widget._getPrices().prices;
127133
expect(result.baseOldPrice.amount).toBe(0);
128134
expect(result.oldPrice.amount).toBe(0);
@@ -140,7 +146,26 @@ define([
140146
it('check that price is reloaded on qty change', function () {
141147
spyOn($.fn, 'trigger');
142148
qtyElement.trigFunc('input');
143-
expect($.fn.trigger).toHaveBeenCalledWith('updatePrice', {});
149+
expect($.fn.trigger)
150+
.toHaveBeenCalledWith(
151+
'updatePrice',
152+
{
153+
prices: {
154+
baseOldPrice: {
155+
amount: 0
156+
},
157+
oldPrice: {
158+
amount: 0
159+
},
160+
basePrice: {
161+
amount: 0
162+
},
163+
finalPrice: {
164+
amount: 0
165+
}
166+
}
167+
}
168+
);
144169
});
145170

146171
it('check if the _configureElement method is enabling configurable option or not', function () {

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

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,23 +94,55 @@ define([
9494
});
9595

9696
it('check udate price method', function () {
97-
var productPriceMock = {
98-
find: jasmine.createSpy().and.returnValue({
99-
hide: jasmine.createSpy(),
97+
var productBlock, parentsResultMap, findResultMap;
98+
99+
parentsResultMap = {
100+
'[data-role=priceBox]': {
100101
priceBox: jasmine.createSpy().and.returnValue(''),
101102
trigger: jasmine.createSpy(),
102103
find: jasmine.createSpy().and.returnValue({
103104
toggleClass: jasmine.createSpy()
104105
})
106+
},
107+
'.normal-price .price-label': {
108+
hide: jasmine.createSpy(),
109+
show: jasmine.createSpy()
110+
},
111+
'.sly-old-price': {
112+
hide: jasmine.createSpy()
113+
}
114+
};
115+
116+
findResultMap = {
117+
'.swatch-attribute-options': [
118+
$('<div class="swatch-attribute-options"><div class="swatch-option"></div></div>')
119+
]
120+
};
121+
122+
productBlock = {
123+
// eslint-disable-next-line max-nested-callbacks
124+
find: jasmine.createSpy().and.callFake(function (selector) {
125+
return parentsResultMap[selector];
105126
})
106127
};
107128

108129
widget.element = {
109-
parents: jasmine.createSpy().and.returnValue(productPriceMock)
130+
parents: jasmine.createSpy().and.returnValue(productBlock),
131+
// eslint-disable-next-line max-nested-callbacks
132+
find: jasmine.createSpy().and.callFake(function (selector) {
133+
return findResultMap[selector];
134+
})
110135
};
111136
widget._getNewPrices = jasmine.createSpy().and.returnValue(undefined);
112137
widget._UpdatePrice();
113-
expect(productPriceMock.find().find.calls.count()).toBe(1);
138+
expect(widget.element.parents).toHaveBeenCalledOnceWith('.product-info-main');
139+
expect(widget.element.find).toHaveBeenCalledOnceWith('.swatch-attribute-options');
140+
expect(parentsResultMap['[data-role=priceBox]'].find).toHaveBeenCalledOnceWith('span:first');
141+
expect(parentsResultMap['.sly-old-price'].hide).toHaveBeenCalledTimes(1);
142+
expect(parentsResultMap['.normal-price .price-label'].hide).toHaveBeenCalledTimes(1);
143+
expect(parentsResultMap['.normal-price .price-label'].hide)
144+
.toHaveBeenCalledBefore(parentsResultMap['.normal-price .price-label'].show);
145+
expect(parentsResultMap['.normal-price .price-label'].show).toHaveBeenCalledTimes(1);
114146
});
115147

116148
it('check getSelectedOptionPriceIndex', function () {

0 commit comments

Comments
 (0)