Skip to content

Commit 0e11c35

Browse files
author
Oleksandr Karpenko
committed
Merge branch 'develop' of https://github.corp.magento.com/magento2/magento2ce into develop
2 parents b83f2b1 + 7f2b288 commit 0e11c35

File tree

137 files changed

+3806
-4115
lines changed

Some content is hidden

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

137 files changed

+3806
-4115
lines changed

app/code/Magento/Authorizenet/Controller/Directpost/Payment/Redirect.php

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,12 @@
88

99
use Magento\Framework\App\ObjectManager;
1010
use Magento\Payment\Block\Transparent\Iframe;
11-
use Magento\Framework\Escaper;
1211

1312
/**
1413
* Class Redirect
1514
*/
1615
class Redirect extends \Magento\Authorizenet\Controller\Directpost\Payment
1716
{
18-
/**
19-
* @var Escaper
20-
*/
21-
private $escaper;
22-
2317
/**
2418
* Retrieve params and put javascript into iframe
2519
*
@@ -29,7 +23,7 @@ public function execute()
2923
{
3024
$helper = $this->dataFactory->create('frontend');
3125

32-
$redirectParams = $this->filterData($this->getRequest()->getParams());
26+
$redirectParams = $this->getRequest()->getParams();
3327
$params = [];
3428
if (!empty($redirectParams['success'])
3529
&& isset($redirectParams['x_invoice_num'])
@@ -38,9 +32,11 @@ public function execute()
3832
$this->_getDirectPostSession()->unsetData('quote_id');
3933
$params['redirect_parent'] = $helper->getSuccessOrderUrl([]);
4034
}
35+
4136
if (!empty($redirectParams['error_msg'])) {
4237
$cancelOrder = empty($redirectParams['x_invoice_num']);
4338
$this->_returnCustomerQuote($cancelOrder, $redirectParams['error_msg']);
39+
$params['error_msg'] = $redirectParams['error_msg'];
4440
}
4541

4642
if (isset($redirectParams['controller_action_name'])
@@ -50,34 +46,8 @@ public function execute()
5046
unset($params['redirect_parent']);
5147
}
5248

53-
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, array_merge($params, $redirectParams));
49+
$this->_coreRegistry->register(Iframe::REGISTRY_KEY, $params);
5450
$this->_view->addPageLayoutHandles();
5551
$this->_view->loadLayout(false)->renderLayout();
5652
}
57-
58-
/**
59-
* Escape xss in request data
60-
* @param array $data
61-
* @return array
62-
*/
63-
private function filterData(array $data)
64-
{
65-
$self = $this;
66-
array_walk($data, function (&$item) use ($self) {
67-
$item = $self->getEscaper()->escapeXssInUrl($item);
68-
});
69-
return $data;
70-
}
71-
72-
/**
73-
* Get Escaper instance
74-
* @return Escaper
75-
*/
76-
private function getEscaper()
77-
{
78-
if (!$this->escaper) {
79-
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
80-
}
81-
return $this->escaper;
82-
}
8353
}

app/code/Magento/Authorizenet/Test/Unit/Controller/Directpost/Payment/RedirectTest.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Magento\Authorizenet\Controller\Directpost\Payment\Redirect;
99
use Magento\Framework\App\RequestInterface;
1010
use Magento\Framework\App\ViewInterface;
11-
use Magento\Framework\Escaper;
1211
use Magento\Framework\Registry;
1312
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1413
use Magento\Payment\Block\Transparent\Iframe;
@@ -34,11 +33,6 @@ class RedirectTest extends \PHPUnit_Framework_TestCase
3433
*/
3534
private $coreRegistry;
3635

37-
/**
38-
* @var Escaper|MockObject
39-
*/
40-
private $escaper;
41-
4236
/**
4337
* @var Redirect
4438
*/
@@ -57,21 +51,11 @@ protected function setUp()
5751
->setMethods(['register'])
5852
->getMock();
5953

60-
$this->escaper = static::getMockBuilder(Escaper::class)
61-
->disableOriginalConstructor()
62-
->setMethods(['escapeXssInUrl'])
63-
->getMock();
64-
6554
$this->controller = $objectManager->getObject(Redirect::class, [
6655
'request' => $this->request,
6756
'view' => $this->view,
6857
'coreRegistry' => $this->coreRegistry
6958
]);
70-
71-
$refClass = new \ReflectionClass(Redirect::class);
72-
$refProperty = $refClass->getProperty('escaper');
73-
$refProperty->setAccessible(true);
74-
$refProperty->setValue($this->controller, $this->escaper);
7559
}
7660

