Skip to content

Commit a361046

Browse files
committed
Merge remote-tracking branch 'mpi/MC-19296' into Chaika-PR-2019-08-29-2
2 parents 71d6954 + 6d4a568 commit a361046

File tree

4 files changed

+74
-21
lines changed

4 files changed

+74
-21
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77

88
namespace Magento\Paypal\Model;
99

10+
use Magento\Checkout\Helper\Data;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\Locale\ResolverInterface;
13+
use Magento\Store\Model\ScopeInterface;
1114

1215
/**
1316
* Smart button config
@@ -34,21 +37,29 @@ class SmartButtonConfig
3437
*/
3538
private $allowedFunding;
3639

40+
/**
41+
* @var ScopeConfigInterface
42+
*/
43+
private $scopeConfig;
44+
3745
/**
3846
* @param ResolverInterface $localeResolver
3947
* @param ConfigFactory $configFactory
48+
* @param ScopeConfigInterface $scopeConfig
4049
* @param array $defaultStyles
4150
* @param array $allowedFunding
4251
*/
4352
public function __construct(
4453
ResolverInterface $localeResolver,
4554
ConfigFactory $configFactory,
55+
ScopeConfigInterface $scopeConfig,
4656
$defaultStyles = [],
4757
$allowedFunding = []
4858
) {
4959
$this->localeResolver = $localeResolver;
5060
$this->config = $configFactory->create();
5161
$this->config->setMethod(Config::METHOD_EXPRESS);
62+
$this->scopeConfig = $scopeConfig;
5263
$this->defaultStyles = $defaultStyles;
5364
$this->allowedFunding = $allowedFunding;
5465
}
@@ -61,14 +72,19 @@ public function __construct(
6172
*/
6273
public function getConfig(string $page): array
6374
{
75+
$isGuestCheckoutAllowed = $this->scopeConfig->isSetFlag(
76+
Data::XML_PATH_GUEST_CHECKOUT,
77+
ScopeInterface::SCOPE_STORE
78+
);
6479
return [
6580
'merchantId' => $this->config->getValue('merchant_id'),
6681
'environment' => ((int)$this->config->getValue('sandbox_flag') ? 'sandbox' : 'production'),
6782
'locale' => $this->localeResolver->getLocale(),
6883
'allowedFunding' => $this->getAllowedFunding($page),
6984
'disallowedFunding' => $this->getDisallowedFunding(),
7085
'styles' => $this->getButtonStyles($page),
71-
'isVisibleOnProductPage' => (int)$this->config->getValue('visible_on_product')
86+
'isVisibleOnProductPage' => $this->config->getValue('visible_on_product'),
87+
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed
7288
];
7389
}
7490

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

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77

88
namespace Magento\Paypal\Test\Unit\Model;
99

10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Paypal\Model\Config;
1012
use Magento\Paypal\Model\SmartButtonConfig;
1113
use Magento\Framework\Locale\ResolverInterface;
1214
use Magento\Paypal\Model\ConfigFactory;
1315

16+
/**
17+
* Class SmartButtonConfigTest
18+
*/
1419
class SmartButtonConfigTest extends \PHPUnit\Framework\TestCase
1520
{
1621
/**
@@ -31,9 +36,15 @@ class SmartButtonConfigTest extends \PHPUnit\Framework\TestCase
3136
protected function setUp()
3237
{
3338
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
34-
$this->configMock = $this->getMockBuilder(\Magento\Paypal\Model\Config::class)
39+
$this->configMock = $this->getMockBuilder(Config::class)
3540
->disableOriginalConstructor()
3641
->getMock();
42+
43+
/** @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject $scopeConfigMock */
44+
$scopeConfigMock = $this->getMockForAbstractClass(ScopeConfigInterface::class);
45+
$scopeConfigMock->method('isSetFlag')
46+
->willReturn(true);
47+
3748
/** @var \PHPUnit_Framework_MockObject_MockObject $configFactoryMock */
3849
$configFactoryMock = $this->getMockBuilder(ConfigFactory::class)
3950
->disableOriginalConstructor()
@@ -43,12 +54,15 @@ protected function setUp()
4354
$this->model = new SmartButtonConfig(
4455
$this->localeResolverMock,
4556
$configFactoryMock,
57+
$scopeConfigMock,
4658
$this->getDefaultStyles(),
4759
$this->getAllowedFundings()
4860
);
4961
}
5062

5163
/**
64+
* Tests config.
65+
*
5266
* @param string $page
5367
* @param string $locale
5468
* @param string $disallowedFundings
@@ -78,22 +92,33 @@ public function testGetConfig(
7892
array $expected = []
7993
) {
8094
$this->localeResolverMock->expects($this->any())->method('getLocale')->willReturn($locale);
81-
$this->configMock->expects($this->any())->method('getValue')->will($this->returnValueMap([
82-
['merchant_id', null, 'merchant'],
83-
['sandbox_flag', null, true],
84-
['disable_funding_options', null, $disallowedFundings],
85-
["{$page}_page_button_customize", null, $isCustomize],
86-
["{$page}_page_button_layout", null, $layout],
87-
["{$page}_page_button_size", null, $size],
88-
["{$page}_page_button_color", null, $color],
89-
["{$page}_page_button_shape", null, $shape],
90-
["{$page}_page_button_label", null, $label],
91-
[$page . '_page_button_' . $installmentPeriodLocale . '_installment_period', null, $installmentPeriodLabel]
92-
]));
95+
$this->configMock->method('getValue')->will(
96+
$this->returnValueMap(
97+
[
98+
['merchant_id', null, 'merchant'],
99+
['sandbox_flag', null, true],
100+
['disable_funding_options', null, $disallowedFundings],
101+
["{$page}_page_button_customize", null, $isCustomize],
102+
["{$page}_page_button_layout", null, $layout],
103+
["{$page}_page_button_size", null, $size],
104+
["{$page}_page_button_color", null, $color],
105+
["{$page}_page_button_shape", null, $shape],
106+
["{$page}_page_button_label", null, $label],
107+
[
108+
$page . '_page_button_' . $installmentPeriodLocale . '_installment_period',
109+
null,
110+
$installmentPeriodLabel
111+
]
112+
]
113+
)
114+
);
93115

94116
self::assertEquals($expected, $this->model->getConfig($page));
95117
}
96118

119+
/**
120+
* @return array
121+
*/
97122
public function getConfigDataProvider()
98123
{
99124
return include __DIR__ . '/_files/expected_config.php';

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
'label' => 'installment',
3333
'installmentperiod' => 0
3434
],
35-
'isVisibleOnProductPage' => 0
35+
'isVisibleOnProductPage' => 0,
36+
'isGuestCheckoutAllowed' => true
3637
]
3738
],
3839
'checkout' => [
@@ -61,7 +62,8 @@
6162
'label' => 'installment',
6263
'installmentperiod' => 0
6364
],
64-
'isVisibleOnProductPage' => 0
65+
'isVisibleOnProductPage' => 0,
66+
'isGuestCheckoutAllowed' => true
6567
]
6668
],
6769
'mini_cart' => [
@@ -89,7 +91,8 @@
8991
'shape' => 'rect',
9092
'label' => 'paypal'
9193
],
92-
'isVisibleOnProductPage' => 0
94+
'isVisibleOnProductPage' => 0,
95+
'isGuestCheckoutAllowed' => true
9396
]
9497
],
9598
'mini_cart' => [
@@ -117,7 +120,8 @@
117120
'shape' => 'rect',
118121
'label' => 'paypal'
119122
],
120-
'isVisibleOnProductPage' => 0
123+
'isVisibleOnProductPage' => 0,
124+
'isGuestCheckoutAllowed' => true
121125
]
122126
],
123127
'product' => [
@@ -145,7 +149,8 @@
145149
'shape' => 'rect',
146150
'label' => 'paypal',
147151
],
148-
'isVisibleOnProductPage' => 0
152+
'isVisibleOnProductPage' => 0,
153+
'isGuestCheckoutAllowed' => true
149154
]
150155
]
151156
];

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,22 @@ define([
2121
/** @inheritdoc */
2222
initialize: function (config, element) {
2323
var cart = customerData.get('cart'),
24-
customer = customerData.get('customer');
24+
customer = customerData.get('customer'),
25+
isGuestCheckoutAllowed;
2526

2627
this._super();
2728

29+
isGuestCheckoutAllowed = cart().isGuestCheckoutAllowed;
30+
31+
if (typeof isGuestCheckoutAllowed === 'undefined') {
32+
isGuestCheckoutAllowed = config.clientConfig.isGuestCheckoutAllowed;
33+
}
34+
2835
if (config.clientConfig.isVisibleOnProductPage) {
2936
this.renderPayPalButtons(element);
3037
}
3138

32-
this.declinePayment = !customer().firstname && !cart().isGuestCheckoutAllowed;
39+
this.declinePayment = !customer().firstname && !isGuestCheckoutAllowed;
3340

3441
return this;
3542
},

0 commit comments

Comments
 (0)