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

Commit f4d0420

Browse files
committed
Merge remote-tracking branch 'upstream/2.3.0-release' into 2.3.0-release-sync2
2 parents 96498d0 + 8f5c010 commit f4d0420

File tree

7 files changed

+243
-17
lines changed

7 files changed

+243
-17
lines changed

app/code/Magento/Sales/Model/Order/Shipment.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ public function register()
277277
}
278278

279279
/**
280+
* Retrieves the collection used to track the shipment's items
281+
*
280282
* @return mixed
281283
*/
282284
public function getItemsCollection()
@@ -295,6 +297,8 @@ public function getItemsCollection()
295297
}
296298

297299
/**
300+
* Retrieves all non-deleted items from the shipment
301+
*
298302
* @return array
299303
*/
300304
public function getAllItems()
@@ -309,6 +313,8 @@ public function getAllItems()
309313
}
310314

311315
/**
316+
* Retrieves an item from the shipment using its ID
317+
*
312318
* @param string|int $itemId
313319
* @return bool|\Magento\Sales\Model\Order\Shipment\Item
314320
*/
@@ -323,6 +329,8 @@ public function getItemById($itemId)
323329
}
324330

325331
/**
332+
* Adds an item to the shipment
333+
*
326334
* @param \Magento\Sales\Model\Order\Shipment\Item $item
327335
* @return $this
328336
*/
@@ -353,6 +361,8 @@ public function getTracksCollection()
353361
}
354362

355363
/**
364+
* Retrieves all available tracks in the collection that aren't deleted
365+
*
356366
* @return array
357367
*/
358368
public function getAllTracks()
@@ -367,6 +377,8 @@ public function getAllTracks()
367377
}
368378

369379
/**
380+
* Retrieves a track using its ID
381+
*
370382
* @param string|int $trackId
371383
* @return bool|\Magento\Sales\Model\Order\Shipment\Track
372384
*/
@@ -381,6 +393,8 @@ public function getTrackById($trackId)
381393
}
382394

383395
/**
396+
* Addes a track to the collection and associates the shipment to the track
397+
*
384398
* @param \Magento\Sales\Model\Order\Shipment\Track $track
385399
* @return $this
386400
*/
@@ -409,8 +423,7 @@ public function addTrack(\Magento\Sales\Model\Order\Shipment\Track $track)
409423
}
410424

