Skip to content

Commit 6890656

Browse files
committed
Merge remote-tracking branch 'origin/2.2-develop' into MC-15671
2 parents fdc64fd + c52ee4a commit 6890656

File tree

137 files changed

+3678
-1282
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

+3678
-1282
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Massaction/AbstractMassaction.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,23 @@ public function getGridIdsJson()
281281
if (!$this->getUseSelectAll()) {
282282
return '';
283283
}
284-
/** @var \Magento\Framework\Data\Collection $allIdsCollection */
285-
$allIdsCollection = clone $this->getParentBlock()->getCollection();
286284

287-
if ($this->getMassactionIdField()) {
288-
$massActionIdField = $this->getMassactionIdField();
285+
/** @var \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection $collection */
286+
$collection = clone $this->getParentBlock()->getCollection();
287+
288+
if ($collection instanceof AbstractDb) {
289+
$idsSelect = clone $collection->getSelect();
290+
$idsSelect->reset(\Magento\Framework\DB\Select::ORDER);
291+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_COUNT);
292+
$idsSelect->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET);
293+
$idsSelect->reset(\Magento\Framework\DB\Select::COLUMNS);
294+
$idsSelect->columns($this->getMassactionIdField(), 'main_table');
295+
$idList = $collection->getConnection()->fetchCol($idsSelect);
289296
} else {
290-
$massActionIdField = $this->getParentBlock()->getMassactionIdField();
297+
$idList = $collection->setPageSize(0)->getColumnValues($this->getMassactionIdField());
291298
}
292-
if ($allIdsCollection instanceof AbstractDb) {
293-
$allIdsCollection->getSelect()->limit();
294-
$allIdsCollection->clear();
295-
}
296-
297-
$gridIds = $allIdsCollection->setPageSize(0)->getColumnValues($massActionIdField);
298-
if (!empty($gridIds)) {
299-
return join(",", $gridIds);
300-
}
301-
return '';
299+
300+
return implode(',', $idList);
302301
}
303302

304303
/**

app/code/Magento/Backend/Test/Mftf/Section/AdminPopupModalSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<section name="AdminPopupModalSection">
1111
<element name="message" type="text" selector="aside.modal-popup .modal-content .popup-window-content"/>
1212
<element name="ok" type="button" selector="//span[contains(text(),'Ok')]/ancestor::button"/>
13+
<element name="confirm" type="button" selector="//aside[contains(@class, 'modal-popup')]//footer/button[normalize-space(.)='Confirm']" timeout="30"/>
1314
</section>
1415
</sections>

app/code/Magento/Backend/Test/Unit/Block/Widget/Grid/MassactionTest.php

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -269,62 +269,6 @@ public function testGetGridIdsJsonWithoutUseSelectAll()
269269
$this->assertEmpty($this->_block->getGridIdsJson());
270270
}
271271

272-
/**
273-
* @param array $items
274-
* @param string $result
275-
*
276-
* @dataProvider dataProviderGetGridIdsJsonWithUseSelectAll
277-
*/
278-
public function testGetGridIdsJsonWithUseSelectAll(array $items, $result)
279-
{
280-
$this->_block->setUseSelectAll(true);
281-
282-
if ($this->_block->getMassactionIdField()) {
283-
$massActionIdField = $this->_block->getMassactionIdField();
284-
} else {
285-
$massActionIdField = $this->_block->getParentBlock()->getMassactionIdField();
286-
}
287-
288-
$collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection::class)
289-
->disableOriginalConstructor()
290-
->getMock();
291-
292-
$this->_gridMock->expects($this->once())
293-
->method('getCollection')
294-
->willReturn($collectionMock);
295-
$collectionMock->expects($this->once())
296-
->method('setPageSize')
297-
->with(0)
298-
->willReturnSelf();
299-
$collectionMock->expects($this->once())
300-
->method('getColumnValues')
301-
->with($massActionIdField)
302-
->willReturn($items);
303-
304-
$this->assertEquals($result, $this->_block->getGridIdsJson());
305-
}
306-
307-
/**
308-
* @return array
309-
*/
310-
public function dataProviderGetGridIdsJsonWithUseSelectAll()
311-
{
312-
return [
313-
[
314-
[],
315-
'',
316-
],
317-
[
318-
[1],
319-
'1',
320-
],
321-
[
322-
[1, 2, 3],
323-
'1,2,3',
324-
],
325-
];
326-
}
327-
328272
/**
329273
* @param string $itemId
330274
* @param array|\Magento\Framework\DataObject $item

app/code/Magento/Braintree/Controller/Paypal/Review.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Braintree\Gateway\Config\PayPal\Config;
1212
use Magento\Braintree\Model\Paypal\Helper\QuoteUpdater;
1313
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Payment\Model\Method\Logger;
1415

1516
/**
1617
* Class Review
@@ -22,6 +23,11 @@ class Review extends AbstractAction
2223
*/
2324
private $quoteUpdater;
2425

