Skip to content

Commit 457d7b8

Browse files
committed
Merge remote-tracking branch 'trigger/MC-41604' into MC-41701
2 parents 5c65fac + fb6a73e commit 457d7b8

File tree

15 files changed

+278
-11
lines changed

15 files changed

+278
-11
lines changed

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);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public function isEnabled(string $placement): bool
6161
{
6262
$enabled = false;
6363
if ($this->isPPCreditEnabled()) {
64+
$payLaterActive = (boolean)$this->config->getPayLaterConfigValue('experience_active');
6465
$isPayLaterEnabled = (boolean)$this->config->getPayLaterConfigValue('enabled');
65-
$enabled = $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
66+
$enabled = $payLaterActive && $isPayLaterEnabled && $this->getSectionConfig($placement, 'display');
6667
}
6768
return $enabled;
6869
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
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\Setup\Patch\Data;
9+
10+
use Magento\Framework\Setup\ModuleDataSetupInterface;
11+
use Magento\Framework\Setup\Patch\DataPatchInterface;
12+
13+
/**
14+
* Update bml config settings to the equivalent paylater settings
15+
*/
16+
class UpdateBmltoPayLater implements DataPatchInterface
17+
{
18+
/**
19+
* BML config path
20+
*/
21+
private const BMLPATH = 'payment/paypal_express_bml/';
22+
23+
/**
24+
* PayLater config path
25+
*/
26+
private const PAYLATERPATH = 'payment/paypal_paylater/';
27+
28+
/**
29+
* @var array
30+
*/
31+
private $bmlToPayLater = [
32+
[
33+
'pages' => ['productpage'],
34+
'data' => [
35+
'position' => [
36+
'name' =>'position',
37+
'values' => ['0' => 'header', '1' => 'near_pp_button'],
38+
'requires' => [
39+
'header' => ['name' => 'stylelayout', 'value' => 'flex'],
40+
'near_pp_button' => ['name' => 'stylelayout', 'value' => 'text']
41+
]
42+
],
43+
'size' => [
44+
'name' => 'ratio',
45+
'values' => [
46+
'190x100' => '8x1',
47+
'234x60' => '8x1',
48+
'300x50' => '8x1',
49+
'468x60' => '8x1',
50+
'728x90' => '20x1',
51+
'800x66' => '20x1'
52+
],
53+
'depends' => ['name' => 'position', 'value' => '0']
54+
]
55+
]
56+
]
57+
];
58+
59+
/**
60+
* @var ModuleDataSetupInterface
61+
*/
62+
private $moduleDataSetup;
63+
64+
/**
65+
* PrepareInitialConfig constructor.
66+
* @param ModuleDataSetupInterface $moduleDataSetup
67+
*/
68+
public function __construct(
69+
ModuleDataSetupInterface $moduleDataSetup
70+
) {
71+
$this->moduleDataSetup = $moduleDataSetup;
72+
}
73+
74+
/**
75+
* @inheritdoc
76+
*/
77+
public function apply()
78+
{
79+
$this->moduleDataSetup->getConnection()->startSetup();
80+
81+
$select = $this->moduleDataSetup->getConnection()->select()
82+
->from(
83+
$this->moduleDataSetup->getTable('core_config_data'),
84+
['path', 'value']
85+
)
86+
->where('path LIKE ?', self::BMLPATH . '%');
87+
$bmlSettings = $this->moduleDataSetup->getConnection()->fetchPairs($select);
88+
89+
foreach ($bmlSettings as $bmlPath => $bmlValue) {
90+
$setting = str_replace(self::BMLPATH, '', $bmlPath);
91+
$settingParts = explode('_', $setting);
92+
$page = $settingParts[0];
93+
$setting = $settingParts[1];
94+
$payLaterPath = self::PAYLATERPATH . $page;
95+
96+
if (array_key_exists(self::BMLPATH . $page . '_display', $bmlSettings)
97+
&& $bmlSettings[self::BMLPATH . $page . '_display'] === '0'
98+
) {
99+
continue;
100+
}
101+
102+
foreach ($this->bmlToPayLater as $bmlToPayLaterSetting) {
103+
if (in_array($page, $bmlToPayLaterSetting['pages'])
104+
&& array_key_exists($setting, $bmlToPayLaterSetting['data'])
105+
) {
106+
$pageSetting = $bmlToPayLaterSetting['data'][$setting];
107+
108+
$this->convertAndSaveConfigValues($bmlSettings, $pageSetting, $payLaterPath, $page, $bmlValue);
109+
}
110+
}
111+
}
112+
113+
return $this->moduleDataSetup->getConnection()->endSetup();
114+
}
115+
116+
/**
117+
* Convert BML settings to PayLater and save
118+
*
119+
* @param array $bmlSettings
120+
* @param array $pageSetting
121+
* @param string $payLaterPath
122+
* @param string $page
123+
* @param string $bmlValue
124+
*/
125+
private function convertAndSaveConfigValues(
126+
array $bmlSettings,
127+
array $pageSetting,
128+
string $payLaterPath,
129+
string $page,
130+
string $bmlValue
131+
) {
132+
$dependsPath = isset($pageSetting['depends'])
133+
? self::BMLPATH . $page . '_' . $pageSetting['depends']['name']
134+
: '';
135+
136+
if (!array_key_exists('depends', $pageSetting)
137+
|| (array_key_exists($dependsPath, $bmlSettings)
138+
&& $bmlSettings[$dependsPath] === $pageSetting['depends']['value'])
139+
) {
140+
$path = $payLaterPath . '_' . $pageSetting['name'];
141+
$value = $pageSetting['values'][$bmlValue];
142+
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
143+
$this->moduleDataSetup->getTable('core_config_data'),
144+
[
145+
'scope' => 'default',
146+
'scope_id' => 0,
147+
'path' => $path,
148+
'value' => $value
149+
]
150+
);
151+
if (array_key_exists('requires', $pageSetting)
152+
&& array_key_exists($value, $pageSetting['requires'])
153+
) {
154+
$requiredPath = $payLaterPath . '_' . $pageSetting['requires'][$value]['name'];
155+
$requiredValue = $pageSetting['requires'][$value]['value'];
156+
$this->moduleDataSetup->getConnection()->insertOnDuplicate(
157+
$this->moduleDataSetup->getTable('core_config_data'),
158+
[
159+
'scope' => 'default',
160+
'scope_id' => 0,
161+
'path' => $requiredPath,
162+
'value' => $requiredValue
163+
]
164+
);
165+
}
166+
}
167+
}
168+
169+
/**
170+
* @inheritdoc
171+
*/
172+
public static function getDependencies()
173+
{
174+
return [];
175+
}
176+
177+
/**
178+
* @inheritdoc
179+
*/
180+
public function getAliases()
181+
{
182+
return [];
183+
}
184+
}

