Skip to content

Commit 49e721d

Browse files
committed
Merge remote-tracking branch 'gl_magento2ce/AC-1228' into AC-1228
2 parents f3e8f25 + 9e9fec6 commit 49e721d

File tree

5 files changed

+45
-10
lines changed

5 files changed

+45
-10
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Locale\ResolverInterface;
1313
use Magento\Store\Model\ScopeInterface;
1414
use Magento\Store\Model\StoreManagerInterface;
15+
use Magento\Paypal\Model\Config as PaypalConfig;
1516

1617
/**
1718
* Provides configuration values for PayPal in-context checkout
@@ -43,18 +44,25 @@ class SmartButtonConfig
4344
*/
4445
private $sdkUrl;
4546

47+
/**
48+
* @var PaypalConfig
49+
*/
50+
private $paypalConfig;
51+
4652
/**
4753
* @param ResolverInterface $localeResolver
4854
* @param ConfigFactory $configFactory
4955
* @param ScopeConfigInterface $scopeConfig
5056
* @param SdkUrl $sdkUrl
57+
* @param PaypalConfig $paypalConfig
5158
* @param array $defaultStyles
5259
*/
5360
public function __construct(
5461
ResolverInterface $localeResolver,
5562
ConfigFactory $configFactory,
5663
ScopeConfigInterface $scopeConfig,
5764
SdkUrl $sdkUrl,
65+
PaypalConfig $paypalConfig,
5866
$defaultStyles = []
5967
) {
6068
$this->localeResolver = $localeResolver;
@@ -63,6 +71,7 @@ public function __construct(
6371
$this->scopeConfig = $scopeConfig;
6472
$this->defaultStyles = $defaultStyles;
6573
$this->sdkUrl = $sdkUrl;
74+
$this->paypalConfig = $paypalConfig;
6675
}
6776

6877
/**
@@ -81,7 +90,10 @@ public function getConfig(string $page): array
8190
'styles' => $this->getButtonStyles($page),
8291
'isVisibleOnProductPage' => (bool)$this->config->getValue('visible_on_product'),
8392
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed,
84-
'sdkUrl' => $this->sdkUrl->getUrl()
93+
'sdkUrl' => $this->sdkUrl->getUrl(),
94+
'dataAttributes' => [
95+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
96+
]
8597
];
8698
}
8799

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ class SmartButtonConfigTest extends TestCase
4242
*/
4343
protected function setUp(): void
4444
{
45-
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
46-
$this->configMock = $this->getMockBuilder(Config::class)
45+
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
46+
$this->configMock = $this->getMockBuilder(Config::class)
4747
->disableOriginalConstructor()
4848
->getMock();
4949

@@ -67,7 +67,8 @@ protected function setUp(): void
6767
$configFactoryMock,
6868
$scopeConfigMock,
6969
$sdkUrl,
70-
$this->getDefaultStyles(),
70+
$this->configMock,
71+
$this->getDefaultStyles()
7172
);
7273
}
7374

app/code/Magento/Paypal/Test/Unit/Model/_files/expected_style_config.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727
],
2828
'isVisibleOnProductPage' => false,
2929
'isGuestCheckoutAllowed' => true,
30-
'sdkUrl' => 'http://mock.url'
30+
'sdkUrl' => 'http://mock.url',
31+
'dataAttributes' => [
32+
'data-partner-attribution-id' => ''
33+
]
3134
]
3235
],
3336
'checkout' => [
@@ -51,7 +54,10 @@
5154
],
5255
'isVisibleOnProductPage' => false,
5356
'isGuestCheckoutAllowed' => true,
54-
'sdkUrl' => 'http://mock.url'
57+
'sdkUrl' => 'http://mock.url',
58+
'dataAttributes' => [
59+
'data-partner-attribution-id' => ''
60+
]
5561
]
5662
],
5763
'mini_cart' => [
@@ -74,7 +80,10 @@
7480
],
7581
'isVisibleOnProductPage' => false,
7682
'isGuestCheckoutAllowed' => true,
77-
'sdkUrl' => 'http://mock.url'
83+
'sdkUrl' => 'http://mock.url',
84+
'dataAttributes' => [
85+
'data-partner-attribution-id' => ''
86+
]
7887
]
7988
],
8089
'product' => [
@@ -97,7 +106,10 @@
97106
],
98107
'isVisibleOnProductPage' => false,
99108
'isGuestCheckoutAllowed' => true,
100-
'sdkUrl' => 'http://mock.url'
109+
'sdkUrl' => 'http://mock.url',
110+
'dataAttributes' => [
111+
'data-partner-attribution-id' => ''
112+
]
101113
]
102114
],
103115
];

app/code/Magento/Paypal/view/frontend/web/js/in-context/express-checkout-smart-buttons.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ define([
6464
}
6565

6666
return function (clientConfig, element) {
67-
paypalSdk(clientConfig.sdkUrl).done(function (paypal) {
67+
paypalSdk(clientConfig.sdkUrl, clientConfig.dataAttributes).done(function (paypal) {
6868
paypal.Buttons({
6969
style: clientConfig.styles,
7070

app/code/Magento/Paypal/view/frontend/web/js/in-context/paypal-sdk.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ define([
1212
/**
1313
* Loads the PayPal SDK object
1414
* @param {String} paypalUrl - the url of the PayPal SDK
15+
* @param {Array} dataAttributes - Array of the Attributes for PayPal SDK Script tag
1516
*/
16-
return function loadPaypalScript(paypalUrl) {
17+
return function loadPaypalScript(paypalUrl, dataAttributes) {
1718
//configuration for loaded PayPal script
1819
require.config({
1920
paths: {
@@ -23,6 +24,15 @@ define([
2324
paypalSdk: {
2425
exports: 'paypal'
2526
}
27+
},
28+
29+
/**
30+
* Add attributes under Paypal SDK Script tag
31+
*/
32+
onNodeCreated: function (node) {
33+
$.each(dataAttributes, function (index, elem) {
34+
node.setAttribute(index, elem);
35+
});
2636
}
2737
});
2838

0 commit comments

Comments
 (0)