Skip to content

Commit ab532bd

Browse files
MC-41657: Reflect changed price: Checkout
- use amount providers for product and checkout and layout processor for checkout
1 parent f186566 commit ab532bd

File tree

12 files changed

+174
-105
lines changed

12 files changed

+174
-105
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ protected function _toHtml(): string
7676
public function getJsLayout()
7777
{
7878
$jsComponent = $this->jsLayout['components']['payLater']['component']
79-
?? 'Magento_Paypal/js/view/paylater-default';
79+
?? 'Magento_Paypal/js/view/paylater';
8080

8181
//Extend block component config with defaults
8282
$componentConfig = $this->jsLayout['components']['payLater']['config'] ?? [];
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\PayPal\Block\PayLater;
8+
9+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
10+
use Magento\Paypal\Model\PayLaterConfig;
11+
use Magento\Paypal\Model\SdkUrl;
12+
13+
/**
14+
* PayLater Layout Processor
15+
*/
16+
class LayoutProcessor implements LayoutProcessorInterface
17+
{
18+
/**
19+
* Checkout payment page placement
20+
*/
21+
private const PLACEMENT = 'payment';
22+
23+
/**
24+
* @var PayLaterConfig
25+
*/
26+
private $payLaterConfig;
27+
28+
/**
29+
* @var SdkUrl
30+
*/
31+
private $sdkUrl;
32+
33+
/**
34+
* @param PayLaterConfig $payLaterConfig
35+
* @param SdkUrl $sdkUrl
36+
*/
37+
public function __construct(PayLaterConfig $payLaterConfig, SdkUrl $sdkUrl)
38+
{
39+
$this->payLaterConfig = $payLaterConfig;
40+
$this->sdkUrl = $sdkUrl;
41+
}
42+
43+
/**
44+
* {@inheritdoc}
45+
*/
46+
public function process($jsLayout)
47+
{
48+
if (!$this->payLaterConfig->isEnabled(PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT)) {
49+
return $jsLayout;
50+
}
51+
52+
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
53+
['children']['payment']['children']['payments-list']['children']['before-place-order']['children']
54+
['paylater-place-order'])
55+
) {
56+
$payLaterPlaceOrder = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
57+
['children']['payment']['children']['payments-list']['children']['before-place-order']['children']
58+
['paylater-place-order'];
59+
60+
$attributes = $this->payLaterConfig->getSectionConfig(
61+
PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT,
62+
PayLaterConfig::CONFIG_KEY_STYLE
63+
);
64+
$attributes['data-pp-placement'] = self::PLACEMENT;
65+
66+
$payLaterPlaceOrder['config'] = [
67+
'sdkUrl' => $this->sdkUrl->getUrl(),
68+
'attributes' => $attributes,
69+
'displayAmount' => true,
70+
'amountComponentConfig' => [
71+
'component' => 'Magento_Paypal/js/view/amountProviders/checkout'
72+
]
73+
];
74+
}
75+
76+
return $jsLayout;
77+
}
78+
}

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

Lines changed: 0 additions & 59 deletions
This file was deleted.

app/code/Magento/Paypal/etc/frontend/di.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@
8484
<item name="paypal_iframe_config_provider" xsi:type="object">Magento\Paypal\Model\IframeConfigProvider</item>
8585
<item name="paypal_billing_agreement_config_provider" xsi:type="object">Magento\Paypal\Model\BillingAgreementConfigProvider</item>
8686
<item name="paypal_iframe_cc_config_provider" xsi:type="object">PaypalIframeCcConfigProvider</item>
87-
<item name="paypal_paylater_config_provider" xsi:type="object">Magento\Paypal\Model\PayLaterCheckoutConfigProvider</item>
8887
</argument>
8988
</arguments>
9089
</type>
@@ -190,4 +189,11 @@
190189
<argument name="localeResolver" xsi:type="object">Magento\Paypal\Model\Express\LocaleResolver</argument>
191190
</arguments>
192191
</type>
192+
<type name="Magento\Checkout\Block\Onepage">
193+
<arguments>
194+
<argument name="layoutProcessors" xsi:type="array">
195+
<item name="payLater" xsi:type="object">Magento\PayPal\Block\PayLater\LayoutProcessor</item>
196+
</argument>
197+
</arguments>
198+
</type>
193199
</config>