26+
/**
27+
* @var Logger
28+
*/
29+
private $logger;
30+
2531
/**
2632
* @var string
2733
*/
@@ -34,15 +40,18 @@ class Review extends AbstractAction
3440
* @param Config $config
3541
* @param Session $checkoutSession
3642
* @param QuoteUpdater $quoteUpdater
43+
* @param Logger $logger
3744
*/
3845
public function __construct(
3946
Context $context,
4047
Config $config,
4148
Session $checkoutSession,
42-
QuoteUpdater $quoteUpdater
49+
QuoteUpdater $quoteUpdater,
50+
Logger $logger
4351
) {
4452
parent::__construct($context, $config, $checkoutSession);
4553
$this->quoteUpdater = $quoteUpdater;
54+
$this->logger = $logger;
4655
}
4756

4857
/**
@@ -54,6 +63,7 @@ public function execute()
5463
$this->getRequest()->getPostValue('result', '{}'),
5564
true
5665
);
66+
$this->logger->debug($requestData);
5767
$quote = $this->checkoutSession->getQuote();
5868

5969
try {
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
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\Braintree\Model\Multishipping;
9+
10+
use Magento\Braintree\Gateway\Command\GetPaymentNonceCommand;
11+
use Magento\Braintree\Model\Ui\ConfigProvider;
12+
use Magento\Braintree\Observer\DataAssignObserver;
13+
use Magento\Braintree\Model\Ui\PayPal\ConfigProvider as PaypalConfigProvider;
14+
use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderInterface;
15+
use Magento\Sales\Api\Data\OrderInterface;
16+
use Magento\Sales\Api\Data\OrderPaymentExtensionInterface;
17+
use Magento\Sales\Api\Data\OrderPaymentExtensionInterfaceFactory;
18+
use Magento\Sales\Api\Data\OrderPaymentInterface;
19+
use Magento\Sales\Api\OrderManagementInterface;
20+
use Magento\Vault\Api\Data\PaymentTokenInterface;
21+
22+
/**
23+
* Order payments processing for multishipping checkout flow.
24+
*
25+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
*/
27+
class PlaceOrder implements PlaceOrderInterface
28+
{
29+
/**
30+
* @var OrderManagementInterface
31+
*/
32+
private $orderManagement;
33+
34+
/**
35+
* @var OrderPaymentExtensionInterfaceFactory
36+
*/
37+
private $paymentExtensionFactory;
38+
39+
/**
40+
* @var GetPaymentNonceCommand
41+
*/
42+
private $getPaymentNonceCommand;
43+
44+
/**
45+
* @param OrderManagementInterface $orderManagement
46+
* @param OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory
47+
* @param GetPaymentNonceCommand $getPaymentNonceCommand
48+
*/
49+
public function __construct(
50+
OrderManagementInterface $orderManagement,
51+
OrderPaymentExtensionInterfaceFactory $paymentExtensionFactory,
52+
GetPaymentNonceCommand $getPaymentNonceCommand
53+
) {
54+
$this->orderManagement = $orderManagement;
55+
$this->paymentExtensionFactory = $paymentExtensionFactory;
56+
$this->getPaymentNonceCommand = $getPaymentNonceCommand;
57+
}
58+
59+
/**
60+
* @inheritdoc
61+
*/
62+
public function place(array $orderList): array
63+
{
64+
if (empty($orderList)) {
65+
return [];
66+
}
67+
68+
$errorList = [];
69+
$firstOrder = $this->orderManagement->place(array_shift($orderList));
70+
// get payment token from first placed order
71+
$paymentToken = $this->getPaymentToken($firstOrder);
72+
73+
foreach ($orderList as $order) {
74+
try {
75+
/** @var OrderInterface $order */
76+
$orderPayment = $order->getPayment();
77+
$this->setVaultPayment($orderPayment, $paymentToken);
78+
$this->orderManagement->place($order);
79+
} catch (\Exception $e) {
80+
$incrementId = $order->getIncrementId();
81+
$errorList[$incrementId] = $e;
82+
}
83+
}
84+
85+
return $errorList;
86+
}
87+
88+
/**
89+
* Sets vault payment method.
90+
*
91+
* @param OrderPaymentInterface $orderPayment
92+
* @param PaymentTokenInterface $paymentToken
93+
* @return void
94+
*/
95+
private function setVaultPayment(OrderPaymentInterface $orderPayment, PaymentTokenInterface $paymentToken)
96+
{
97+
$vaultMethod = $this->getVaultPaymentMethod(
98+
$orderPayment->getMethod()
99+
);
100+
$orderPayment->setMethod($vaultMethod);
101+
102+
$publicHash = $paymentToken->getPublicHash();
103+
$customerId = $paymentToken->getCustomerId();
104+
$result = $this->getPaymentNonceCommand->execute(
105+
['public_hash' => $publicHash, 'customer_id' => $customerId]
106+
)
107+
->get();
108+
109+
$orderPayment->setAdditionalInformation(
110+
DataAssignObserver::PAYMENT_METHOD_NONCE,
111+
$result['paymentMethodNonce']
112+
);
113+
$orderPayment->setAdditionalInformation(
114+
PaymentTokenInterface::PUBLIC_HASH,
115+
$publicHash
116+
);
117+
$orderPayment->setAdditionalInformation(
118+
PaymentTokenInterface::CUSTOMER_ID,
119+
$customerId
120+
);
121+
}
122+
123+
/**
124+
* Returns vault payment method.
125+
*
126+
* For placing sequence of orders, we need to replace the original method on the vault method.
127+
*
128+
* @param string $method
129+
* @return string
130+
*/
131+
private function getVaultPaymentMethod(string $method): string
132+
{
133+
$vaultPaymentMap = [
134+
ConfigProvider::CODE => ConfigProvider::CC_VAULT_CODE,
135+
PaypalConfigProvider::PAYPAL_CODE => PaypalConfigProvider::PAYPAL_VAULT_CODE
136+
];
137+
138+
return $vaultPaymentMap[$method] ?? $method;
139+
}
140+
141+
/**
142+
* Returns payment token.
143+
*
144+
* @param OrderInterface $order
145+
* @return PaymentTokenInterface
146+
* @throws \BadMethodCallException
147+
*/
148+
private function getPaymentToken(OrderInterface $order): PaymentTokenInterface
149+
{
150+
$orderPayment = $order->getPayment();
151+
$extensionAttributes = $this->getExtensionAttributes($orderPayment);
152+
$paymentToken = $extensionAttributes->getVaultPaymentToken();
153+
154+
if ($paymentToken === null) {
155+
throw new \BadMethodCallException('Vault Payment Token should be defined for placed order payment.');
156+
}
157+
158+
return $paymentToken;
159+
}
160+
161+
/**
162+
* Gets payment extension attributes.
163+
*
164+
* @param OrderPaymentInterface $payment
165+
* @return OrderPaymentExtensionInterface
166+
*/
167+
private function getExtensionAttributes(OrderPaymentInterface $payment): OrderPaymentExtensionInterface
168+
{
169+
$extensionAttributes = $payment->getExtensionAttributes();
170+
if (null === $extensionAttributes) {
171+
$extensionAttributes = $this->paymentExtensionFactory->create();
172+
$payment->setExtensionAttributes($extensionAttributes);
173+
}
174+
175+
return $extensionAttributes;
176+
}
177+
}

