Skip to content

Commit bd27efb

Browse files
authored
Merge pull request #6874 from magento-trigger/MC-42177-1
[Trigger] PayLater bugfixes
2 parents 45a40fd + 7955395 commit bd27efb

File tree

10 files changed

+212
-7
lines changed

10 files changed

+212
-7
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public function getJsLayout()
8282
$componentConfig = $this->jsLayout['components']['payLater']['config'] ?? [];
8383
$defaultConfig = ['sdkUrl' => $this->getPayPalSdkUrl()];
8484
$config = array_replace($defaultConfig, $componentConfig);
85+
$displayAmount = $config['displayAmount'] ?? false;
86+
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
87+
? false : true;
8588

8689
//Extend block component attributes with defaults
8790
$componentAttributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ public function process($jsLayout)
7272
]
7373
];
7474
$config = array_replace($defaultConfig, $componentConfig);
75+
$displayAmount = $config['displayAmount'] ?? false;
76+
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
77+
? false : true;
7578

7679
$attributes = $this->payLaterConfig->getSectionConfig(
7780
PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT,

app/code/Magento/Paypal/Model/PayLaterConfig.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,14 @@ public function getSectionConfig(string $section, string $key)
134134

135135
return $this->configData[$section][$key];
136136
}
137+
138+
/**
139+
* Check if billing agreement is enabled
140+
*
141+
* @return bool
142+
*/
143+
public function isPPBillingAgreementEnabled(): bool
144+
{
145+
return $this->config->isMethodActive(Config::METHOD_BILLING_AGREEMENT);
146+
}
137147
}

app/code/Magento/Paypal/etc/adminhtml/system/payflow_link.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@
226226
</group>
227227
</group>
228228
<group id="payflow_link_advertise_paylater" translate="label" showInDefault="1" showInWebsite="1" sortOrder="60">
229-
<label>Advertise PayPal Paylater</label>
229+
<label>Advertise PayPal PayLater</label>
230230
<field id="paylater_enabled" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_paylater/paylater_enabled" />
231231
<depends>
232232
<field id="enable_paypal_paylater_experience">1</field>

app/code/Magento/Paypal/etc/adminhtml/system/payments_pro_hosted_solution.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@
154154
</group>
155155
</group>
156156
<group id="pphs_advertise_paylater" translate="label" showInDefault="1" showInWebsite="1" sortOrder="60">
157-
<label>Advertise PayPal Paylater</label>
157+
<label>Advertise PayPal PayLater</label>
158158
<field id="paylater_enabled" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_paylater/paylater_enabled" />
159159
<depends>
160160
<field id="enable_paypal_paylater_experience">1</field>

app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
</field>
9797
<field id="enable_paypal_paylater_experience" sortOrder="30" extends="payment_all_paypal/express_checkout/express_checkout_required/enable_paypal_paylater_experience"/>
9898
<group id="paypal_payflow_advertise_paylater" translate="label" showInDefault="1" showInWebsite="1" sortOrder="40">
99-
<label>Advertise PayPal Paylater</label>
99+
<label>Advertise PayPal PayLater</label>
100100
<field id="paylater_enabled" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_paylater/paylater_enabled" />
101101
<depends>
102102
<field id="enable_paypal_paylater_experience">1</field>