app/code/Magento/Paypal/view/frontend/layout/catalog_product_view.xml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
<argument name="jsLayout" xsi:type="array">
2323
<item name="components" xsi:type="array">
2424
<item name="payLater" xsi:type="array">
25-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater-product</item>
25+
<item name="config" xsi:type="array">
26+
<item name="displayAmount" xsi:type="boolean">true</item>
27+
<item name="amountComponentConfig" xsi:type="array">
28+
<item name="component" xsi:type="string">
29+
Magento_Paypal/js/view/amountProviders/product
30+
</item>
31+
</item>
32+
</item>
2633
</item>
2734
</item>
2835
</argument>
@@ -44,7 +51,14 @@
4451
<argument name="jsLayout" xsi:type="array">
4552
<item name="components" xsi:type="array">
4653
<item name="payLater" xsi:type="array">
47-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater-product</item>
54+
<item name="config" xsi:type="array">
55+
<item name="displayAmount" xsi:type="boolean">true</item>
56+
<item name="amountComponentConfig" xsi:type="array">
57+
<item name="component" xsi:type="string">
58+
Magento_Paypal/js/view/amountProviders/product
59+
</item>
60+
</item>
61+
</item>
4862
</item>
4963
</item>
5064
</argument>
@@ -60,7 +74,14 @@
6074
<argument name="jsLayout" xsi:type="array">
6175
<item name="components" xsi:type="array">
6276
<item name="payLater" xsi:type="array">
63-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater-product</item>
77+
<item name="config" xsi:type="array">
78+
<item name="displayAmount" xsi:type="boolean">true</item>
79+
<item name="amountComponentConfig" xsi:type="array">
80+
<item name="component" xsi:type="string">
81+
Magento_Paypal/js/view/amountProviders/product
82+
</item>
83+
</item>
84+
</item>
6485
</item>
6586
</item>
6687
</argument>

app/code/Magento/Paypal/view/frontend/layout/checkout_index_index.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<item name="before-place-order" xsi:type="array">
2929
<item name="children" xsi:type="array">
3030
<item name="paylater-place-order" xsi:type="array">
31-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater-checkout</item>
31+
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater</item>
3232
<item name="sortOrder" xsi:type="string">100</item>
3333
<item name="displayArea" xsi:type="string">before-place-order</item>
3434
</item>

app/code/Magento/Paypal/view/frontend/web/js/view/paylater-checkout.js renamed to app/code/Magento/Paypal/view/frontend/web/js/view/amountProviders/checkout.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,22 @@
66
define([
77
'jquery',
88
'ko',
9-
'Magento_Paypal/js/view/paylater-default',
9+
'uiElement',
10+
'uiRegistry',
1011
'Magento_Checkout/js/model/quote',
1112
'domReady!'
1213
], function (
1314
$,
1415
ko,
1516
Component,
17+
registry,
1618
quote
1719
) {
1820
'use strict';
1921

20-
var payLaterEnabled = window.checkoutConfig.payment.paypalPayLater.enabled,
21-
payLaterConfig = window.checkoutConfig.payment.paypalPayLater.config;
22-
2322
return Component.extend({
2423
defaults: {
25-
template: 'Magento_Paypal/paylater',
26-
sdkUrl: payLaterEnabled ? payLaterConfig.sdkUrl : '',
27-
attributes: payLaterConfig.attributes,
28-
amount: ko.observable(),
29-
style: 'margin-bottom: 10px;'
24+
amount: null
3025
},
3126

3227
/**
@@ -36,6 +31,7 @@ define([
3631
*/
3732
initialize: function () {
3833
this._super();
34+
3935
this.updateAmount();
4036

4137
return this;
@@ -45,10 +41,10 @@ define([
4541
* Update amount
4642
*/
4743
updateAmount: function () {
48-
var amount = this.amount;
44+
var payLater = registry.get(this.parentName);
4945

5046
quote.totals.subscribe(function (newValue) {
51-
amount(newValue['base_grand_total']);
47+
payLater.amount(newValue['base_grand_total']);
5248
});
5349
}
5450
});

app/code/Magento/Paypal/view/frontend/web/js/view/paylater-product.js renamed to app/code/Magento/Paypal/view/frontend/web/js/view/amountProviders/product.js

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
4-
*/
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
55

66
define([
77
'jquery',
8-
'ko',
9-
'Magento_Paypal/js/view/paylater-default',
8+
'uiElement',
9+
'uiRegistry',
1010
'priceBox',
1111
'domReady!'
1212
], function (
1313
$,
14-
ko,
15-
Component
14+
Component,
15+
registry
1616
) {
1717
'use strict';
1818

@@ -21,7 +21,7 @@ define([
2121
defaults: {
2222
priceBoxSelector: '.price-box',
2323
qtyFieldSelector: '#product_addtocart_form [name="qty"]',
24-
refreshSelector: ''
24+
amount: null,
2525
},
2626
qty: 1,
2727
price: 0,
@@ -48,10 +48,6 @@ define([
4848

4949
$(this.qtyFieldSelector).on('change', this._onQtyChange.bind(this));
5050

51-
if (this.refreshSelector) {
52-
$(this.refreshSelector).on('click', this._refreshMessages.bind(this));
53-
}
54-
5551
this._updateAmount();
5652

5753
return this;
@@ -91,19 +87,9 @@ define([
9187
var amount = this.price * this.qty;
9288

9389
if (amount !== 0) {
94-
this.amount(amount);
90+
var payLater = registry.get(this.parentName);
91+
payLater.amount(amount);
9592
}
9693
},
97-
98-
/**
99-
* Render messages
100-
*
101-
* @private
102-
*/
103-
_refreshMessages: function () {
104-
if (this.paypal) {
105-
this.paypal.Messages.render();
106-
}
107-
}
10894
});
10995
});

0 commit comments

Comments
 (0)