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

Commit e9c1946

Browse files
authored
Merge pull request #3325 from magento-tsg-csl3/2.2-develop-pr6
[TSG-CSL3] Backporting 2.2 (pr6)
2 parents 8fd8aca + d418636 commit e9c1946

File tree

20 files changed

+515
-37
lines changed

20 files changed

+515
-37
lines changed

app/code/Magento/Braintree/Gateway/Request/PayPal/VaultDataBuilder.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ public function build(array $buildSubject)
4949

5050
$payment = $paymentDO->getPayment();
5151
$data = $payment->getAdditionalInformation();
52+
// the payment token could be stored only if a customer checks the Vault flow on storefront
53+
// see https://developers.braintreepayments.com/guides/paypal/vault/javascript/v2#invoking-the-vault-flow
5254
if (!empty($data[VaultConfigProvider::IS_ACTIVE_CODE])) {
5355
$result[self::$optionsKey] = [
5456
self::$storeInVaultOnSuccess => true

app/code/Magento/Braintree/Gateway/Request/VaultCaptureDataBuilder.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Braintree\Gateway\Request;
77

88
use Magento\Braintree\Gateway\SubjectReader;
9+
use Magento\Payment\Gateway\Command\CommandException;
910
use Magento\Payment\Gateway\Request\BuilderInterface;
1011
use Magento\Payment\Helper\Formatter;
1112

@@ -41,6 +42,9 @@ public function build(array $buildSubject)
4142
$payment = $paymentDO->getPayment();
4243
$extensionAttributes = $payment->getExtensionAttributes();
4344
$paymentToken = $extensionAttributes->getVaultPaymentToken();
45+
if ($paymentToken === null) {
46+
throw new CommandException(__('The Payment Token is not available to perform the request.'));
47+
}
4448
return [
4549
'amount' => $this->formatPrice($this->subjectReader->readAmount($buildSubject)),
4650
'paymentMethodToken' => $paymentToken->getGatewayToken()

app/code/Magento/Braintree/Test/Unit/Gateway/Request/VaultCaptureDataBuilderTest.php

Lines changed: 66 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,20 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Braintree\Test\Unit\Gateway\Request;
78

8-
use Magento\Braintree\Gateway\SubjectReader;
99
use Magento\Braintree\Gateway\Request\VaultCaptureDataBuilder;
10+
use Magento\Braintree\Gateway\SubjectReader;
1011
use Magento\Payment\Gateway\Data\PaymentDataObjectInterface;
1112
use Magento\Sales\Api\Data\OrderPaymentExtension;
1213
use Magento\Sales\Model\Order\Payment;
1314
use Magento\Vault\Model\PaymentToken;
1415
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1516

17+
/**
18+
* Tests VaultCaptureDataBuilder.
19+
*/
1620
class VaultCaptureDataBuilderTest extends \PHPUnit\Framework\TestCase
1721
{
1822
/**
@@ -30,7 +34,15 @@ class VaultCaptureDataBuilderTest extends \PHPUnit\Framework\TestCase
3034
*/
3135
private $payment;
3236

33-
public function setUp()
37+
/**
38+
* @var SubjectReader|MockObject
39+
*/
40+
private $subjectReader;
41+
42+
/**
43+
* @inheritdoc
44+
*/
45+
protected function setUp()
3446
{
3547
$this->paymentDO = $this->createMock(PaymentDataObjectInterface::class);
3648
$this->payment = $this->getMockBuilder(Payment::class)
@@ -39,31 +51,44 @@ public function setUp()
3951
$this->paymentDO->method('getPayment')
4052
->willReturn($this->payment);
4153

42-
$this->builder = new VaultCaptureDataBuilder(new SubjectReader());
54+
$this->subjectReader = $this->getMockBuilder(SubjectReader::class)
55+
->disableOriginalConstructor()
56+
->getMock();
57+
58+
$this->builder = new VaultCaptureDataBuilder($this->subjectReader);
4359
}
4460

4561
/**
46-
* \Magento\Braintree\Gateway\Request\VaultCaptureDataBuilder::build
62+
* Checks the result after builder execution.
4763
*/
4864
public function testBuild()
4965
{
5066
$amount = 30.00;
5167
$token = '5tfm4c';
5268
$buildSubject = [
5369
'payment' => $this->paymentDO,
54-
'amount' => $amount
70+
'amount' => $amount,
5571
];
5672

5773
$expected = [
5874
'amount' => $amount,
59-
'paymentMethodToken' => $token
75+
'paymentMethodToken' => $token,
6076
];
6177

78+
$this->subjectReader->method('readPayment')
79+
->with($buildSubject)
80+
->willReturn($this->paymentDO);
81+
$this->subjectReader->method('readAmount')
82+
->with($buildSubject)
83+
->willReturn($amount);
84+
85+
/** @var OrderPaymentExtension|MockObject $paymentExtension */
6286
$paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)
6387
->setMethods(['getVaultPaymentToken'])
6488
->disableOriginalConstructor()
6589
->getMockForAbstractClass();
6690

91+
/** @var PaymentToken|MockObject $paymentToken */
6792
$paymentToken = $this->getMockBuilder(PaymentToken::class)
6893
->disableOriginalConstructor()
6994
->getMock();
@@ -79,4 +104,39 @@ public function testBuild()
79104
$result = $this->builder->build($buildSubject);
80105
self::assertEquals($expected, $result);
81106
}
107+
108+
/**
109+
* Checks a builder execution if Payment Token doesn't exist.
110+
*
111+
* @expectedException \Magento\Payment\Gateway\Command\CommandException
112+
* @expectedExceptionMessage The Payment Token is not available to perform the request.
113+
*/
114+
public function testBuildWithoutPaymentToken(): void
115+
{
116+
$amount = 30.00;
117+
$buildSubject = [
118+
'payment' => $this->paymentDO,
119+
'amount' => $amount,
120+
];
121+
122+
$this->subjectReader->method('readPayment')
123+
->with($buildSubject)
124+
->willReturn($this->paymentDO);
125+
$this->subjectReader->method('readAmount')
126+
->with($buildSubject)
127+
->willReturn($amount);
128+
129+
/** @var OrderPaymentExtension|MockObject $paymentExtension */
130+
$paymentExtension = $this->getMockBuilder(OrderPaymentExtension::class)
131+
->setMethods(['getVaultPaymentToken'])
132+
->disableOriginalConstructor()
133+
->getMockForAbstractClass();
134+
135+
$this->payment->method('getExtensionAttributes')
136+
->willReturn($paymentExtension);
137+
$paymentExtension->method('getVaultPaymentToken')
138+
->willReturn(null);
139+
140+
$this->builder->build($buildSubject);
141+
}
82142
}

app/code/Magento/Braintree/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,3 +192,4 @@ Currency,Currency
192192
"Too many concurrent attempts to refund this transaction. Try again later.","Too many concurrent attempts to refund this transaction. Try again later."
193193
"Too many concurrent attempts to void this transaction. Try again later.","Too many concurrent attempts to void this transaction. Try again later."
194194
"Braintree Settlement","Braintree Settlement"
195+
"The Payment Token is not available to perform the request.","The Payment Token is not available to perform the request."

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,14 @@ protected function _saveProducts()
15741574
$rowScope = $this->getRowScope($rowData);
15751575

15761576
$urlKey = $this->getUrlKey($rowData);
1577-
if (!empty($urlKey)) {
1577+
if (!empty($rowData[self::URL_KEY])) {
1578+
// If url_key column and its value were in the CSV file
15781579
$rowData[self::URL_KEY] = $urlKey;
1580+
} else if ($this->isNeedToChangeUrlKey($rowData)) {
1581+
// If url_key column was empty or even not declared in the CSV file but by the rules it is need to
1582+
// be setteed. In case when url_key is generating from name column we have to ensure that the bunch
1583+
// of products will pass for the event with url_key column.
1584+
$bunch[$rowNum][self::URL_KEY] = $rowData[self::URL_KEY] = $urlKey;
15791585
}
15801586

15811587
$rowSku = $rowData[self::COL_SKU];
@@ -2475,17 +2481,17 @@ public function validateRow(array $rowData, $rowNum)
24752481
}
24762482

24772483
/**
2484+
* Check if need to validate url key.
2485+
*
24782486
* @param array $rowData
24792487
* @return bool
24802488
*/
24812489
private function isNeedToValidateUrlKey($rowData)
24822490
{
2483-
$urlKey = $this->getUrlKey($rowData);
2484-
2485-
return (!empty($urlKey))
2491+
return (!empty($rowData[self::URL_KEY]) || !empty($rowData[self::COL_NAME]))
24862492
&& (empty($rowData[self::COL_VISIBILITY])
2487-
|| $rowData[self::COL_VISIBILITY]
2488-
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
2493+
|| $rowData[self::COL_VISIBILITY]
2494+
!== (string)Visibility::getOptionArray()[Visibility::VISIBILITY_NOT_VISIBLE]);
24892495
}
24902496

24912497
/**
@@ -2785,23 +2791,20 @@ protected function getProductUrlSuffix($storeId = null)
27852791
}
27862792

27872793
/**
2794+
* Retrieve url key from provided row data.
2795+
*
27882796
* @param array $rowData
27892797
* @return string
2798+
*
27902799
* @since 100.0.3
27912800
*/
27922801
protected function getUrlKey($rowData)
27932802
{
27942803
if (!empty($rowData[self::URL_KEY])) {
27952804
return $this->productUrl->formatUrlKey($rowData[self::URL_KEY]);
27962805
}
2797-
2798-
/**
2799-
* If the product exists, assume it already has a URL Key and even
2800-
* if a name is provided in the import data, it should not be used
2801-
* to overwrite that existing URL Key the product already has.
2802-
*/
2803-
$isSkuExist = $this->isSkuExist($rowData[self::COL_SKU]);
2804-
if (!$isSkuExist && !empty($rowData[self::COL_NAME])) {
2806+
2807+
if (!empty($rowData[self::COL_NAME])) {
28052808
return $this->productUrl->formatUrlKey($rowData[self::COL_NAME]);
28062809
}
28072810

@@ -2820,6 +2823,26 @@ protected function getResource()
28202823
return $this->_resource;
28212824
}
28222825

2826+
/**
2827+
* Whether a url key is needed to be change.
2828+
*
2829+
* @param array $rowData
2830+
* @return bool
2831+
*/
2832+
private function isNeedToChangeUrlKey(array $rowData): bool
2833+
{
2834+
$urlKey = $this->getUrlKey($rowData);
2835+
$productExists = $this->isSkuExist($rowData[self::COL_SKU]);
2836+
$markedToEraseUrlKey = isset($rowData[self::URL_KEY]);
2837+
// The product isn't new and the url key index wasn't marked for change.
2838+
if (!$urlKey && $productExists && !$markedToEraseUrlKey) {
2839+
// Seems there is no need to change the url key
2840+
return false;
2841+
}
2842+
2843+
return true;
2844+
}
2845+
28232846
/**
28242847
* Get product entity link field
28252848
*

app/code/Magento/Sales/Model/AdminOrder/Create.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Quote\Model\Quote\Item;
1717
use Magento\Sales\Api\Data\OrderAddressInterface;
1818
use Magento\Sales\Model\Order;
19+
use Magento\Store\Model\StoreManagerInterface;
1920

2021
/**
2122
* Order create model
@@ -243,6 +244,11 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
243244
*/
244245
private $dataObjectConverter;
245246

247+
/**
248+
* @var StoreManagerInterface
249+
*/
250+
private $storeManager;
251+
246252
/**
247253
* @param \Magento\Framework\ObjectManagerInterface $objectManager
248254
* @param \Magento\Framework\Event\ManagerInterface $eventManager
@@ -274,6 +280,7 @@ class Create extends \Magento\Framework\DataObject implements \Magento\Checkout\
274280
* @param array $data
275281
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
276282
* @param ExtensibleDataObjectConverter|null $dataObjectConverter
283+
* @param StoreManagerInterface $storeManager
277284
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
278285
*/
279286
public function __construct(
@@ -306,7 +313,8 @@ public function __construct(
306313
\Magento\Quote\Model\QuoteFactory $quoteFactory,
307314
array $data = [],
308315
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
309-
ExtensibleDataObjectConverter $dataObjectConverter = null
316+
ExtensibleDataObjectConverter $dataObjectConverter = null,
317+
StoreManagerInterface $storeManager = null
310318
) {
311319
$this->_objectManager = $objectManager;
312320
$this->_eventManager = $eventManager;
@@ -340,6 +348,7 @@ public function __construct(
340348
parent::__construct($data);
341349
$this->dataObjectConverter = $dataObjectConverter ?: ObjectManager::getInstance()
342350
->get(ExtensibleDataObjectConverter::class);
351+
$this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManagerInterface::class);
343352
}
344353

345354
/**
@@ -417,7 +426,8 @@ public function setRecollect($flag)
417426

418427
/**
419428
* Recollect totals for customer cart.
420-
* Set recollect totals flag for quote
429+
*
430+
* Set recollect totals flag for quote.
421431
*
422432
* @return $this
423433
*/
@@ -1327,6 +1337,7 @@ protected function _createCustomerForm(\Magento\Customer\Api\Data\CustomerInterf
13271337

13281338
/**
13291339
* Set and validate Quote address
1340+
*
13301341
* All errors added to _errors
13311342
*
13321343
* @param \Magento\Quote\Model\Quote\Address $address
@@ -1530,6 +1541,8 @@ public function resetShippingMethod()
15301541
*/
15311542
public function collectShippingRates()
15321543
{
1544+
$store = $this->getQuote()->getStore();
1545+
$this->storeManager->setCurrentStore($store);
15331546
$this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
15341547
$this->collectRates();
15351548

app/code/Magento/Sales/Model/ResourceModel/Order/Grid/Collection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,19 @@ public function __construct(
3535
) {
3636
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $mainTable, $resourceModel);
3737
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
protected function _initSelect()
43+
{
44+
parent::_initSelect();
45+
46+
$tableDescription = $this->getConnection()->describeTable($this->getMainTable());
47+
foreach ($tableDescription as $columnInfo) {
48+
$this->addFilterToMap($columnInfo['COLUMN_NAME'], 'main_table.' . $columnInfo['COLUMN_NAME']);
49+
}
50+
51+
return $this;
52+
}
3853
}

0 commit comments

Comments
 (0)