app/code/Magento/Paypal/etc/adminhtml/system.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
</group>
5252
<group id="payments_pro_hosted_solution_without_bml_and_paylater" extends="payments_pro_hosted_solution_without_bml">
5353
<group id="pphs_required_settings">
54+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
5455
<group id="pphs_advertise_paylater" showInDefault="0" showInWebsite="0"/>
5556
</group>
5657
</group>
@@ -267,6 +268,7 @@
267268
<group id="express_checkout_required">
268269
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
269270
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
271+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
270272
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
271273
<group id="advertise_paylater" showInDefault="0" showInWebsite="0"/>
272274
</group>
@@ -298,6 +300,7 @@
298300
</field>
299301
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
300302
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
303+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
301304
<group id="advertise_bml" showInDefault="0" showInWebsite="0"/>
302305
<group id="advertise_paylater" showInDefault="0" showInWebsite="0"/>
303306
</group>
@@ -345,6 +348,7 @@
345348
<config_path>payment/paypal_payment_pro/active</config_path>
346349
<frontend_model>Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\Payment</frontend_model>
347350
</field>
351+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
348352
<group id="paypal_payflow_advertise_paylater" showInDefault="0" showInWebsite="0"/>
349353
</group>
350354
<group id="settings_paypal_payflow">
@@ -353,13 +357,15 @@
353357
</group>
354358
<group id="paypal_payflowpro_ca" extends="payment_all_paypal/paypal_payflowpro" sortOrder="40">
355359
<group id="paypal_payflow_required">
360+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
356361
<group id="paypal_payflow_advertise_paylater" showInDefault="0" showInWebsite="0"/>
357362
</group>
358363
</group>
359364
<group id="payflow_link_ca" extends="payment_all_paypal/payflow_link" sortOrder="50">
360365
<group id="payflow_link_required">
361366
<field id="enable_express_checkout_bml" showInDefault="0" showInWebsite="0"/>
362367
<field id="express_checkout_bml_sort_order" showInDefault="0" showInWebsite="0"/>
368+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
363369
<group id="payflow_link_advertise_bml" showInDefault="0" showInWebsite="0"/>
364370
<group id="payflow_link_advertise_paylater" showInDefault="0" showInWebsite="0"/>
365371
</group>
@@ -369,12 +375,14 @@
369375
<section id="payment_au" extends="payment_other">
370376
<group id="express_checkout_other">
371377
<group id="express_checkout_required">
378+
<field id="enable_paypal_paylater_experience" showInDefault="1" showInWebsite="1"/>
372379
<group id="advertise_paylater" showInDefault="1" showInWebsite="1"/>
373380
</group>
374381
</group>
375382
<group id="paypal_group_all_in_one">
376383
<group id="wps_other" sortOrder="12">
377384
<group id="express_checkout_required">
385+
<field id="enable_paypal_paylater_experience" showInDefault="1" showInWebsite="1"/>
378386
<group id="advertise_paylater" showInDefault="1" showInWebsite="1"/>
379387
</group>
380388
</group>
@@ -396,6 +404,7 @@
396404
<section id="payment_fr" extends="payment_other">
397405
<group id="express_checkout_other">
398406
<group id="express_checkout_required">
407+
<field id="enable_paypal_paylater_experience" showInDefault="1" showInWebsite="1"/>
399408
<group id="advertise_paylater" showInDefault="1" showInWebsite="1">
400409
<field id="paylater_enabled">
401410
<comment>
@@ -417,6 +426,7 @@
417426
<group id="paypal_group_all_in_one">
418427
<group id="wps_other" sortOrder="12">
419428
<group id="express_checkout_required">
429+
<field id="enable_paypal_paylater_experience" showInDefault="1" showInWebsite="1"/>
420430
<group id="advertise_paylater" showInDefault="1" showInWebsite="1">
421431
<field id="paylater_enabled">
422432
<comment>
@@ -438,6 +448,7 @@
438448
<group id="payments_pro_hosted_solution_fr" extends="payment_all_paypal/payments_pro_hosted_solution_without_bml" sortOrder="10">
439449
<label>Integral Evolution</label>
440450
<group id="pphs_required_settings">
451+
<field id="enable_paypal_paylater_experience" showInDefault="1" showInWebsite="1"/>
441452
<group id="pphs_advertise_paylater">
442453
<field id="paylater_enabled">
443454
<comment>
@@ -491,6 +502,7 @@
491502
<group id="paypal_payment_gateways" showInDefault="1" showInWebsite="1" showInStore="1">
492503
<group id="paypal_payflowpro_nz" extends="payment_all_paypal/paypal_payflowpro">
493504
<group id="paypal_payflow_required">
505+
<field id="enable_paypal_paylater_experience" showInDefault="0" showInWebsite="0"/>
494506
<group id="paypal_payflow_advertise_paylater" showInDefault="0" showInWebsite="0"/>
495507
</group>
496508
</group>

