Skip to content

Commit f1ff5de

Browse files
committed
MC-41654: Read and apply configuration to PP PayLater component
- Add default config for js component - Add "messages" to product page with custom options - Show "messages" only if PP Credit enabled
1 parent 0ec1dc7 commit f1ff5de

File tree

9 files changed

+501
-99
lines changed

9 files changed

+501
-99
lines changed

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,30 @@ protected function _toHtml(): string
6565
*/
6666
public function getJsLayout()
6767
{
68-
$this->jsLayout['components']['payLater']['config']['sdkUrl'] = $this->getPayPalSdkUrl();
68+
$jsLayout = [
69+
'components' => [
70+
'payLater' => [
71+
'component' =>
72+
$this->jsLayout['components']['payLater']['component'] ?? 'Magento_Paypal/js/view/paylater',
73+
'config' => [
74+
'sdkUrl' => $this->getPayPalSdkUrl(),
75+
]
76+
]
77+
]
78+
];
79+
80+
//Merge config
81+
$config = $this->jsLayout['components']['payLater']['config'] ?? [];
82+
$config = array_replace($jsLayout['components']['payLater']['config'], $config);
83+
84+
//Merge attributes
6985
$attributes = $this->jsLayout['components']['payLater']['config']['attributes'] ?? [];
70-
$attributes = array_replace($attributes, $this->getStyleAttributesConfig());
71-
$this->jsLayout['components']['payLater']['config']['attributes'] = $attributes;
86+
$config['attributes'] = array_replace($this->getStyleAttributesConfig(), $attributes);
87+
$config['attributes']['data-pp-placement'] = $this->placement;
88+
$jsLayout['components']['payLater']['config'] = $config;
89+
90+
$this->jsLayout = $jsLayout;
91+
7292
return parent::getJsLayout();
7393
}
7494

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/PayLaterConfig.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,24 @@ public function getPositionConfig(string $placement): string
7171
*/
7272
public function isEnabled(string $placement): bool
7373
{
74-
$isPayLaterEnabled = (boolean)$this->config->getPayLaterConfigValue('enabled');
75-
return $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
74+
$enabled = false;
75+
if ($this->isPPCreditEnabled()) {
76+
$isPayLaterEnabled = (boolean)$this->config->getPayLaterConfigValue('enabled');
77+
$enabled = $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
78+
}
79+
return $enabled;
80+
}
81+
82+
/**
83+
* Check that PayPal Credit enabled with any PayPal express method
84+
*
85+
* @return
86+
*/
87+
private function isPPCreditEnabled()
88+
{
89+
return $this->config->isMethodAvailable(Config::METHOD_WPP_BML)
90+
|| $this->config->isMethodAvailable(Config::METHOD_WPS_BML)
91+
|| $this->config->isMethodAvailable(Config::METHOD_WPP_PE_BML);
7692
}
7793

