Skip to content

Commit 17a308d

Browse files
authored
Merge branch '2.4-develop' into MC-41861
2 parents 1e63679 + 74ff24b commit 17a308d

File tree

96 files changed

+5063
-966
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+5063
-966
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
@@ -133,6 +133,7 @@ define([
133133
}, this);
134134
}
135135

136+
this.element.trigger('priceUpdated', this.cache.displayPrices);
136137
this.element.trigger('reloadPrice');
137138
},
138139

app/code/Magento/Paypal/Block/Bml/Banners.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ protected function _toHtml()
6060
$publisherId = $this->_paypalConfig->getBmlPublisherId();
6161
$display = $this->_paypalConfig->getBmlDisplay($this->_section);
6262
$position = $this->_paypalConfig->getBmlPosition($this->_section);
63-
if (!$publisherId || $display == 0 || $this->_position != $position) {
63+
$payLaterActive = (bool)$this->_paypalConfig->getPayLaterConfigValue('experience_active');
64+
if (!$publisherId || $display == 0 || $this->_position != $position || $payLaterActive) {
6465
return '';
6566
}
6667
$this->setData('publisher_id', $publisherId);
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Paypal\Block\PayLater;
10+
11+
use Magento\Framework\View\Element\Template;
12+
use Magento\Paypal\Model\PayLaterConfig;
13+
use Magento\Paypal\Model\SdkUrl;
14+
15+
/**
16+
* PayPal PayLater component block
17+
* @api
18+
*/
19+
class Banner extends Template
20+
{
21+
/**
22+
* @var PayLaterConfig
23+
*/
24+
private $payLaterConfig;
25+
26+
/**
27+
* @var SdkUrl
28+
*/
29+
private $sdkUrl;
30+
31+
/**
32+
* @var string
33+
*/
34+
private $placement = '';
35+
36+
/**
37+
* @var string
38+
*/
39+
private $position = '';
40+
41+
/**
42+
* @param Template\Context $context
43+
* @param PayLaterConfig $payLaterConfig
44+
* @param SdkUrl $sdkUrl
45+
* @param array $data
46+
*/
47+
public function __construct(
48+
Template\Context $context,
49+
PayLaterConfig $payLaterConfig,
50+
SdkUrl $sdkUrl,
51+
array $data = []
52+
) {
53+
parent::__construct($context, $data);
54+
$this->payLaterConfig = $payLaterConfig;
55+
$this->sdkUrl = $sdkUrl;
56+
$this->placement = $data['placement'] ?? '';
57+
$this->position = $data['position'] ?? '';
58+
}
59+
60+
/**
61+
* Disable block output
62+
*
63+
* @return string
64+
*/
65+
protected function _toHtml(): string
66+
{
67+
if (!$this->isEnabled()) {
68+
return '';
69+
}
70+
return parent::_toHtml();
71+
}
72+
73+
/**
74+
* @inheritdoc
75+
*/
76+
public function getJsLayout()
77+
{
78+
$jsComponent = $this->jsLayout['components']['payLater']['component']
79+
?? 'Magento_Paypal/js/view/paylater';
80+
81+
//Extend block component config with defaults
82+
$componentConfig = $this->jsLayout['components']['payLater']['config'] ?? [];
83+
$defaultConfig = ['sdkUrl' => $this->getPayPalSdkUrl()];
84+
$config = array_replace($defaultConfig, $componentConfig);
85+
86+
//Extend block component attributes with defaults
87+
$componentAttributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
88+
$config['attributes'] = array_replace($this->getStyleAttributesConfig(), $componentAttributes);
89+
$config['attributes']['data-pp-placement'] = $this->placement;
90+
91+
$this->jsLayout = [
92+
'components' => [
93+
'payLater' => [
94+
'component' => $jsComponent,
95+
'config' => $config
96+
]
97+
]
98+
];
99+
100+
return parent::getJsLayout();
101+
}
102+
103+
/**
104+
* Build\Get URL to PP SDK
105+
*
106+
* @return string
107+
*/
108+
private function getPayPalSdkUrl(): string
109+
{
110+
return $this->sdkUrl->getUrl();
111+
}
112+
113+
/**
114+
* Retrieve style configuration
115+
*
116+
* @return string[]
117+
*/
118+
private function getStyleAttributesConfig(): array
119+
{
120+
return $this->payLaterConfig->getSectionConfig($this->placement, PayLaterConfig::CONFIG_KEY_STYLE);
121+
}
122+
123+
/**
124+
* Check if block should be displayed
125+
*
126+
* @return bool
127+
*/
128+
private function isEnabled(): bool
129+
{
130+
$enabled = $this->payLaterConfig->isEnabled($this->placement);
131+
return $enabled &&
132+
$this->payLaterConfig->getSectionConfig($this->placement, PayLaterConfig::CONFIG_KEY_POSITION) ===
133+
$this->position;
134+
}
135+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Paypal\Block\PayLater;
10+
11+
use Magento\Checkout\Block\Checkout\LayoutProcessorInterface;
12+
use Magento\Paypal\Model\PayLaterConfig;
13+
use Magento\Paypal\Model\SdkUrl;
14+
15+
/**
16+
* PayLater Layout Processor
17+
*/
18+
class LayoutProcessor implements LayoutProcessorInterface
19+
{
20+
/**
21+
* Checkout payment page placement
22+
*/
23+
private const PLACEMENT = 'payment';
24+
25+
/**
26+
* @var PayLaterConfig
27+
*/
28+
private $payLaterConfig;
29+
30+
/**
31+
* @var SdkUrl
32+
*/
33+
private $sdkUrl;
34+
35+
/**
36+
* @param PayLaterConfig $payLaterConfig
37+
* @param SdkUrl $sdkUrl
38+
*/
39+
public function __construct(PayLaterConfig $payLaterConfig, SdkUrl $sdkUrl)
40+
{
41+
$this->payLaterConfig = $payLaterConfig;
42+
$this->sdkUrl = $sdkUrl;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function process($jsLayout)
49+
{
50+
if (!$this->payLaterConfig->isEnabled(PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT)) {
51+
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
52+
['children']['payment']['children']['payments-list']['children']['before-place-order']['children']
53+
['paylater-place-order']);
54+
55+
return $jsLayout;
56+
}
57+
58+
if (isset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
59+
['children']['payment']['children']['payments-list']['children']['before-place-order']['children']
60+
['paylater-place-order'])
61+
) {
62+
$payLaterPlaceOrder = &$jsLayout['components']['checkout']['children']['steps']['children']['billing-step']
63+
['children']['payment']['children']['payments-list']['children']['before-place-order']['children']
64+
['paylater-place-order'];
65+
66+
$componentConfig = $payLaterPlaceOrder['config'] ?? [];
67+
$defaultConfig = [
68+
'sdkUrl' => $this->sdkUrl->getUrl(),
69+
'displayAmount' => true,
70+
'amountComponentConfig' => [
71+
'component' => 'Magento_Paypal/js/view/amountProviders/checkout'
72+
]
73+
];
74+
$config = array_replace($defaultConfig, $componentConfig);
75+
76+
$attributes = $this->payLaterConfig->getSectionConfig(
77+
PayLaterConfig::CHECKOUT_PAYMENT_PLACEMENT,
78+
PayLaterConfig::CONFIG_KEY_STYLE
79+
);
80+
$attributes['data-pp-placement'] = self::PLACEMENT;
81+
82+
$componentAttributes = $payLaterPlaceOrder['config']['attributes'] ?? [];
83+
$config['attributes'] = array_replace($attributes, $componentAttributes);
84+
85+
$payLaterPlaceOrder['config'] = $config;
86+
}
87+
88+
return $jsLayout;
89+
}
90+
}

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

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,20 +292,33 @@ public function isMethodActive($method)
292292
break;
293293
case Config::METHOD_WPS_BML:
294294
case Config::METHOD_WPP_BML:
295-
$disabledFunding = $this->_scopeConfig->getValue(
296-
'paypal/style/disable_funding_options',
297-
ScopeInterface::SCOPE_STORE,
298-
$this->_storeId
299-
);
300-
$isExpressCreditEnabled = $disabledFunding
301-
? strpos($disabledFunding, 'CREDIT') === false
302-
: true;
303-
$isEnabled = $isExpressCreditEnabled
304-
|| $this->_scopeConfig->isSetFlag(
305-
'payment/' . Config::METHOD_WPP_BML .'/active',
295+
$isWpsEnabled = $this->_scopeConfig->isSetFlag(
296+
'payment/' . Config::METHOD_WPS_EXPRESS .'/active',
306297
ScopeInterface::SCOPE_STORE,
307298
$this->_storeId
308299
);
300+
if ($isWpsEnabled) {
301+
$isEnabled = $this->_scopeConfig->isSetFlag(
302+
'payment/' . Config::METHOD_WPS_BML .'/active',
303+
ScopeInterface::SCOPE_STORE,
304+
$this->_storeId
305+
);
306+
} else {
307+
$disabledFunding = $this->_scopeConfig->getValue(
308+
'paypal/style/disable_funding_options',
309+
ScopeInterface::SCOPE_STORE,
310+
$this->_storeId
311+
);
312+
$isExpressCreditEnabled = $disabledFunding
313+
? strpos($disabledFunding, 'CREDIT') === false
314+
: true;
315+
$isEnabled = $isExpressCreditEnabled
316+
|| $this->_scopeConfig->isSetFlag(
317+
'payment/' . Config::METHOD_WPP_BML .'/active',
318+
ScopeInterface::SCOPE_STORE,
319+
$this->_storeId
320+
);
321+
}
309322
$method = Config::METHOD_WPP_BML;
310323
break;
311324
case Config::METHOD_PAYMENT_PRO:

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ class Config extends AbstractConfig
174174
*/
175175
const XML_PATH_PAYPAL_EXPRESS_SKIP_ORDER_REVIEW_STEP_FLAG = 'payment/paypal_express/skip_order_review_step';
176176

177+
/**
178+
* PayPal PayLater
179+
*/
180+
const PAYLATER = 'paypal_paylater';
181+
177182
/**
178183
* Instructions for generating proper BN code
179184
*
@@ -1828,4 +1833,19 @@ public function getBmlSize($section)
18281833
$this->_storeId
18291834
);
18301835
}
1836+
1837+
/**
1838+
* Get PayLater config values
1839+
*
1840+
* @param string $fieldName
1841+
* @return mixed
1842+
*/
1843+
public function getPayLaterConfigValue($fieldName)
1844+
{
1845+
return $this->_scopeConfig->getValue(
1846+
'payment/' . self::PAYLATER . '/' . $fieldName,
1847+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
1848+
$this->_storeId
1849+
);
1850+
}
18311851
}

0 commit comments

Comments
 (0)