411425
/**
412-
* Adds comment to shipment with additional possibility to send it to customer via email
413-
* and show it in customer account
426+
* Adds comment to shipment with option to send it to customer via email and show it in customer account
414427
*
415428
* @param \Magento\Sales\Model\Order\Shipment\Comment|string $comment
416429
* @param bool $notify
@@ -574,13 +587,10 @@ public function setItems($items)
574587
public function getTracks()
575588
{
576589
if ($this->getData(ShipmentInterface::TRACKS) === null) {
577-
$collection = $this->_trackCollectionFactory->create()->setShipmentFilter($this->getId());
578-
if ($this->getId()) {
579-
foreach ($collection as $item) {
580-
$item->setShipment($this);
581-
}
582-
$this->setData(ShipmentInterface::TRACKS, $collection->getItems());
590+
foreach ($this->getTracksCollection() as $item) {
591+
$item->setShipment($this);
583592
}
593+
$this->setData(ShipmentInterface::TRACKS, $this->getTracksCollection()->getItems());
584594
}
585595
return $this->getData(ShipmentInterface::TRACKS);
586596
}

app/code/Magento/Sales/Model/Service/InvoiceService.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public function setVoid($id)
125125
}
126126

127127
/**
128+
* Creates an invoice based on the order and quantities provided
129+
*
128130
* @param Order $order
129131
* @param array $qtys
130132
* @return \Magento\Sales\Model\Order\Invoice
@@ -136,7 +138,7 @@ public function prepareInvoice(Order $order, array $qtys = [])
136138
$totalQty = 0;
137139
$qtys = $this->prepareItemsQty($order, $qtys);
138140
foreach ($order->getAllItems() as $orderItem) {
139-
if (!$this->_canInvoiceItem($orderItem)) {
141+
if (!$this->_canInvoiceItem($orderItem, $qtys)) {
140142
continue;
141143
}
142144
$item = $this->orderConverter->itemToInvoiceItem($orderItem);
@@ -192,16 +194,15 @@ private function prepareItemsQty(Order $order, array $qtys = [])
192194
}
193195

194196
/**
195-
* Check if order item can be invoiced. Dummy item can be invoiced or with his children or
196-
* with parent item which is included to invoice
197+
* Check if order item can be invoiced.
197198
*
198199
* @param \Magento\Sales\Api\Data\OrderItemInterface $item
200+
* @param array $qtys
199201
* @return bool
200202
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
201203
*/
202-
protected function _canInvoiceItem(\Magento\Sales\Api\Data\OrderItemInterface $item)
204+
protected function _canInvoiceItem(\Magento\Sales\Api\Data\OrderItemInterface $item, array $qtys = [])
203205
{
204-
$qtys = [];
205206
if ($item->getLockedDoInvoice()) {
206207
return false;
207208
}

app/code/Magento/Wishlist/Test/Mftf/Test/StorefrontAddMultipleStoreProductsToWishlistTest.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
<description value="All products added to wishlist should be visible on any store. Even if product visibility was set to 'Not Visible Individually' for this store"/>
1616
<group value="wishlist"/>
1717
<severity value="AVERAGE"/>
18-
<skip>
19-
<issueId value="MAGETWO-93980"/>
20-
</skip>
18+
<testCaseId value="MAGETWO-95678"/>
2119
</annotations>
2220
<before>
2321
<createData entity="customStoreGroup" stepKey="storeGroup"/>

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/OrderInvoiceCreateTest.php

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,96 @@ public function testInvoiceCreate()
9090
'Failed asserting that Order status was changed'
9191
);
9292
}
93+
94+
/**
95+
* Tests that MAGETWO-95346 was fixed for bundled products
96+
*
97+
* @expectedException \Exception
98+
* @codingStandardsIgnoreStart
99+
* @expectedExceptionMessageRegExp /Invoice Document Validation Error\(s\):(?:\n|\\n)The invoice can't be created without products. Add products and try again./
100+
* @codingStandardsIgnoreEnd
101+
* @magentoApiDataFixture Magento/Sales/_files/order_with_bundle.php
102+
*/
103+
public function testOrderWithBundleInvoicedWithInvalidQuantitiesReturnsError()
104+
{
105+
/** @var \Magento\Sales\Model\Order $existingOrder */
106+
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
107+
->loadByIncrementId('100000001');
108+
109+
$serviceInfo = [
110+
'rest' => [
111+
'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
112+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
113+
],
114+
'soap' => [
115+
'service' => self::SERVICE_READ_NAME,
116+
'serviceVersion' => self::SERVICE_VERSION,
117+
'operation' => self::SERVICE_READ_NAME . 'execute',
118+
],
119+
];
120+
121+
$requestData = [
122+
'orderId' => $existingOrder->getId(),
123+
'notify' => true,
124+
'appendComment' => true,
125+
'items' => [
126+
[
127+
'order_item_id' => -1,
128+
'qty' => 1
129+
]
130+
],
131+
'comment' => [
132+
'comment' => 'Test offline',
133+
'isVisibleOnFront' => 1,
134+
],
135+
];
136+
137+
$this->_webApiCall($serviceInfo, $requestData);
138+
}
139+
140+
/**
141+
* Tests that MAGETWO-95346 was fixed for configurable products
142+
*
143+
* @expectedException \Exception
144+
* @codingStandardsIgnoreStart
145+
* @expectedExceptionMessageRegExp /Invoice Document Validation Error\(s\):(?:\n|\\n)The invoice can't be created without products. Add products and try again./
146+
* @codingStandardsIgnoreEnd
147+
* @magentoApiDataFixture Magento/Sales/_files/order_configurable_product.php
148+
*/
149+
public function testOrderWithConfigurableProductInvoicedWithInvalidQuantitiesReturnsError()
150+
{
151+
/** @var \Magento\Sales\Model\Order $existingOrder */
152+
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
153+
->loadByIncrementId('100000001');
154+
155+
$serviceInfo = [
156+
'rest' => [
157+
'resourcePath' => '/V1/order/' . $existingOrder->getId() . '/invoice',
158+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_POST,
159+
],
160+
'soap' => [
161+
'service' => self::SERVICE_READ_NAME,
162+
'serviceVersion' => self::SERVICE_VERSION,
163+
'operation' => self::SERVICE_READ_NAME . 'execute',
164+
],
165+
];
166+
167+
$requestData = [
168+
'orderId' => $existingOrder->getId(),
169+
'notify' => true,
170+
'appendComment' => true,
171+
'items' => [
172+
[
173+
'order_item_id' => -1,
174+
'qty' => 1
175+
]
176+
],
177+
'comment' => [
178+
'comment' => 'Test offline',
179+
'isVisibleOnFront' => 1,
180+
],
181+
];
182+
183+
$this->_webApiCall($serviceInfo, $requestData);
184+
}
93185
}

dev/tests/api-functional/testsuite/Magento/Sales/Service/V1/ShipOrderTest.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class ShipOrderTest extends \Magento\TestFramework\TestCase\WebapiAbstract
2525

