Skip to content

Commit 465e5c7

Browse files
committed
Merge remote-tracking branch 'act4/ACP2E-3947' into PR_25_June_odubovyk
2 parents 7ac8e72 + 37e8bf8 commit 465e5c7

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,16 @@ public function canShip()
887887
private function checkItemShipping(): bool
888888
{
889889
foreach ($this->getAllItems() as $item) {
890-
$qtyToShip = !$item->getParentItem() || $item->getParentItem()->getProductType() !== Type::TYPE_BUNDLE ?
891-
$item->getQtyToShip() : $item->getSimpleQtyToShip();
890+
if (!$item->getParentItem() || $item->getParentItem()->getProductType() !== Type::TYPE_BUNDLE) {
891+
$qtyToShip = $item->getQtyToShip();
892+
} else {
893+
if ($item->getParentItem()->getProductType() === Type::TYPE_BUNDLE &&
894+
$item->getParentItem()->getProduct()->getShipmentType() == Type\AbstractType::SHIPMENT_TOGETHER) {
895+
$qtyToShip = $item->getParentItem()->getQtyToShip();
896+
} else {
897+
$qtyToShip = $item->getSimpleQtyToShip();
898+
}
899+
}
892900

893901
if ($qtyToShip > 0 && !$item->getIsVirtual() && !$item->getLockedDoShip()) {
894902
return true;

app/code/Magento/Sales/Test/Unit/Model/OrderTest.php

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\Sales\Test\Unit\Model;
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\Product\Type;
1113
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
1214
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;
1315
use Magento\Framework\Api\SearchCriteria;
@@ -213,6 +215,49 @@ protected function setUp(): void
213215
);
214216
}
215217

218+
/**
219+
* @return void
220+
* @throws \PHPUnit\Framework\MockObject\Exception
221+
*/
222+
public function testCanShipBundleWithToghetherShipment(): void
223+
{
224+
$this->order->setActionFlag($this->order::ACTION_FLAG_UNHOLD, false);
225+
$this->order->setActionFlag($this->order::ACTION_FLAG_SHIP, true);
226+
227+
$bundleItem = $this->createMock(Item::class);
228+
$bundleItem->expects($this->any())->method('getParentItem')->willReturn(null);
229+
$bundleItem->expects($this->exactly(2))->method('getQtyToShip')->willReturn(0);
230+
$bundleItem->expects($this->any())->method('getProductType')->willReturn(Type::TYPE_BUNDLE);
231+
232+
$product = $this->getMockBuilder(Product::class)
233+
->disableOriginalConstructor()
234+
->addMethods(['getShipmentType'])
235+
->getMock();
236+
$product->expects($this->any())
237+
->method('getShipmentType')
238+
->willReturn(Type\AbstractType::SHIPMENT_TOGETHER);
239+
$bundleItem->expects($this->any())->method('getProduct')->willReturn($product);
240+
241+
$childProduct = $this->createMock(Item::class);
242+
$childProduct->expects($this->any())->method('getParentItem')->willReturn($bundleItem);
243+
244+
$orderItems = [$bundleItem, $childProduct];
245+
$this->searchCriteriaBuilder->expects($this->once())->method('addFilter')->willReturnSelf();
246+
247+
$searchCriteria = $this->getMockBuilder(SearchCriteria::class)
248+
->disableOriginalConstructor()
249+
->getMockForAbstractClass();
250+
$this->searchCriteriaBuilder->expects($this->once())->method('create')->willReturn($searchCriteria);
251+
$itemsCollection = $this->getMockBuilder(OrderItemSearchResultInterface::class)
252+
->onlyMethods(['getItems'])
253+
->disableOriginalConstructor()
254+
->getMockForAbstractClass();
255+
$itemsCollection->expects($this->once())->method('getItems')->willReturn($orderItems);
256+
$this->itemRepository->expects($this->once())->method('getList')->willReturn($itemsCollection);
257+
258+
$this->assertFalse($this->order->canShip());
259+
}
260+
216261
/**
217262
* Test testGetItems method.
218263
*/

0 commit comments

Comments
 (0)