app/code/Magento/Paypal/etc/adminhtml/system/paypal_payflowpro_with_express_checkout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
</group>
151151
</group>
152152
<group id="paypal_payflow_advertise_paylater" translate="label" showInDefault="1" showInWebsite="1" sortOrder="60">
153-
<label>Advertise PayPal Paylater</label>
153+
<label>Advertise PayPal PayLater</label>
154154
<field id="paylater_enabled" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_paylater/paylater_enabled" />
155155
<depends>
156156
<field id="enable_paypal_paylater_experience">1</field>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<body>
10+
<referenceContainer name="top.container">
11+
<block class="Magento\Paypal\Block\PayLater\Banner" name="top.container.paylater"
12+
template="Magento_Paypal::paylater/banner.phtml">
13+
<arguments>
14+
<argument name="placement" xsi:type="string">product</argument>
15+
<argument name="position" xsi:type="string">header</argument>
16+
<argument name="jsLayout" xsi:type="array">
17+
<item name="components" xsi:type="array">
18+
<item name="payLater" xsi:type="array">
19+
<item name="config" xsi:type="array">
20+
<item name="displayAmount" xsi:type="boolean">true</item>
21+
<item name="amountComponentConfig" xsi:type="array">
22+
<item name="component" xsi:type="string">
23+
Magento_Paypal/js/view/amountProviders/product-grouped
24+
</item>
25+
</item>
26+
</item>
27+
</item>
28+
</item>
29+
</argument>
30+
</arguments>
31+
</block>
32+
</referenceContainer>
33+
<referenceContainer name="product.info.addtocart">
34+
<block class="Magento\Paypal\Block\PayLater\Banner" name="product.info.addtocart.paylater"
35+
template="Magento_Paypal::paylater/banner.phtml">
36+
<arguments>
37+
<argument name="placement" xsi:type="string">product</argument>
38+
<argument name="position" xsi:type="string">near_pp_button</argument>
39+
<argument name="jsLayout" xsi:type="array">
40+
<item name="components" xsi:type="array">
41+
<item name="payLater" xsi:type="array">
42+
<item name="config" xsi:type="array">
43+
<item name="displayAmount" xsi:type="boolean">true</item>
44+
<item name="amountComponentConfig" xsi:type="array">
45+
<item name="component" xsi:type="string">
46+
Magento_Paypal/js/view/amountProviders/product-grouped
47+
</item>
48+
</item>
49+
</item>
50+
</item>
51+
</item>
52+
</argument>
53+
</arguments>
54+
</block>
55+
</referenceContainer>
56+
<referenceBlock name="product.info.addtocart.additional">
57+
<block class="Magento\Paypal\Block\PayLater\Banner" name="product.info.addtocart.additional.paylater"
58+
template="Magento_Paypal::paylater/banner.phtml">
59+
<arguments>
60+
<argument name="placement" xsi:type="string">product</argument>
61+
<argument name="position" xsi:type="string">near_pp_button</argument>
62+
<argument name="jsLayout" xsi:type="array">
63+
<item name="components" xsi:type="array">
64+
<item name="payLater" xsi:type="array">
65+
<item name="config" xsi:type="array">
66+
<item name="displayAmount" xsi:type="boolean">true</item>
67+
<item name="amountComponentConfig" xsi:type="array">
68+
<item name="component" xsi:type="string">
69+
Magento_Paypal/js/view/amountProviders/product-grouped
70+
</item>
71+
</item>
72+
</item>
73+
</item>
74+
</item>
75+
</argument>
76+
</arguments>
77+
</block>
78+
</referenceBlock>
79+
</body>
80+
</page>
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
define([
7+
'jquery',
8+
'uiElement',
9+
'uiRegistry',
10+
'domReady!'
11+
], function (
12+
$,
13+
Component,
14+
registry
15+
) {
16+
'use strict';
17+
18+
return Component.extend({
19+
20+
defaults: {
21+
tableWrapperSelector: '.table-wrapper.grouped',
22+
priceBoxSelector: '[data-role="priceBox"]',
23+
qtyFieldSelector: '.input-text.qty',
24+
amount: null
25+
},
26+
priceInfo: {},
27+
28+
/**
29+
* Initialize
30+
*
31+
* @returns {*}
32+
*/
33+
initialize: function () {
34+
var self = this;
35+
36+
this._super();
37+
38+
$('tbody tr', this.tableWrapperSelector).each(function (index, element) {
39+
var priceBox = $(self.priceBoxSelector, element),
40+
qtyElement = $(self.qtyFieldSelector, element),
41+
productId = priceBox.data('productId'),
42+
priceElement = $('#product-price-' + productId);
43+
44+
self.priceInfo[productId] = {
45+
qty: self._getQty(qtyElement),
46+
price: priceElement.data('priceAmount')
47+
};
48+
});
49+
50+
$(this.qtyFieldSelector).on('change', this._onQtyChange.bind(this));
51+
52+
this._updateAmount();
53+
54+
return this;
55+
},
56+
57+
/**
58+
* Get product quantity
59+
*
60+
* @param {jQuery.Element} element
61+
* @private
62+
*/
63+
_getQty: function (element) {
64+
var qty = parseFloat(element.val());
65+
66+
return !isNaN(qty) && qty ? qty : 0;
67+
},
68+
69+
/**
70+
* Handle changed product quantity
71+
*
72+
* @param {jQuery.Event} event
73+
* @private
74+
*/
75+
_onQtyChange: function (event) {
76+
var qtyElement = $(event.target),
77+
parent = qtyElement.parents('tr'),
78+
priceBox = $(this.priceBoxSelector, parent),
79+
productId = priceBox.data('productId');
80+
81+
if (this.priceInfo[productId]) {
82+
this.priceInfo[productId].qty = this._getQty(qtyElement);
83+
}
84+
85+
this._updateAmount();
86+
},
87+
88+
/**
89+
* Calculate and update amount
90+
*
91+
* @private
92+
*/
93+
_updateAmount: function () {
94+
var productId,
95+
amount = 0,
96+
payLater = registry.get(this.parentName);
97+
98+
for (productId in this.priceInfo) {
99+
if (this.priceInfo.hasOwnProperty(productId)) {
100+
amount += this.priceInfo[productId].price * this.priceInfo[productId].qty;
101+
}
102+
}
103+
104+
payLater.amount(amount);
105+
}
106+
});
107+
});

app/code/Magento/Paypal/view/frontend/web/js/view/amountProviders/product.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ define([
2525
},
2626
qty: 1,
2727
price: 0,
28+
priceType: '',
2829

2930
/**
3031
* Initialize
@@ -41,9 +42,10 @@ define([
4142

4243
if (priceBox.priceBox('option') &&
4344
priceBox.priceBox('option').prices &&
44-
priceBox.priceBox('option').prices.finalPrice
45+
(priceBox.priceBox('option').prices.finalPrice || priceBox.priceBox('option').prices.basePrice)
4546
) {
46-
this.price = priceBox.priceBox('option').prices.finalPrice.amount;
47+
this.priceType = priceBox.priceBox('option').prices.finalPrice ? 'finalPrice' : 'basePrice';
48+
this.price = priceBox.priceBox('option').prices[this.priceType].amount;
4749
}
4850

4951
$(this.qtyFieldSelector).on('change', this._onQtyChange.bind(this));
@@ -74,7 +76,7 @@ define([
7476
* @private
7577
*/
7678
_onPriceChange: function (event, data) {
77-
this.price = data.finalPrice.amount;
79+
this.price = data[this.priceType].amount;
7880
this._updateAmount();
7981
},
8082

0 commit comments

Comments
 (0)