Skip to content

Commit 1e67450

Browse files
committed
MC-41710: Build URL to paypal SDK
- Fix CR notes
1 parent 89b8b2e commit 1e67450

File tree

3 files changed

+29
-32
lines changed

3 files changed

+29
-32
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ private function getPayPalSdkUrl()
8787
private function getStyleAttributesConfig()
8888
{
8989
return array_replace(
90-
['data-pp-style-logo-position' => 'center'],
91-
$this->payLaterConfig->getStyleConfig($this->placement)
90+
['data-pp-style-logo-position' => 'left'],
91+
$this->payLaterConfig->getSectionConfig($this->placement, PayLaterConfig::CONFIG_KEY_STYLES)
9292
);
9393
}
9494

@@ -100,6 +100,8 @@ private function getStyleAttributesConfig()
100100
private function isEnabled()
101101
{
102102
$enabled = $this->payLaterConfig->isEnabled($this->placement);
103-
return $enabled && $this->payLaterConfig->getPositionConfig($this->placement) == $this->position;
103+
return $enabled &&
104+
$this->payLaterConfig->getSectionConfig($this->placement, PayLaterConfig::CONFIG_KEY_POSITION) ==
105+
$this->position;
104106
}
105107
}

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

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,15 @@
1818
*/
1919
class PayLaterConfig
2020
{
21-
const PLACEMENT_PRODUCT = 'product';
21+
/**
22+
* Configuration key for Styles settings
23+
*/
24+
const CONFIG_KEY_STYLES = 'styles';
25+
26+
/**
27+
* Configuration key for Position setting
28+
*/
29+
const CONFIG_KEY_POSITION = 'position';
2230

2331
/**
2432
* @var ScopeConfigInterface
@@ -34,27 +42,6 @@ public function __construct(
3442
$this->scopeConfig = $scopeConfig;
3543
}
3644

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-
5845
/**
5946
* Check if Banner enabled for specified page
6047
*
@@ -67,10 +54,17 @@ public function isEnabled(string $placement)
6754
return $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
6855
}
6956

70-
private function getSectionConfig($section, $key)
57+
/**
58+
* Get config for a specific section and key
59+
*
60+
* @param string $section
61+
* @param string $key
62+
* @return array|mixed
63+
*/
64+
public function getSectionConfig($section, $key)
7165
{
7266
$configMock = [
73-
self::PLACEMENT_PRODUCT => [
67+
'product' => [
7468
'display' => 1,
7569
'position' => 'header', // 'sidebar'
7670
'style' => [

app/code/Magento/Paypal/Plugin/CheckoutIndex.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Checkout\Controller\Index\Index;
1111
use Magento\Paypal\Model\Config;
12+
use Magento\Paypal\Model\ConfigFactory;
1213
use Magento\Paypal\Model\SdkUrl;
1314

1415
/**
@@ -25,19 +26,18 @@ class CheckoutIndex
2526
/**
2627
* @var Config
2728
*/
28-
private $config;
29+
private $configFactory;
2930

3031
/**
3132
* @param SdkUrl $sdkUrl
3233
* @param Config $config
3334
*/
3435
public function __construct(
3536
SdkUrl $sdkUrl,
36-
Config $config
37+
ConfigFactory $config
3738
) {
3839
$this->sdkUrl = $sdkUrl;
39-
$this->config = $config;
40-
$this->config->setMethod(Config::METHOD_EXPRESS);
40+
$this->configFactory = $config;
4141
}
4242

4343
/**
@@ -50,7 +50,8 @@ public function __construct(
5050
public function beforeExecute(Index $subject)
5151
{
5252
// Check If PP SmartButtons enabled
53-
if ((bool)(int) $this->config->getValue('in_context')) {
53+
$config = $this->configFactory->create()->setMethod(Config::METHOD_EXPRESS);
54+
if ((bool)(int) $config->getValue('in_context')) {
5455
$this->sdkUrl->setQueryParam('commit', 'true');
5556
}
5657

0 commit comments

Comments
 (0)