Skip to content

Commit 4104fac

Browse files
committed
Merge remote-tracking branch 'trigger/MC-42208' into MC-41701
2 parents 92c1970 + 9df8275 commit 4104fac

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ class PayLaterConfig
4141

4242
/**
4343
* @param ScopeConfigInterface $scopeConfig
44-
* @param Config $config
44+
* @param ConfigFactory $configFactory
4545
*/
4646
public function __construct(
4747
ScopeConfigInterface $scopeConfig,
48-
Config $config
48+
ConfigFactory $configFactory
4949
) {
5050
$this->scopeConfig = $scopeConfig;
51-
$this->config = $config;
51+
$this->config = $configFactory->create();
5252
}
5353

5454
/**
@@ -75,8 +75,13 @@ public function isEnabled(string $placement): bool
7575
*/
7676
private function isPPCreditEnabled()
7777
{
78-
return $this->config->isMethodAvailable(Config::METHOD_WPP_BML)
79-
|| $this->config->isMethodAvailable(Config::METHOD_WPS_BML)
78+
$isEnabled = false;
79+
if ($this->config->setMethod(Config::METHOD_EXPRESS)->getValue('in_context')) {
80+
$disabledFunding = $this->config->getValue('disable_funding_options');
81+
$isEnabled = $disabledFunding ? strpos($disabledFunding, 'CREDIT') === false : true;
82+
}
83+
84+
return $isEnabled || $this->config->isMethodAvailable(Config::METHOD_WPP_BML)
8085
|| $this->config->isMethodAvailable(Config::METHOD_WPP_PE_BML);
8186
}
8287

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<referenceBlock name="product.info.addtocart.bundle">
11+
<block class="Magento\Paypal\Block\PayLater\Banner" name="product.info.addtocart.additional.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">near_pp_button</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="refreshSelector" xsi:type="string">#bundle-slide</item>
21+
</item>
22+
</item>
23+
</item>
24+
</argument>
25+
</arguments>
26+
</block>
27+
</referenceBlock>
28+
</body>
29+
</page>

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,43 @@ define([
2525
sdkUrl: '',
2626
priceBoxSelector: '.price-box',
2727
qtyFieldSelector: '#product_addtocart_form [name="qty"]',
28+
refreshSelector: '',
2829
displayAmount: true,
2930
attributes: {}
3031
},
3132
amount: ko.observable(),
3233
qty: 1,
3334
price: 0,
35+
paypal: null,
3436

3537
/**
3638
* Initialize
3739
*
3840
* @returns {*}
3941
*/
4042
initialize: function () {
41-
var priceBox, qty;
43+
var priceBox;
4244

4345
this._super();
44-
this.loadPayPalSdk(this.sdkUrl);
46+
this.loadPayPalSdk()
47+
.then(this._setPayPalObject.bind(this));
4548

4649
if (this.displayAmount) {
4750
priceBox = $(this.priceBoxSelector);
51+
priceBox.on('priceUpdated', this._onPriceChange.bind(this));
4852

4953
if (priceBox.priceBox('option') &&
50-
priceBox.priceBox('option').prices
54+
priceBox.priceBox('option').prices &&
55+
priceBox.priceBox('option').prices.finalPrice
5156
) {
5257
this.price = priceBox.priceBox('option').prices.finalPrice.amount;
53-
priceBox.on('priceUpdated', this._onPriceChange.bind(this));
5458
}
5559

56-
qty = $(this.qtyFieldSelector);
57-
qty.on('change', this._onQtyChange.bind(this));
60+
$(this.qtyFieldSelector).on('change', this._onQtyChange.bind(this));
61+
62+
if (this.refreshSelector) {
63+
$(this.refreshSelector).on('click', this._refreshMessages.bind(this));
64+
}
5865

5966
this._updateAmount();
6067
}
@@ -113,11 +120,30 @@ define([
113120

114121
/**
115122
* Load PP SDK with preconfigured options
123+
*/
124+
loadPayPalSdk: function () {
125+
return paypalSdk(this.sdkUrl);
126+
},
127+
128+
/**
129+
* Set reference to paypal Sdk object
130+
*
131+
* @param {Object} paypal
132+
* @private
133+
*/
134+
_setPayPalObject: function (paypal) {
135+
this.paypal = paypal;
136+
},
137+
138+
/**
139+
* Render messages
116140
*
117-
* @param {String} sdkUrl
141+
* @private
118142
*/
119-
loadPayPalSdk: function (sdkUrl) {
120-
paypalSdk(sdkUrl);
143+
_refreshMessages: function () {
144+
if (this.paypal) {
145+
this.paypal.Messages.render();
146+
}
121147
}
122148
});
123149
});

0 commit comments

Comments
 (0)