2626
protected function setUp()
2727
{
28-
$this->markTestIncomplete('https://github.com/magento-engcom/msi/issues/1335');
2928
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
3029

3130
$this->shipmentRepository = $this->objectManager->get(
@@ -38,6 +37,7 @@ protected function setUp()
3837
*/
3938
public function testConfigurableShipOrder()
4039
{
40+
$this->markTestIncomplete('https://github.com/magento-engcom/msi/issues/1335');
4141
$productsQuantity = 1;
4242

4343
/** @var \Magento\Sales\Model\Order $existingOrder */
@@ -132,6 +132,39 @@ public function testShipOrder()
132132
);
133133
}
134134

135+
/**
136+
* Tests that not providing a tracking number produces the correct error. See MAGETWO-95429
137+
* @expectedException \Exception
138+
* @codingStandardsIgnoreStart
139+
* @expectedExceptionMessageRegExp /Shipment Document Validation Error\(s\):(?:\n|\\n)Please enter a tracking number./
140+
* @codingStandardsIgnoreEnd
141+
* @magentoApiDataFixture Magento/Sales/_files/order_new.php
142+
*/
143+
public function testShipOrderWithoutTrackingNumberReturnsError()
144+
{
145+
$this->_markTestAsRestOnly('SOAP requires an tracking number to be provided so this case is not possible.');
146+
147+
/** @var \Magento\Sales\Model\Order $existingOrder */
148+
$existingOrder = $this->objectManager->create(\Magento\Sales\Model\Order::class)
149+
->loadByIncrementId('100000001');
150+
151+
$requestData = [
152+
'orderId' => $existingOrder->getId(),
153+
'comment' => [
154+
'comment' => 'Test Comment',
155+
'is_visible_on_front' => 1,
156+
],
157+
'tracks' => [
158+
[
159+
'title' => 'Simple shipment track',
160+
'carrier_code' => 'UPS'
161+
]
162+
]
163+
];
164+
165+
$this->_webApiCall($this->getServiceInfo($existingOrder), $requestData);
166+
}
167+
135168
/**
136169
* @magentoApiDataFixture Magento/Bundle/_files/order_with_bundle_shipped_separately.php
137170
*/
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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\Sales\Api\Data\OrderItemInterface;
9+
use Magento\Sales\Api\OrderItemRepositoryInterface;
10+
use Magento\Sales\Api\OrderRepositoryInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\Sales\Model\Order\Item;
13+
use Magento\TestFramework\ObjectManager;
14+
15+
$objectManager = ObjectManager::getInstance();
16+
17+
require 'order.php';
18+
/** @var Order $order */
19+
20+
$orderItems = [
21+
[
22+
OrderItemInterface::PRODUCT_ID => 2,
23+
OrderItemInterface::BASE_PRICE => 100,
24+
OrderItemInterface::ORDER_ID => $order->getId(),
25+
OrderItemInterface::QTY_ORDERED => 2,
26+
OrderItemInterface::QTY_INVOICED => 2,
27+
OrderItemInterface::PRICE => 100,
28+
OrderItemInterface::ROW_TOTAL => 102,
29+
OrderItemInterface::PRODUCT_TYPE => 'bundle',
30+
'product_options' => [
31+
'product_calculations' => 0,
32+
],
33+
'children' => [
34+
[
35+
OrderItemInterface::PRODUCT_ID => 13,
36+
OrderItemInterface::ORDER_ID => $order->getId(),
37+
OrderItemInterface::QTY_ORDERED => 10,
38+
OrderItemInterface::QTY_INVOICED => 10,
39+
OrderItemInterface::BASE_PRICE => 90,
40+
OrderItemInterface::PRICE => 90,
41+
OrderItemInterface::ROW_TOTAL => 92,
42+
OrderItemInterface::PRODUCT_TYPE => 'simple',
43+
'product_options' => [
44+
'bundle_selection_attributes' => [
45+
'qty' => 2,
46+
],
47+
],
48+
],
49+
],
50+
],
51+
];
52+
53+
if (!function_exists('saveOrderItems')) {
54+
/**
55+
* Save Order Items.
56+
*
57+
* @param array $orderItems
58+
* @param Item|null $parentOrderItem [optional]
59+
* @return void
60+
*/
61+
function saveOrderItems(array $orderItems, Order $order, $parentOrderItem = null)
62+
{
63+
$objectManager = ObjectManager::getInstance();
64+
65+
foreach ($orderItems as $orderItemData) {
66+
/** @var Item $orderItem */
67+
$orderItem = $objectManager->create(Item::class);
68+
if (null !== $parentOrderItem) {
69+
$orderItemData['parent_item'] = $parentOrderItem;
70+
}
71+
$orderItem->setData($orderItemData);
72+
$order->addItem($orderItem);
73+
74+
if (isset($orderItemData['children'])) {
75+
saveOrderItems($orderItemData['children'], $order, $orderItem);
76+
}
77+
}
78+
}
79+
}
80+
81+
saveOrderItems($orderItems, $order);
82+
/** @var OrderRepositoryInterface $orderRepository */
83+
$orderRepository = $objectManager->get(OrderRepositoryInterface::class);
84+
$order = $orderRepository->save($order);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
require 'order_rollback.php';

0 commit comments

Comments
 (0)