Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit f6876dd

Browse files
authored
Merge pull request #3681 from magento-trigger/MC-6279
[trigger] MC-5235 Update PayPal Express Checkout to JSv4
2 parents b46b8be + 8fc9911 commit f6876dd

File tree

92 files changed

+3706
-467
lines changed

Some content is hidden

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

92 files changed

+3706
-467
lines changed

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,16 @@ define([
165165
self.enableAddToCartButton(form);
166166
},
167167

168+
/** @inheritdoc */
169+
error: function (res) {
170+
$(document).trigger('ajax:addToCart:error', {
171+
'sku': form.data().productSku,
172+
'productIds': productIds,
173+
'form': form,
174+
'response': res
175+
});
176+
},
177+
168178
/** @inheritdoc */
169179
complete: function (res) {
170180
if (res.state() === 'rejected') {

app/code/Magento/Checkout/Block/QuoteShortcutButtons.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Magento\Framework\View\Element\Template;
99

1010
/**
11+
* Displays buttons on shopping cart page
12+
*
1113
* @api
1214
*/
1315
class QuoteShortcutButtons extends \Magento\Catalog\Block\ShortcutButtons
@@ -45,7 +47,8 @@ protected function _beforeToHtml()
4547
'container' => $this,
4648
'is_catalog_product' => $this->_isCatalogProduct,
4749
'or_position' => $this->_orPosition,
48-
'checkout_session' => $this->_checkoutSession
50+
'checkout_session' => $this->_checkoutSession,
51+
'is_shopping_cart' => true
4952
]
5053
);
5154
return $this;

app/code/Magento/Checkout/view/frontend/web/js/model/payment/additional-validators.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ define([], function () {
3535
*
3636
* @returns {Boolean}
3737
*/
38-
validate: function () {
38+
validate: function (hideError) {
3939
var validationResult = true;
4040

41+
hideError = hideError || false;
42+
4143
if (validators.length <= 0) {
4244
return validationResult;
4345
}
4446

4547
validators.forEach(function (item) {
46-
if (item.validate() == false) { //eslint-disable-line eqeqeq
48+
if (item.validate(hideError) == false) { //eslint-disable-line eqeqeq
4749
validationResult = false;
4850

4951
return false;

app/code/Magento/CheckoutAgreements/view/frontend/web/js/model/agreement-validator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ define([
1919
*
2020
* @returns {Boolean}
2121
*/
22-
validate: function () {
22+
validate: function (hideError) {
2323
var isValid = true;
2424

2525
if (!agreementsConfig.isEnabled || $(agreementsInputPath).length === 0) {
@@ -28,7 +28,8 @@ define([
2828

2929
$(agreementsInputPath).each(function (index, element) {
3030
if (!$.validator.validateSingleElement(element, {
31-
errorElement: 'div'
31+
errorElement: 'div',
32+
hideError: hideError || false
3233
})) {
3334
isValid = false;
3435
}

app/code/Magento/Config/etc/adminhtml/di.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9-
<preference for="Magento\Config\Model\Config\Structure\SearchInterface" type="Magento\Config\Model\Config\Structure" />
109
<preference for="Magento\Config\Model\Config\Backend\File\RequestData\RequestDataInterface" type="Magento\Config\Model\Config\Backend\File\RequestData" />
1110
<preference for="Magento\Config\Model\Config\Structure\ElementVisibilityInterface" type="Magento\Config\Model\Config\Structure\ElementVisibilityComposite" />
1211
<type name="Magento\Config\Model\Config\Structure\Element\Iterator\Tab" shared="false" />
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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\Block\Adminhtml\System\Config\Field\Depends;
9+
10+
use Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\AbstractEnable;
11+
12+
/**
13+
* Class ButtonStylesLabel
14+
*/
15+
class ButtonStylesLabel extends AbstractEnable
16+
{
17+
/**
18+
* Getting the name of a UI attribute
19+
*
20+
* @return string
21+
*/
22+
protected function getDataAttributeName()
23+
{
24+
return 'button-label';
25+
}
26+
}

app/code/Magento/Paypal/Block/Adminhtml/System/Config/Field/Enable/BmlApi.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
/**
99
* Class Bml
10+
* @deprecated
11+
* "Enable PayPal Credit" setting was removed. Please @see "Disable Funding Options"
1012
*/
1113
class BmlApi extends AbstractEnable
1214
{
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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\Block\Adminhtml\System\Config\MultiSelect;
9+
10+
use Magento\Paypal\Block\Adminhtml\System\Config\Field\Enable\AbstractEnable;
11+
use Magento\Paypal\Model\Config\StructurePlugin;
12+
use Magento\Backend\Block\Template\Context;
13+
use Magento\Paypal\Model\Config;
14+
use Magento\Framework\Data\Form\Element\AbstractElement;
15+
16+
/**
17+
* Class DisabledFundingOptions
18+
*/
19+
class DisabledFundingOptions extends AbstractEnable
20+
{
21+
/**
22+
* @var Config
23+
*/
24+
private $config;
25+
26+
/**
27+
* DisabledFundingOptions constructor.
28+
* @param Context $context
29+
* @param Config $config
30+
* @param array $data
31+
*/
32+
public function __construct(
33+
Context $context,
34+
Config $config,
35+
$data = []
36+
) {
37+
$this->config = $config;
38+
parent::__construct($context, $data);
39+
}
40+
41+
/**
42+
* Render country field considering request parameter
43+
*
44+
* @param AbstractElement $element
45+
* @return string
46+
*/
47+
public function render(AbstractElement $element)
48+
{
49+
if (!$this->isSelectedMerchantCountry('US')) {
50+
$fundingOptions = $element->getValues();
51+
$element->setValues($this->filterValuesForPaypalCredit($fundingOptions));
52+
}
53+
return parent::render($element);
54+
}
55+
56+
/**
57+
* Getting the name of a UI attribute
58+
*
59+
* @return string
60+
*/
61+
protected function getDataAttributeName(): string
62+
{
63+
return 'disable-funding-options';
64+
}
65+
66+
/**
67+
* Filters array for CREDIT
68+
*
69+
* @param array $options
70+
* @return array
71+
*/
72+
private function filterValuesForPaypalCredit($options): array
73+
{
74+
return array_filter($options, function ($opt) {
75+
return ($opt['value'] !== 'CREDIT');
76+
});
77+
}
78+
79+
/**
80+
* Checks for chosen Merchant country from the config/url
81+
*
82+
* @param string $country
83+
* @return bool
84+
*/
85+
private function isSelectedMerchantCountry(string $country): bool
86+
{
87+
$merchantCountry = $this->getRequest()->getParam(StructurePlugin::REQUEST_PARAM_COUNTRY)
88+
?: $this->config->getMerchantCountry();
89+
return $merchantCountry === $country;
90+
}
91+
}

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88

99
use Magento\Catalog\Block as CatalogBlock;
1010
use Magento\Paypal\Helper\Shortcut\ValidatorInterface;
11+
use Magento\Paypal\Model\ConfigFactory;
12+
use Magento\Paypal\Model\Config;
13+
use Magento\Framework\App\ObjectManager;
1114

15+
/**
16+
* Class shortcut
17+
*/
1218
class Shortcut extends \Magento\Framework\View\Element\Template implements CatalogBlock\ShortcutInterface
1319
{
1420
/**
@@ -66,6 +72,11 @@ class Shortcut extends \Magento\Framework\View\Element\Template implements Catal
6672
*/
6773
private $_shortcutValidator;
6874

75+
/**
76+
* @var Config
77+
*/
78+
private $config;
79+
6980
/**
7081
* @param \Magento\Framework\View\Element\Template\Context $context
7182
* @param \Magento\Payment\Helper\Data $paymentData
@@ -77,7 +88,9 @@ class Shortcut extends \Magento\Framework\View\Element\Template implements Catal
7788
* @param string $bmlMethodCode
7889
* @param string $shortcutTemplate
7990
* @param array $data
91+
* @param ConfigFactory|null $config
8092
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
93+
* @codingStandardsIgnoreStart
8194
*/
8295
public function __construct(
8396
\Magento\Framework\View\Element\Template\Context $context,
@@ -89,28 +102,35 @@ public function __construct(
89102
$alias,
90103
$bmlMethodCode,
91104
$shortcutTemplate,
92-
array $data = []
105+
array $data = [],
106+
ConfigFactory $config = null
93107
) {
94108
$this->_paymentData = $paymentData;
95109
$this->_mathRandom = $mathRandom;
96110
$this->_shortcutValidator = $shortcutValidator;
97-
98111
$this->_paymentMethodCode = $paymentMethodCode;
99112
$this->_startAction = $startAction;
100113
$this->_alias = $alias;
101114
$this->setTemplate($shortcutTemplate);
102115
$this->_bmlMethodCode = $bmlMethodCode;
116+
$this->config = $config
117+
? $config->create()
118+
: ObjectManager::getInstance()->get(ConfigFactory::class)->create();
119+
$this->config->setMethod($this->_paymentMethodCode);
103120
parent::__construct($context, $data);
104121
}
122+
//@codingStandardsIgnoreEnd
105123

106124
/**
107-
* @return \Magento\Framework\View\Element\AbstractBlock
125+
* @inheritdoc
108126
*/
109127
protected function _beforeToHtml()
110128
{
111129
$result = parent::_beforeToHtml();
112130
$isInCatalog = $this->getIsInCatalogProduct();
113-
if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)) {
131+
if (!$this->_shortcutValidator->validate($this->_paymentMethodCode, $isInCatalog)
132+
|| (bool)(int)$this->config->getValue('in_context')
133+
) {
114134
$this->_shouldRender = false;
115135
return $result;
116136
}

app/code/Magento/Paypal/Block/Express/InContext/Minicart/Button.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
use Magento\Payment\Model\MethodInterface;
1010
use Magento\Paypal\Model\Config;
1111
use Magento\Paypal\Model\ConfigFactory;
12-
use Magento\Paypal\Block\Express\InContext;
1312
use Magento\Framework\View\Element\Template;
1413
use Magento\Catalog\Block\ShortcutInterface;
1514
use Magento\Framework\Locale\ResolverInterface;
1615
use Magento\Framework\View\Element\Template\Context;
1716

1817
/**
1918
* Class Button
19+
* @deprecated @see \Magento\Paypal\Block\Express\InContext\Minicart\SmartButton
2020
*/
2121
class Button extends Template implements ShortcutInterface
2222
{
@@ -59,8 +59,8 @@ class Button extends Template implements ShortcutInterface
5959
* @param Context $context
6060
* @param ResolverInterface $localeResolver
6161
* @param ConfigFactory $configFactory
62-
* @param MethodInterface $payment
6362
* @param Session $session
63+
* @param MethodInterface $payment
6464
* @param array $data
6565
*/
6666
public function __construct(
@@ -101,8 +101,7 @@ private function isVisibleOnCart()
101101
}
102102

103103
/**
104-
* Check is Paypal In-Context Express Checkout button
105-
* should render in cart/mini-cart
104+
* Check is Paypal In-Context Express Checkout button should render in cart/mini-cart
106105
*
107106
* @return bool
108107
*/
@@ -127,6 +126,8 @@ protected function _toHtml()
127126
}
128127

129128
/**
129+
* Returns container id
130+
*
130131
* @return string
131132
*/
132133
public function getContainerId()
@@ -135,6 +136,8 @@ public function getContainerId()
135136
}
136137

137138
/**
139+
* Returns link action
140+
*
138141
* @return string
139142
*/
140143
public function getLinkAction()
@@ -143,6 +146,8 @@ public function getLinkAction()
143146
}
144147

145148
/**
149+
* Returns add to cart selector
150+
*
146151
* @return string
147152
*/
148153
public function getAddToCartSelector()
@@ -151,6 +156,8 @@ public function getAddToCartSelector()
151156
}
152157

153158
/**
159+
* Returns image url
160+
*
154161
* @return string
155162
*/
156163
public function getImageUrl()
@@ -171,6 +178,8 @@ public function getAlias()
171178
}
172179

173180
/**
181+
* Set information if button renders in the mini cart
182+
*
174183
* @param bool $isCatalog
175184
* @return $this
176185
*/

0 commit comments

Comments
 (0)