app/code/Magento/Paypal/etc/adminhtml/system/express_checkout.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,18 @@
183183
<field id="enable_express_checkout_bml">1</field>
184184
</depends>
185185
</field>
186+
<field id="enable_paypal_paylater_experience" translate="label comment" type="select" sortOrder="27" showInDefault="1" showInWebsite="1">
187+
<label>Enable PayPal PayLater Experience</label>
188+
<comment>
189+
<![CDATA[Recommended. <strong>Advertise PayPal Credit</strong> is deprecated.
190+
See PayPal PayLater details and list of supported regions
191+
<a href="https://developer.paypal.com/docs/business/pay-later/us/#eligibility" target="_blank">
192+
here</a>.]]>
193+
</comment>
194+
<config_path>payment/paypal_paylater/experience_active</config_path>
195+
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
196+
<attribute type="shared">1</attribute>
197+
</field>
186198
<group id="advertise_bml" translate="label comment" showInDefault="1" showInWebsite="1" sortOrder="30">
187199
<label>Advertise PayPal Credit</label>
188200
<comment>
@@ -193,6 +205,10 @@
193205
The PayPal Advertising Program has been shown to generate additional purchases as well as increase consumer's average purchase sizes by 15%
194206
or more. <a href="https://financing.paypal.com/ppfinportal/content/forrester" target="_blank">See Details</a>.]]>
195207
</comment>
208+
<fieldset_css>paypal-advertise-bml</fieldset_css>
209+
<depends>
210+
<field id="enable_paypal_paylater_experience">0</field>
211+
</depends>
196212
<field id="bml_publisher_id" translate="label comment tooltip" showInDefault="1" showInWebsite="1" sortOrder="10">
197213
<label>Publisher ID</label>
198214
<comment><![CDATA[Required to display a banner]]></comment>
@@ -322,6 +338,9 @@
322338
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
323339
<attribute type="shared">1</attribute>
324340
</field>
341+
<depends>
342+
<field id="enable_paypal_paylater_experience">1</field>
343+
</depends>
325344
<group id="settings_paylater_productpage" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="20">
326345
<label>Catalog Product Page</label>
327346
<depends>