7761
/**
@@ -87,14 +71,9 @@ public function testExecute()
8771
->method('getParams')
8872
->willReturn($params);
8973

90-
$this->escaper->expects(static::once())
91-
->method('escapeXssInUrl')
92-
->with($url)
93-
->willReturn($url);
94-
9574
$this->coreRegistry->expects(static::once())
9675
->method('register')
97-
->with(Iframe::REGISTRY_KEY, $params);
76+
->with(Iframe::REGISTRY_KEY, []);
9877

9978
$this->view->expects(static::once())
10079
->method('addPageLayoutHandles');

app/code/Magento/Braintree/Controller/Payment/GetNonce.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
use Magento\Framework\Controller\ResultInterface;
1313
use Magento\Framework\Session\SessionManagerInterface;
1414
use Magento\Framework\Webapi\Exception;
15-
use Psr\Log\LoggerInterface;
16-
use Magento\Vault\Model\Ui\TokenUiComponentProviderInterface;
17-
use Magento\CheckoutAgreements;
1815
use Magento\Theme;
16+
use Psr\Log\LoggerInterface;
1917

2018
/**
2119
* Class GetNonce

app/code/Magento/Braintree/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
"magento/module-catalog": "*",
1717
"magento/module-quote": "*",
1818
"magento/module-paypal": "*",
19-
"magento/module-checkout-agreements": "*",
2019
"magento/module-theme": "*",
2120
"braintree/braintree_php": "3.7.0"
2221
},
22+
"suggest": {
23+
"magento/module-checkout-agreements": "100.0.*"
24+
},
2325
"type": "magento2-module",
2426
"version": "100.0.2",
2527
"license": [

app/code/Magento/Braintree/etc/module.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<module name="Magento_Catalog"/>
1616
<module name="Magento_Quote"/>
1717
<module name="Magento_Paypal"/>
18-
<module name="Magento_CheckoutAgreements"/>
1918
<module name="Magento_Theme"/>
2019
</sequence>
2120
</module>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ define([
1010
'Magento_Checkout/js/view/payment/default',
1111
'Magento_Braintree/js/view/payment/adapter',
1212
'Magento_Checkout/js/model/quote',
13-
'Magento_Checkout/js/model/full-screen-loader'
14-
], function ($, _, Component, Braintree, quote, fullScreenLoader) {
13+
'Magento_Checkout/js/model/full-screen-loader',
14+
'Magento_Checkout/js/model/payment/additional-validators'
15+
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
1516
'use strict';
1617

1718
var checkout;
@@ -173,7 +174,9 @@ define([
173174
* Triggers when customer click "Continue to PayPal" button
174175
*/
175176
payWithPayPal: function () {
176-
checkout.paypal.initAuthFlow();
177+
if (additionalValidators.validate()) {
178+
checkout.paypal.initAuthFlow();
179+
}
177180
},
178181

179182
/**

app/code/Magento/Braintree/view/frontend/web/template/payment/form.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
</fieldset>
132132
<input type="submit" id="braintree_submit" style="display:none" />
133133
</form>
134+
<div class="checkout-agreements-block">
135+
<!-- ko foreach: $parent.getRegion('before-place-order') -->
136+
<!-- ko template: getTemplate() --><!-- /ko -->
137+
<!--/ko-->
138+
</div>
134139
<div class="actions-toolbar">
135140
<div class="primary">
136141
<button class="action primary checkout"

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class Helper
4040

4141
/**
4242
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
43+
*
44+
* @deprecated
4345
*/
4446
protected $dateFilter;
4547

@@ -68,6 +70,11 @@ class Helper
6870
*/
6971
private $linkResolver;
7072