7894
/**

app/code/Magento/Paypal/Model/System/Config/Source/PayLater/Position.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function getPositionsCPP(): array
2121
{
2222
return [
2323
'header' => __('Header (center)'),
24-
'sidebar' => __('Near PayPal Credit checkout button')
24+
'near_pp_button' => __('Near PayPal Credit checkout button')
2525
];
2626
}
2727
}

app/code/Magento/Paypal/Test/Unit/Model/AbstractConfigTest.php

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\App\ProductMetadataInterface;
1212
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1313
use Magento\Payment\Model\MethodInterface;
14+
use Magento\Store\Model\ScopeInterface;
1415
use Magento\Store\Model\ScopeInterface as ModelScopeInterface;
1516
use PHPUnit\Framework\MockObject\MockObject;
1617
use PHPUnit\Framework\TestCase;
@@ -300,23 +301,33 @@ public function testIsMethodActive()
300301
* Check bill me later active setting uses disable funding options
301302
*
302303
* @param string|null $disableFundingOptions
303-
* @param int $expectedFlag
304+
* @param int $expressBml
304305
* @param bool $expectedValue
305306
*
306307
* @dataProvider isMethodActiveBmlDataProvider
307308
*/
308-
public function testIsMethodActiveBml($disableFundingOptions, $expectedFlag, $expectedValue)
309-
{
309+
public function testIsMethodActiveBml(
310+
$disableFundingOptions,
311+
$expressBml,
312+
$wpsExpress,
313+
$wpsExpressBml,
314+
$expectedValue
315+
) {
310316
$this->scopeConfigMock->method('getValue')
311317
->with(
312318
self::equalTo('paypal/style/disable_funding_options'),
313-
self::equalTo('store')
319+
self::equalTo(ScopeInterface::SCOPE_STORE)
314320
)
315321
->willReturn($disableFundingOptions);
316322

323+
$configFlagMap = [
324+
['payment/wps_express/active', ScopeInterface::SCOPE_STORE, null, $wpsExpress],
325+
['payment/wps_express_bml/active', ScopeInterface::SCOPE_STORE, null, $wpsExpressBml],
326+
['payment/paypal_express_bml/active', ScopeInterface::SCOPE_STORE, null, $expressBml]
327+
];
328+
317329
$this->scopeConfigMock->method('isSetFlag')
318-
->with('payment/paypal_express_bml/active')
319-
->willReturn($expectedFlag);
330+
->willReturnMap($configFlagMap);
320331

321332
self::assertEquals($expectedValue, $this->config->isMethodActive('paypal_express_bml'));
322333
}
@@ -327,14 +338,18 @@ public function testIsMethodActiveBml($disableFundingOptions, $expectedFlag, $ex
327338
public function isMethodActiveBmlDataProvider()
328339
{
329340
return [
330-
['CREDIT,CARD,ELV', 0, false],
331-
['CREDIT,CARD,ELV', 1, true],
332-
['CREDIT', 0, false],
333-
['CREDIT', 1, true],
334-
['CARD', 0, true],
335-
['CARD', 1, true],
336-
[null, 0, true],
337-
[null, 1, true]
341+
['CREDIT,CARD,ELV', 0, 0, 0, false],
342+
['CREDIT,CARD,ELV', 1, 0, 0, true],
343+
['CREDIT', 0, 0, 0, false],
344+
['CREDIT', 1, 0, 0, true],
345+
['CARD', 0, 0, 0, true],
346+
['CARD', 1, 0, 0, true],
347+
[null, 0, 0, 0, true],
348+
[null, 1, 0, 0, true],
349+
['CREDIT', 0, 1, 0, false],
350+
['', 0, 1, 0, false],
351+
['', 0, 1, 1, true],
352+
['CREDIT', 0, 1, 1, true]
338353
];
339354
}
340355

app/code/Magento/Paypal/Test/Unit/Model/ConfigTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,20 +135,22 @@ public function testIsMethodAvailableForIsMethodActive($methodName, $expected)
135135
$this->scopeConfig
136136
->method('getValue')
137137
->willReturnMap($valueMap);
138-
$this->scopeConfig->expects($this->exactly(1))
139-
->method('isSetFlag')
140-
->withAnyParameters()
141-
->willReturn(true);
142138
} else {
143139
$this->scopeConfig
144140
->method('getValue')
145141
->with('paypal/general/merchant_country')
146142
->willReturn('US');
147-
$this->scopeConfig->expects($this->exactly(2))
148-
->method('isSetFlag')
149-
->withAnyParameters()
150-
->willReturn(true);
151143
}
144+
$flagMap = [
145+
['payment/'. Config::METHOD_WPS_EXPRESS . '/active', ScopeInterface::SCOPE_STORE, null, 0],
146+
['payment/'. Config::METHOD_WPS_BML . '/active', ScopeInterface::SCOPE_STORE, null, 0],
147+
['payment/'. Config::METHOD_WPP_EXPRESS . '/active', ScopeInterface::SCOPE_STORE, null, 1],
148+
['payment/'. Config::METHOD_PAYFLOWPRO . '/active', ScopeInterface::SCOPE_STORE, null, 1],
149+
['payment/'. Config::METHOD_WPP_PE_EXPRESS . '/active', ScopeInterface::SCOPE_STORE, null, 1],
150+
['payment/'. Config::METHOD_WPP_PE_BML . '/active', ScopeInterface::SCOPE_STORE, null, 1],
151+
];
152+
$this->scopeConfig->method('isSetFlag')
153+
->willReturnMap($flagMap);
152154

153155
$this->model->setMethod($methodName);
154156
$this->assertEquals($expected, $this->model->isMethodAvailable($methodName));

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

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,11 @@
1414
<argument name="position" xsi:type="number">0</argument>
1515
</arguments>
1616
</block>
17-
<block class="Magento\Paypal\Block\PayLater\Banner" name="paylater.center.logo"
17+
<block class="Magento\Paypal\Block\PayLater\Banner" name="top.container.paylater"
1818
template="Magento_Paypal::paylater/banner.phtml">
1919
<arguments>
2020
<argument name="placement" xsi:type="string">product</argument>
2121
<argument name="position" xsi:type="string">header</argument>
22-
<argument name="jsLayout" xsi:type="array">
23-
<item name="components" xsi:type="array">
24-
<item name="payLater" xsi:type="array">
25-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater</item>
26-
<item name="config" xsi:type="array">
27-
<item name="attributes" xsi:type="array">
28-
<item name="data-pp-placement" xsi:type="string">product</item>
29-
</item>
30-
</item>
31-
</item>
32-
</item>
33-
</argument>
3422
</arguments>
3523
</block>
3624
</referenceContainer>
@@ -41,25 +29,22 @@
4129
<argument name="position" xsi:type="number">1</argument>
4230
</arguments>
4331
</block>
44-
<block class="Magento\Paypal\Block\PayLater\Banner" name="paylater.right.logo"
32+
<block class="Magento\Paypal\Block\PayLater\Banner" name="product.info.addtocart.paylater"
4533
template="Magento_Paypal::paylater/banner.phtml">
4634
<arguments>
4735
<argument name="placement" xsi:type="string">product</argument>
48-
<argument name="position" xsi:type="string">sidebar</argument>
49-
<argument name="jsLayout" xsi:type="array">
50-
<item name="components" xsi:type="array">
51-
<item name="payLater" xsi:type="array">
52-
<item name="component" xsi:type="string">Magento_Paypal/js/view/paylater</item>
53-
<item name="config" xsi:type="array">
54-
<item name="attributes" xsi:type="array">
55-
<item name="data-pp-placement" xsi:type="string">product</item>
56-
</item>
57-
</item>
58-
</item>
59-
</item>
60-
</argument>
36+
<argument name="position" xsi:type="string">near_pp_button</argument>
6137
</arguments>
6238
</block>
6339
</referenceContainer>
40+
<referenceBlock name="product.info.addtocart.additional">
41+
<block class="Magento\Paypal\Block\PayLater\Banner" name="product.info.addtocart.additional.paylater"
42+
template="Magento_Paypal::paylater/banner.phtml">
43+
<arguments>
44+
<argument name="placement" xsi:type="string">product</argument>
45+
<argument name="position" xsi:type="string">near_pp_button</argument>
46+
</arguments>
47+
</block>
48+
</referenceBlock>
6449
</body>
6550
</page>

0 commit comments

Comments
 (0)