Skip to content

Commit 0e2d1e1

Browse files
committed
Merge branch 'MC-41710' into MC-41701
2 parents c25442a + 89b8b2e commit 0e2d1e1

File tree

28 files changed

+921
-483
lines changed

28 files changed

+921
-483
lines changed

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

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,39 @@
99
namespace Magento\Paypal\Block\PayLater;
1010

1111
use Magento\Framework\View\Element\Template;
12-
use Magento\Paypal\Model\Config;
12+
use Magento\Paypal\Model\PayLaterConfig;
13+
use Magento\Paypal\Model\SdkUrl;
1314

1415
/**
1516
* PayPal PayLater component block
1617
*/
1718
class Banner extends Template
1819
{
1920
/**
20-
* @var \Magento\Paypal\Model\Config
21+
* @var PayLaterConfig
2122
*/
22-
private $paypalConfig;
23+
private $payLaterConfig;
24+
private $position;
25+
private $placement;
26+
private $sdkUrl;
2327

2428
/**
2529
* @param Template\Context $context
26-
* @param Config $paypalConfig
30+
* @param PayLaterConfig $payLaterConfig
31+
* @param SdkUrl $sdkUrl
2732
* @param array $data
2833
*/
2934
public function __construct(
3035
Template\Context $context,
31-
Config $paypalConfig,
36+
PayLaterConfig $payLaterConfig,
37+
SdkUrl $sdkUrl,
3238
array $data = []
33-
)
34-
{
35-
$this->paypalConfig = $paypalConfig;
39+
) {
3640
parent::__construct($context, $data);
41+
$this->placement = $data['placement'] ?? '';
42+
$this->position = $data['position'] ?? '';
43+
$this->payLaterConfig = $payLaterConfig;
44+
$this->sdkUrl = $sdkUrl;
3745
}
3846

3947
/**
@@ -56,7 +64,7 @@ public function getJsLayout()
5664
{
5765
$this->jsLayout['components']['payLater']['config']['sdkUrl'] = $this->getPayPalSdkUrl();
5866
$attributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
59-
$attributes = array_replace($attributes, $this->getConfig());
67+
$attributes = array_replace($this->getStyleAttributesConfig(), $attributes);
6068
$this->jsLayout['components']['payLater']['config']['attributes'] = $attributes;
6169
return parent::getJsLayout();
6270
}
@@ -68,17 +76,20 @@ public function getJsLayout()
6876
*/
6977
private function getPayPalSdkUrl()
7078
{
71-
return "https://www.paypal.com/sdk/js?client-id=sb&components=messages,buttons";
79+
return $this->sdkUrl->getUrl();
7280
}
7381

7482
/**
7583
* Retrieve style configuration
7684
*
7785
* @return string[]
7886
*/
79-
private function getConfig()
87+
private function getStyleAttributesConfig()
8088
{
81-
return ['data-pp-style-logo-position' => 'right'];
89+
return array_replace(
90+
['data-pp-style-logo-position' => 'center'],
91+
$this->payLaterConfig->getStyleConfig($this->placement)
92+
);
8293
}
8394

8495
/**
@@ -88,6 +99,7 @@ private function getConfig()
8899
*/
89100
private function isEnabled()
90101
{
91-
return true;
102+
$enabled = $this->payLaterConfig->isEnabled($this->placement);
103+
return $enabled && $this->payLaterConfig->getPositionConfig($this->placement) == $this->position;
92104
}
93105
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Paypal\Model;
9+
10+
use Magento\Checkout\Helper\Data;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
12+
use Magento\Framework\Locale\ResolverInterface;
13+
use Magento\Store\Model\ScopeInterface;
14+
use Magento\Store\Model\StoreManagerInterface;
15+
16+
/**
17+
* Provides configuration values for PayPal PayLater Banners
18+
*/
19+
class PayLaterConfig
20+
{
21+
const PLACEMENT_PRODUCT = 'product';
22+
23+
/**
24+
* @var ScopeConfigInterface
25+
*/
26+
private ScopeConfigInterface $scopeConfig;
27+
28+
/**
29+
* @param ScopeConfigInterface $scopeConfig
30+
*/
31+
public function __construct(
32+
ScopeConfigInterface $scopeConfig
33+
) {
34+
$this->scopeConfig = $scopeConfig;
35+
}
36+
37+
/**
38+
* Get configured styles for specified page
39+
*
40+
* @return array
41+
*/
42+
public function getStyleConfig(string $placement): array
43+
{
44+
return $this->getSectionConfig($placement, 'style') ?? [];
45+
}
46+
47+
/**
48+
* Get configured Banner position on specified page
49+
*
50+
* @param string $placement
51+
* @return mixed|string
52+
*/
53+
public function getPositionConfig(string $placement)
54+
{
55+
return $this->getSectionConfig($placement, 'position') ?? '';
56+
}
57+
58+
/**
59+
* Check if Banner enabled for specified page
60+
*
61+
* @param string $placement
62+
* @return bool
63+
*/
64+
public function isEnabled(string $placement)
65+
{
66+
$isPayLaterEnabled = true; //read from config
67+
return $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
68+
}
69+
70+
private function getSectionConfig($section, $key)
71+
{
72+
$configMock = [
73+
self::PLACEMENT_PRODUCT => [
74+
'display' => 1,
75+
'position' => 'header', // 'sidebar'
76+
'style' => [
77+
'data-pp-style-logo-position' => 'right'
78+
]
79+
],
80+
];
81+
return $configMock[$section][$key] ?? [];
82+
}
83+
}

0 commit comments

Comments
 (0)