Skip to content

Commit 527d222

Browse files
committed
Merge remote-tracking branch 'origin/MC-19105' into 2.3-develop-pr30
2 parents 4c37ed6 + a83e819 commit 527d222

File tree

4 files changed

+228
-6
lines changed

4 files changed

+228
-6
lines changed

app/code/Magento/Multishipping/Model/Checkout/Type/Multishipping.php

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @SuppressWarnings(PHPMD.TooManyFields)
2424
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2525
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
2627
* @since 100.0.2
2728
*/
2829
class Multishipping extends \Magento\Framework\DataObject
@@ -526,6 +527,7 @@ protected function _addShippingItem($quoteItemId, $data)
526527
$quoteItem->setQty($quoteItem->getMultishippingQty());
527528
try {
528529
$address = $this->addressRepository->getById($addressId);
530+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
529531
} catch (\Exception $e) {
530532
}
531533
if (isset($address)) {
@@ -565,6 +567,7 @@ public function updateQuoteCustomerShippingAddress($addressId)
565567
}
566568
try {
567569
$address = $this->addressRepository->getById($addressId);
570+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
568571
} catch (\Exception $e) {
569572
//
570573
}
@@ -592,6 +595,7 @@ public function setQuoteCustomerBillingAddress($addressId)
592595
}
593596
try {
594597
$address = $this->addressRepository->getById($addressId);
598+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
595599
} catch (\Exception $e) {
596600
//
597601
}
@@ -716,7 +720,7 @@ protected function _prepareOrder(\Magento\Quote\Model\Quote\Address $address)
716720
);
717721
$orderItem = $this->quoteItemToOrderItem->convert($item);
718722
if ($item->getParentItem()) {
719-
$orderItem->setParentItem($order->getItemByQuoteItemId($item->getParentItem()->getId()));
723+
$orderItem->setParentItem($order->getItemByQuoteItemId($_quoteItem->getParentItem()->getId()));
720724
}
721725
$order->addItem($orderItem);
722726
}
@@ -825,7 +829,7 @@ public function createOrders()
825829
if ($order->getCanSendNewEmailFlag()) {
826830
$this->orderSender->send($order);
827831
}
828-
$placedAddressItems = array_merge($placedAddressItems, $this->getQuoteAddressItems($order));
832+
$placedAddressItems = $this->getPlacedAddressItems($order);
829833
}
830834

831835
$addressErrors = [];
@@ -1090,10 +1094,14 @@ public function getCustomer()
10901094
*/
10911095
protected function isAddressIdApplicable($addressId)
10921096
{
1093-
$applicableAddressIds = array_map(function ($address) {
1094-
/** @var \Magento\Customer\Api\Data\AddressInterface $address */
1095-
return $address->getId();
1096-
}, $this->getCustomer()->getAddresses());
1097+
$applicableAddressIds = array_map(
1098+
function ($address) {
1099+
/** @var \Magento\Customer\Api\Data\AddressInterface $address */
1100+
return $address->getId();
1101+
},
1102+
$this->getCustomer()->getAddresses()
1103+
);
1104+
10971105
return !is_numeric($addressId) || in_array($addressId, $applicableAddressIds);
10981106
}
10991107

@@ -1279,4 +1287,20 @@ private function getQuoteAddressItems(OrderInterface $order): array
12791287

