Skip to content

Commit eae3288

Browse files
author
Alexander Makeev
committed
Merge branch 'MAGETWO-31043' into PR-MPI-S76
2 parents bb0ee7e + 0486d3d commit eae3288

File tree

63 files changed

+1923
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1923
-224
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable;
7+
8+
/**
9+
* Class InContext
10+
*/
11+
class InContext extends AbstractEnable
12+
{
13+
/**
14+
* Getting the name of a UI attribute
15+
*
16+
* @return string
17+
*/
18+
protected function getDataAttributeName()
19+
{
20+
return 'in-context';
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable;
7+
8+
/**
9+
* Class InContextApi
10+
*/
11+
class InContextApi extends AbstractEnable
12+
{
13+
/**
14+
* Getting the name of a UI attribute
15+
*
16+
* @return string
17+
*/
18+
protected function getDataAttributeName()
19+
{
20+
return 'in-context-api';
21+
}
22+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Block\Express\InContext;
7+
8+
use Magento\Paypal\Model\Config;
9+
use Magento\Paypal\Model\ConfigFactory;
10+
use Magento\Framework\View\Element\Template;
11+
use Magento\Framework\Locale\ResolverInterface;
12+
use Magento\Framework\View\Element\Template\Context;
13+
14+
/**
15+
* Class Component
16+
*/
17+
class Component extends Template
18+
{
19+
const IS_BUTTON_CONTEXT_INDEX = 'is_button_context';
20+
21+
/**
22+
* @var ResolverInterface
23+
*/
24+
private $localeResolver;
25+
26+
/**
27+
* @var Config
28+
*/
29+
private $config;
30+
31+
/**
32+
* @inheritdoc
33+
* @param ResolverInterface $localeResolver
34+
*/
35+
public function __construct(
36+
Context $context,
37+
ResolverInterface $localeResolver,
38+
ConfigFactory $configFactory,
39+
array $data = []
40+
) {
41+
parent::__construct($context, $data);
42+
$this->localeResolver = $localeResolver;
43+
$this->config = $configFactory->create();
44+
45+
$this->config->setMethod(Config::METHOD_EXPRESS);
46+
}
47+
48+
/**
49+
* @inheritdoc
50+
*/
51+
protected function _toHtml()
52+
{
53+
if (!$this->isInContext()) {
54+
return '';
55+
}
56+
57+
return parent::_toHtml();
58+
}
59+
60+
/**
61+
* @return bool
62+
*/
63+
private function isInContext()
64+
{
65+
return (bool)(int) $this->config->getValue('in_context');
66+
}
67+
68+
/**
69+
* @return string
70+
*/
71+
public function getEnvironment()
72+
{
73+
return (int) $this->config->getValue('sandbox_flag') ? 'sandbox' : 'production';
74+
}
75+
76+
/**
77+
* @return string
78+
*/
79+
public function getLocale()
80+
{
81+
return $this->localeResolver->getLocale();
82+
}
83+
84+
/**
85+
* @return string
86+
*/
87+
public function getMerchantId()
88+
{
89+
return $this->config->getValue('merchant_id');
90+
}
91+
92+
/**
93+
* @return bool
94+
*/
95+
public function isButtonContext()
96+
{
97+
return (bool) $this->getData(self::IS_BUTTON_CONTEXT_INDEX);
98+
}
99+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Paypal\Block\Express\InContext\Minicart;
7+
8+
use Magento\Paypal\Model\Config;
9+
use Magento\Paypal\Model\ConfigFactory;
10+
use Magento\Paypal\Block\Express\InContext;
11+
use Magento\Framework\View\Element\Template;
12+
use Magento\Catalog\Block\ShortcutInterface;
13+
use Magento\Framework\Locale\ResolverInterface;
14+
use Magento\Framework\View\Element\Template\Context;
15+
16+
/**
17+
* Class Button
18+
*/
19+
class Button extends Template implements ShortcutInterface
20+
{
21+
const ALIAS_ELEMENT_INDEX = 'alias';
22+
23+
const PAYPAL_BUTTON_ID = 'paypal-express-in-context-checkout-main';
24+
25+
const BUTTON_ELEMENT_INDEX = 'button_id';
26+
27+
const CART_BUTTON_ELEMENT_INDEX = 'add_to_cart_selector';
28+
29+
/**
30+
* @var bool
31+
*/
32+
private $isMiniCart = false;
33+
34+
/**
35+
* @var ResolverInterface
36+
*/
37+
private $localeResolver;
38+
39+
/**
40+
* @var Config
41+
*/
42+
private $config;
43+
44+
/**
45+
* Constructor
46+
*
47+
* @param Context $context
48+
* @param ResolverInterface $localeResolver
49+
* @param ConfigFactory $configFactory
50+
* @param array $data
51+
*/
52+
public function __construct(
53+
Context $context,
54+
ResolverInterface $localeResolver,
55+
ConfigFactory $configFactory,
56+
array $data = []
57+
) {
58+
parent::__construct($context, $data);
59+
60+
$this->localeResolver = $localeResolver;
61+
$this->config = $configFactory->create();
62+
$this->config->setMethod(Config::METHOD_EXPRESS);
63+
}
64+
65+
/**
66+
* @return bool
67+
*/
68+
private function isInContext()
69+
{
70+
return (bool)(int) $this->config->getValue('in_context');
71+
}
72+
73+
/**
74+
* @return bool
75+
*/
76+
protected function shouldRender()
77+
{
78+
return $this->isMiniCart && $this->isInContext();
79+
}
80+
81+
/**
82+
* @inheritdoc
83+
*/
84+
protected function _toHtml()
85+
{
86+
if (!$this->shouldRender()) {
87+
return '';
88+
}
89+
90+
return parent::_toHtml();
91+
}
92+
93+
/**
94+
* @return string
95+
*/
96+
public function getContainerId()
97+
{
98+
return $this->getData(self::BUTTON_ELEMENT_INDEX);
99+
}
100+
101+
/**
102+
* @return string
103+
*/
104+
public function getAddToCartSelector()
105+
{
106+
return $this->getData(self::CART_BUTTON_ELEMENT_INDEX);
107+
}
108+
109+
/**
110+
* @return string
111+
*/
112+
public function getImageUrl()
113+
{
114+
return $this->config->getExpressCheckoutInContextImageUrl(
115+
$this->localeResolver->getLocale()
116+
);
117+
}
118+
119+
/**
120+
* Get shortcut alias
121+
*
122+
* @return string
123+
*/
124+
public function getAlias()
125+
{
126+
return $this->getData(self::ALIAS_ELEMENT_INDEX);
127+
}
128+
129+
/**
130+
* @param bool $isCatalog
131+
* @return $this
132+
*/
133+
public function setIsInCatalogProduct($isCatalog)
134+
{
135+
$this->isMiniCart = !$isCatalog;
136+
137+
return $this;
138+
}
139+
}

app/code/Magento/Paypal/Block/Express/Shortcut.php

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Paypal\Block\Express;
77

8+
use Magento\Paypal\Model\Config;
89
use Magento\Catalog\Block as CatalogBlock;
910
use Magento\Paypal\Helper\Shortcut\ValidatorInterface;
1011

@@ -92,6 +93,11 @@ class Shortcut extends \Magento\Framework\View\Element\Template implements Catal
9293
*/
9394
private $_shortcutValidator;
9495

96+
/**
97+
* @var Config
98+
*/
99+
private $config;
100+
95101
/**
96102
* @param \Magento\Framework\View\Element\Template\Context $context
97103
* @param \Magento\Paypal\Helper\Data $paypalData
@@ -142,6 +148,9 @@ public function __construct(
142148
$this->setTemplate($shortcutTemplate);
143149

144150
parent::__construct($context, $data);
151+
152+
$this->config = $this->_paypalConfigFactory->create();
153+
$this->config->setMethod($this->_paymentMethodCode);
145154
$this->currentCustomer = $currentCustomer;
146155
}
147156

@@ -151,9 +160,6 @@ public function __construct(
151160
protected function _beforeToHtml()
152161
{
153162
$result = parent::_beforeToHtml();
154-
/** @var \Magento\Paypal\Model\Config $config */
155-
$config = $this->_paypalConfigFactory->create();
156-
$config->setMethod($this->_paymentMethodCode);
157163

158164
$isInCatalog = $this->getIsInCatalogProduct();
159165

@@ -173,17 +179,17 @@ protected function _beforeToHtml()
173179

174180
// use static image if in catalog
175181
if ($isInCatalog || null === $quote) {
176-
$this->setImageUrl($config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
182+
$this->setImageUrl($this->config->getExpressCheckoutShortcutImageUrl($this->_localeResolver->getLocale()));
177183
} else {
178184
/**@todo refactor checkout model. Move getCheckoutShortcutImageUrl to helper or separate model */
179-
$parameters = ['params' => ['quote' => $quote, 'config' => $config]];
185+
$parameters = ['params' => ['quote' => $quote, 'config' => $this->config]];
180186
$checkoutModel = $this->_checkoutFactory->create($this->_checkoutType, $parameters);
181187
$this->setImageUrl($checkoutModel->getCheckoutShortcutImageUrl());
182188
}
183189

184190
// ask whether to create a billing agreement
185191
$customerId = $this->currentCustomer->getCustomerId(); // potential issue for caching
186-
if ($this->_paypalData->shouldAskToCreateBillingAgreement($config, $customerId)) {
192+
if ($this->_paypalData->shouldAskToCreateBillingAgreement($this->config, $customerId)) {
187193
$this->setConfirmationUrl(
188194
$this->getUrl(
189195
$this->_startAction,
@@ -205,12 +211,28 @@ protected function _beforeToHtml()
205211
*/
206212
protected function _toHtml()
207213
{
208-
if (!$this->_shouldRender) {
214+
if (!$this->shouldRender()) {
209215
return '';
210216
}
211217
return parent::_toHtml();
212218
}
213219

220+
/**
221+
* @return bool
222+
*/
223+
protected function shouldRender()
224+
{
225+
$this->config->setMethod(Config::METHOD_EXPRESS);
226+
227+
$isInCatalog = $this->getIsInCatalogProduct();
228+
$isInContext = (bool)(int) $this->config->getValue('in_context');
229+
230+
$isEnabled = ($isInContext && $isInCatalog) || !$isInContext;
231+
$this->config->setMethod($this->_paymentMethodCode);
232+
233+
return $isEnabled && $this->_shouldRender;
234+
}
235+
214236
/**
215237
* Check is "OR" label position before shortcut
216238
*

0 commit comments

Comments
 (0)