73+
/**
74+
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
75+
*/
76+
private $dateTimeFilter;
77+
7178
/**
7279
* Helper constructor.
7380
* @param \Magento\Framework\App\RequestInterface $request
@@ -94,17 +101,17 @@ public function __construct(
94101
}
95102

96103
/**
97-
* Initialize product before saving
104+
* Initialize product from data
98105
*
99106
* @param \Magento\Catalog\Model\Product $product
107+
* @param array $productData
100108
* @return \Magento\Catalog\Model\Product
101109
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
102110
* @SuppressWarnings(PHPMD.NPathComplexity)
103111
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
104112
*/
105-
public function initialize(\Magento\Catalog\Model\Product $product)
113+
public function initializeFromData(\Magento\Catalog\Model\Product $product, array $productData)
106114
{
107-
$productData = (array)$this->request->getPost('product', []);
108115
unset($productData['custom_attributes']);
109116
unset($productData['extension_attributes']);
110117

@@ -142,14 +149,20 @@ public function initialize(\Magento\Catalog\Model\Product $product)
142149
foreach ($attributes as $attrKey => $attribute) {
143150
if ($attribute->getBackend()->getType() == 'datetime') {
144151
if (array_key_exists($attrKey, $productData) && $productData[$attrKey] != '') {
145-
$dateFieldFilters[$attrKey] = $this->dateFilter;
152+
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
146153
}
147154
}
148155
}
149156

150157
$inputFilter = new \Zend_Filter_Input($dateFieldFilters, [], $productData);
151158
$productData = $inputFilter->getUnescaped();
152159

160+
if (isset($productData['options'])) {
161+
$productOptions = $productData['options'];
162+
unset($productData['options']);
163+
} else {
164+
$productOptions = [];
165+
}
153166
$product->addData($productData);
154167

155168
if ($wasLockedMedia) {
@@ -176,15 +189,20 @@ public function initialize(\Magento\Catalog\Model\Product $product)
176189
/**
177190
* Initialize product options
178191
*/
179-
if (isset($productData['options']) && !$product->getOptionsReadonly()) {
192+
if ($productOptions && !$product->getOptionsReadonly()) {
180193
// mark custom options that should to fall back to default value
181194
$options = $this->mergeProductOptions(
182-
$productData['options'],
195+
$productOptions,
183196
$this->request->getPost('options_use_default')
184197
);
185198
$customOptions = [];
186199
foreach ($options as $customOptionData) {
187200
if (empty($customOptionData['is_delete'])) {
201+
if (isset($customOptionData['values'])) {
202+
$customOptionData['values'] = array_filter($customOptionData['values'], function ($valueData) {
203+
return empty($valueData['is_delete']);
204+
});
205+
}
188206
$customOption = $this->getCustomOptionFactory()->create(['data' => $customOptionData]);
189207
$customOption->setProductSku($product->getSku());
190208
$customOption->setOptionId(null);
@@ -200,6 +218,18 @@ public function initialize(\Magento\Catalog\Model\Product $product)
200218

201219
return $product;
202220
}
221+
222+
/**
223+
* Initialize product before saving
224+
*
225+
* @param \Magento\Catalog\Model\Product $product
226+
* @return \Magento\Catalog\Model\Product
227+
*/
228+
public function initialize(\Magento\Catalog\Model\Product $product)
229+
{
230+
$productData = $this->request->getPost('product', []);
231+
return $this->initializeFromData($product, $productData);
232+
}
203233

204234
/**
205235
* Setting product links
@@ -340,4 +370,18 @@ private function getLinkResolver()
340370
}
341371
return $this->linkResolver;
342372
}
373+
374+
/**
375+
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
376+
*
377+
* @deprecated
378+
*/
379+
private function getDateTimeFilter()
380+
{
381+
if ($this->dateTimeFilter === null) {
382+
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
383+
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
384+
}
385+
return $this->dateTimeFilter;
386+
}
343387
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/NewAction.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use Magento\Backend\App\Action;
1010
use Magento\Catalog\Controller\Adminhtml\Product;
11+
use Magento\Framework\App\ObjectManager;
1112

1213
class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product
1314
{
@@ -26,6 +27,11 @@ class NewAction extends \Magento\Catalog\Controller\Adminhtml\Product
2627
*/
2728
protected $resultForwardFactory;
2829

30+
/**
31+
* @var Initialization\Helper
32+
*/
33+
protected $initializationHelper;
34+
2935
/**
3036
* @param Action\Context $context
3137
* @param Builder $productBuilder
@@ -69,7 +75,7 @@ public function execute()
6975
if ($productData) {
7076
$stockData = isset($productData['stock_data']) ? $productData['stock_data'] : [];
7177
$productData['stock_data'] = $this->stockFilter->filter($stockData);
72-
$product->addData($productData);
78+
$product = $this->getInitializationHelper()->initializeFromData($product, $productData);
7379
}
7480

7581
$this->_eventManager->dispatch('catalog_product_new_action', ['product' => $product]);
@@ -92,4 +98,16 @@ public function execute()
9298

9399
return $resultPage;
94100
}
101+
102+
/**
103+
* @return Initialization\Helper
104+
* @deprecated
105+
*/
106+
protected function getInitializationHelper()
107+
{
108+
if (null === $this->initializationHelper) {
109+
$this->initializationHelper = ObjectManager::getInstance()->get(Initialization\Helper::class);
110+
}
111+
return $this->initializationHelper;
112+
}
95113
}

0 commit comments

Comments
 (0)