app/code/Magento/Paypal/etc/adminhtml/system/payflow_advanced.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<field id="enable_express_checkout_bml">1</field>
118118
</depends>
119119
</field>
120+
<field id="enable_paypal_paylater_experience" sortOrder="55" extends="payment_all_paypal/express_checkout/express_checkout_required/enable_paypal_paylater_experience"/>
120121
<group id="advanced_advertise_bml" showInDefault="1" showInWebsite="1" sortOrder="60" translate="label comment">
121122
<label>Advertise PayPal Credit</label>
122123
<comment>
@@ -127,6 +128,10 @@
127128
The PayPal Advertising Program has been shown to generate additional purchases as well as increase consumer's average purchase sizes by 15%
128129
or more. <a href="https://financing.paypal.com/ppfinportal/content/forrester" target="_blank">See Details</a>.]]>
129130
</comment>
131+
<depends>
132+
<field id="enable_paypal_paylater_experience">0</field>
133+
</depends>
134+
<fieldset_css>paypal-advertise-bml</fieldset_css>
130135
<field id="bml_publisher_id" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_bml/bml_publisher_id" />
131136
<field id="bml_wizard" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_bml/bml_wizard" />
132137
<group id="advanced_settings_bml_homepage" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="20" translate="label">
@@ -213,6 +218,9 @@
213218
</group>
214219
<group id="advanced_advertise_paylater" translate="label" showInDefault="1" showInWebsite="1" sortOrder="70">
215220
<label>Advertise PayPal PayLater</label>
221+
<depends>
222+
<field id="enable_paypal_paylater_experience">1</field>
223+
</depends>
216224
<field id="paylater_enabled" extends="payment_all_paypal/express_checkout/express_checkout_required/advertise_paylater/paylater_enabled" />
217225
<group id="advanced_settings_paylater_productpage" translate="label" showInDefault="1" showInWebsite="1" showInStore="1" sortOrder="20">
218226
<label>Catalog Product Page</label>

0 commit comments

Comments
 (0)