Skip to content

Commit 1ddec1e

Browse files
committed
MC-41652: Reflect changed price: Product
1 parent da1aec5 commit 1ddec1e

File tree

5 files changed

+71
-8
lines changed

5 files changed

+71
-8
lines changed

app/code/Magento/Catalog/view/base/web/js/price-box.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ define([
131131
}, this);
132132
}
133133

134+
this.element.trigger('priceUpdated', this.cache.displayPrices);
134135
this.element.trigger('reloadPrice');
135136
},
136137

app/code/Magento/Paypal/Block/PayLater/Banner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private function getPayPalSdkUrl()
7878
*/
7979
private function getConfig()
8080
{
81-
return [];
81+
return ['data-pp-style-logo-position' => 'right'];
8282
}
8383

8484
/**

app/code/Magento/Paypal/etc/csp_whitelist.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
<value id="paypal_analytics" type="host">t.paypal.com</value>
2626
</values>
2727
</policy>
28+
<policy id="connect-src">
29+
<values>
30+
<value id="www_sandbox_paypal" type="host">www.sandbox.paypal.com</value>
31+
</values>
32+
</policy>
2833
<policy id="frame-src">
2934
<values>
3035
<value id="www_paypal" type="host">www.paypal.com</value>

app/code/Magento/Paypal/view/frontend/web/js/view/paylater.js

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
*/
55

66
define([
7+
'jquery',
78
'ko',
89
'uiElement',
9-
'Magento_Paypal/js/in-context/paypal-sdk'
10+
'Magento_Paypal/js/in-context/paypal-sdk',
11+
'domReady!'
1012
], function (
13+
$,
1114
ko,
1215
Component,
1316
paypalSdk
@@ -19,24 +22,78 @@ define([
1922
defaults: {
2023
template: 'Magento_Paypal/paylater',
2124
sdkUrl: '',
22-
attributes: {
23-
'data-pp-amount': '',
24-
'data-pp-style-logo-position': 'right'
25-
}
25+
priceBoxSelector: '.price-box',
26+
qtyFieldSelector: '#product_addtocart_form [name="qty"]',
27+
displayAmount: true,
28+
attributes: {}
2629
},
30+
amount: ko.observable(),
31+
qty: 1,
32+
price: 0,
2733

2834
/**
2935
* Initialize
3036
*
3137
* @returns {*}
3238
*/
3339
initialize: function () {
40+
var priceBox, qty;
41+
3442
this._super();
3543
this.loadPayPalSdk(this.sdkUrl);
3644

45+
if (this.displayAmount) {
46+
priceBox = $(this.priceBoxSelector);
47+
this.price = priceBox.priceBox('option').priceConfig.prices.finalPrice.amount;
48+
priceBox.on('priceUpdated', this._onPriceChange.bind(this));
49+
50+
qty = $(this.qtyFieldSelector);
51+
qty.on('change', this._onQtyChange.bind(this));
52+
53+
this._updateAmount();
54+
}
55+
3756
return this;
3857
},
3958

59+
/**
60+
* Handle changed product qty
61+
*
62+
* @param {jQuery.Event} event
63+
* @private
64+
*/
65+
_onQtyChange: function (event) {
66+
var qty = parseFloat($(event.target).val());
67+
68+
this.qty = !isNaN(qty) && qty ? qty : 1;
69+
this._updateAmount();
70+
},
71+
72+
/**
73+
* Handle product price change
74+
*
75+
* @param {jQuery.Event} event
76+
* @param {Object} data
77+
* @private
78+
*/
79+
_onPriceChange: function (event, data) {
80+
this.price = data.finalPrice.amount;
81+
this._updateAmount();
82+
},
83+
84+
/**
85+
* Calculate and update amount
86+
*
87+
* @private
88+
*/
89+
_updateAmount: function () {
90+
var amount = this.price * this.qty;
91+
92+
if (amount !== 0) {
93+
this.amount(amount);
94+
}
95+
},
96+
4097
/**
4198
* Get attribute value from configuration
4299
*

app/code/Magento/Paypal/view/frontend/web/template/paylater.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77
<div data-pp-message data-bind="attr: {
8-
'data-pp-amount': getAttribute('data-pp-amount'),
8+
'data-pp-amount': amount,
99
'data-pp-placement': getAttribute('data-pp-placement'),
1010
'data-pp-style-layout': getAttribute('data-pp-style-layout'),
1111
'data-pp-style-logo-type': getAttribute('data-pp-style-logo-type'),
@@ -14,5 +14,5 @@
1414
'data-pp-style-text-size': getAttribute('data-pp-style-text-size'),
1515
'data-pp-style-color': getAttribute('data-pp-style-color'),
1616
'data-pp-style-ratio': getAttribute('data-pp-style-ratio'),
17-
}"></div>
17+
}" ></div>
1818

0 commit comments

Comments
 (0)