12801288
return $placedAddressItems;
12811289
}
1290+
1291+
/**
1292+
* Returns placed address items
1293+
*
1294+
* @param OrderInterface $order
1295+
* @return array
1296+
*/
1297+
private function getPlacedAddressItems(OrderInterface $order): array
1298+
{
1299+
$placedAddressItems = [];
1300+
foreach ($this->getQuoteAddressItems($order) as $key => $quoteAddressItem) {
1301+
$placedAddressItems[$key] = $quoteAddressItem;
1302+
}
1303+
1304+
return $placedAddressItems;
1305+
}
12821306
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
use Magento\Checkout\Model\Session;
9+
use Magento\Eav\Model\Config;
10+
use Magento\Framework\DataObject;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\Quote\Api\Data\AddressInterface;
13+
use Magento\Quote\Api\Data\PaymentInterface;
14+
use Magento\Quote\Model\Quote;
15+
use Magento\Quote\Model\Quote\Address\Rate;
16+
use Magento\TestFramework\Helper\Bootstrap;
17+
use Magento\TestFramework\ObjectManager;
18+
19+
require __DIR__ . '/../../ConfigurableProduct/_files/configurable_products.php';
20+
21+
/** @var ObjectManager $objectManager */
22+
$objectManager = Bootstrap::getObjectManager();
23+
24+
$product = $productRepository->getById(10);
25+
$product->setStockData(['use_config_manage_stock' => 1, 'qty' => 2, 'is_qty_decimal' => 0, 'is_in_stock' => 1]);
26+
$productRepository->save($product);
27+
28+
/** @var Quote $quote */
29+
$quote = $objectManager->create(Quote::class);
30+
$request = $objectManager->create(DataObject::class);
31+
32+
/** @var Config $eavConfig */
33+
$eavConfig = $objectManager->get(Config::class);
34+
/** @var $attribute */
35+
$attribute = $eavConfig->getAttribute('catalog_product', 'test_configurable');
36+
37+
$request->setData(
38+
[
39+
'product_id' => $productRepository->get('configurable')->getId(),
40+
'selected_configurable_option' => '1',
41+
'super_attribute' => [
42+
$attribute->getAttributeId() => $attribute->getOptions()[1]->getValue()
43+
],
44+
'qty' => '2'
45+
]
46+
);
47+
48+
$quote->setStoreId(1)
49+
->setIsActive(
50+
true
51+
)->setIsMultiShipping(
52+
1
53+
)->setReservedOrderId(
54+
'test_order_with_configurable_product'
55+
)->setCustomerEmail(
56+
'store@example.com'
57+
)->addProduct(
58+
$productRepository->get('configurable'),
59+
$request
60+
);
61+
62+
/** @var PaymentInterface $payment */
63+
$payment = $objectManager->create(PaymentInterface::class);
64+
$payment->setMethod('checkmo');
65+
$quote->setPayment($payment);
66+
67+
$addressList = [
68+
[
69+
'firstname' => 'Jonh',
70+
'lastname' => 'Doe',
71+
'telephone' => '0333-233-221',
72+
'street' => ['Main Division 1'],
73+
'city' => 'Culver City',
74+
'region' => 'CA',
75+
'postcode' => 90800,
76+
'country_id' => 'US',
77+
'email' => 'store@example.com',
78+
'address_type' => 'shipping',
79+
],
80+
[
81+
'firstname' => 'Antoni',
82+
'lastname' => 'Holmes',
83+
'telephone' => '0333-233-221',
84+
'street' => ['Second Division 2'],
85+
'city' => 'Denver',
86+
'region' => 'CO',
87+
'postcode' => 80203,
88+
'country_id' => 'US',
89+
'email' => 'customer002@shipping.test',
90+
'address_type' => 'shipping'
91+
],
92+
];
93+
94+
$methodCode = 'flatrate_flatrate';
95+
foreach ($addressList as $data) {
96+
/** @var Rate $rate */
97+
$rate = $objectManager->create(Rate::class);
98+
$rate->setCode($methodCode)
99+
->setPrice(5.00);
100+
101+
$address = $objectManager->create(AddressInterface::class, ['data' => $data]);
102+
$address->setShippingMethod($methodCode)
103+
->addShippingRate($rate)
104+
->setShippingAmount(5.00)
105+
->setBaseShippingAmount(5.00);
106+
107+
$quote->addAddress($address);
108+
}
109+
110+
/** @var CartRepositoryInterface $quoteRepository */
111+
$quoteRepository = $objectManager->get(CartRepositoryInterface::class);
112+
$quoteRepository->save($quote);
113+
114+
$items = $quote->getAllItems();
115+
116+
foreach ($quote->getAllShippingAddresses() as $address) {
117+
foreach ($items as $item) {
118+
$item->setQty(1);
119+
$address->setTotalQty(1);
120+
$address->addItem($item);
121+
};
122+
}
123+
124+
$billingAddressData = [
125+
'firstname' => 'Jonh',
126+
'lastname' => 'Doe',
127+
'telephone' => '0333-233-221',
128+
'street' => ['Third Division 1'],
129+
'city' => 'New York',
130+
'region' => 'NY',
131+
'postcode' => 10029,
132+
'country_id' => 'US',
133+
'email' => 'store@example.com',
134+
'address_type' => 'billing',
135+
];
136+
137+
/** @var AddressInterface $address */
138+
$billingAddress = $objectManager->create(AddressInterface::class, ['data' => $billingAddressData]);
139+
$quote->setBillingAddress($billingAddress);
140+
$quote->collectTotals();
141+
$quoteRepository->save($quote);
142+
143+
/** @var Session $session */
144+
$session = $objectManager->get(Session::class);
145+
$session->setQuoteId($quote->getId());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Rollback for quote_with_configurable_product_last_variation.php fixture.
4+
*
5+
* Copyright © Magento, Inc. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
declare(strict_types=1);
9+
10+
use Magento\Quote\Model\Quote;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use Magento\TestFramework\ObjectManager;
13+
14+
/** @var $objectManager ObjectManager */
15+
$objectManager = Bootstrap::getObjectManager();
16+
$quote = $objectManager->create(Quote::class);
17+
$quote->load('test_order_with_configurable_product', 'reserved_order_id')->delete();

dev/tests/integration/testsuite/Magento/Multishipping/Model/Checkout/Type/MultishippingTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,42 @@ public function testCreateOrdersWithSomeFailedOrders()
361361
);
362362
}
363363

364+
/**
365+
* Check product parent item id in order item
366+
*
367+
* @magentoDataFixture Magento/Multishipping/Fixtures/quote_with_configurable_product.php
368+
*/
369+
public function testCreateOrdersWithConfigurableProduct()
370+
{
371+
$quote = $this->getQuote('test_order_with_configurable_product');
372+
/** @var CheckoutSession $session */
373+
$session = $this->objectManager->get(CheckoutSession::class);
374+
$session->replaceQuote($quote);
375+
376+
$this->model->createOrders();
377+
378+
$quoteItemParentIds = [];
379+
foreach ($quote->getAllItems() as $quoteItem) {
380+
$quoteItemParentIds[] = $quoteItem->getParentItemId();
381+
}
382+
383+
$orderList = $this->getOrderList((int)$quote->getId());
384+
$firstOrder = array_shift($orderList);
385+
$secondOrder = array_shift($orderList);
386+
387+
$firstOrderItemParentsIds = [];
388+
foreach ($firstOrder->getItems() as $orderItem) {
389+
$firstOrderItemParentsIds[] = $orderItem->getParentItemId();
390+
}
391+
$secondOrderItemParentsIds = [];
392+
foreach ($secondOrder->getItems() as $orderItem) {
393+
$secondOrderItemParentsIds[] = $orderItem->getParentItemId();
394+
}
395+
396+
$this->assertNotNull($firstOrderItemParentsIds[1]);
397+
$this->assertNotNull($secondOrderItemParentsIds[1]);
398+
}
399+
364400
/**
365401
* Returns order service mock with successful place on first call and exceptions on other calls.
366402
*

0 commit comments

Comments
 (0)