app/code/Magento/Braintree/Model/Paypal/Helper/QuoteUpdater.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ private function updateShippingAddress(Quote $quote, array $details)
123123
{
124124
$shippingAddress = $quote->getShippingAddress();
125125

126-
$shippingAddress->setLastname($details['lastName']);
127-
$shippingAddress->setFirstname($details['firstName']);
126+
$shippingAddress->setLastname($this->getShippingRecipientLastName($details));
127+
$shippingAddress->setFirstname($this->getShippingRecipientFirstName($details));
128128
$shippingAddress->setEmail($details['email']);
129129

130130
$shippingAddress->setCollectShippingRates(true);
@@ -188,4 +188,30 @@ private function updateAddressData(Address $address, array $addressData)
188188
$address->setSameAsBilling(false);
189189
$address->setCustomerAddressId(null);
190190
}
191+
192+
/**
193+
* Returns shipping recipient first name.
194+
*
195+
* @param array $details
196+
* @return string
197+
*/
198+
private function getShippingRecipientFirstName(array $details)
199+
{
200+
return isset($details['shippingAddress']['recipientName'])
201+
? explode(' ', $details['shippingAddress']['recipientName'], 2)[0]
202+
: $details['firstName'];
203+
}
204+
205+
/**
206+
* Returns shipping recipient last name.
207+
*
208+
* @param array $details
209+
* @return string
210+
*/
211+
private function getShippingRecipientLastName(array $details)
212+
{
213+
return isset($details['shippingAddress']['recipientName'])
214+
? explode(' ', $details['shippingAddress']['recipientName'], 2)[1]
215+
: $details['lastName'];
216+
}
191217
}

0 commit comments

Comments
 (0)