Skip to content

Commit 202b441

Browse files
author
Joan He
committed
Merge remote-tracking branch 'arcticfoxes/MC-10964' into pr
2 parents c5c060f + de52a1f commit 202b441

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ private function prepareItemsQty(Order $order, array $qtys = [])
190190
if ($orderItem->getProductType() == Type::TYPE_BUNDLE && !$orderItem->isShipSeparately()) {
191191
$qtys[$orderItem->getId()] = $orderItem->getQtyOrdered() - $orderItem->getQtyInvoiced();
192192
} else {
193+
$parentItem = $orderItem->getParentItem();
194+
$parentItemId = $parentItem ? $parentItem->getId() : null;
195+
if ($parentItemId && isset($qtys[$parentItemId])) {
196+
$qtys[$orderItem->getId()] = $qtys[$parentItemId];
197+
}
193198
continue;
194199
}
195200
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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\Sales\Model\Service;
9+
10+
use Magento\Sales\Api\Data\OrderInterface;
11+
use Magento\Sales\Model\Order;
12+
use Magento\TestFramework\Helper\Bootstrap;
13+
14+
/**
15+
* Tests \Magento\Sales\Model\Service\InvoiceService
16+
*/
17+
class InvoiceServiceTest extends \PHPUnit\Framework\TestCase
18+
{
19+
/**
20+
* @var InvoiceService
21+
*/
22+
private $invoiceService;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp()
28+
{
29+
$this->invoiceService = Bootstrap::getObjectManager()->create(InvoiceService::class);
30+
}
31+
32+
/**
33+
* @param int $invoiceQty
34+
* @magentoDataFixture Magento/Sales/_files/order_configurable_product.php
35+
* @return void
36+
* @dataProvider prepareInvoiceConfigurableProductDataProvider
37+
*/
38+
public function testPrepareInvoiceConfigurableProduct(int $invoiceQty): void
39+
{
40+
/** @var OrderInterface $order */
41+
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
42+
$orderItems = $order->getItems();
43+
foreach ($orderItems as $orderItem) {
44+
if ($orderItem->getParentItemId()) {
45+
$parentItemId = $orderItem->getParentItemId();
46+
}
47+
}
48+
$invoice = $this->invoiceService->prepareInvoice($order, [$parentItemId => $invoiceQty]);
49+
$invoiceItems = $invoice->getItems();
50+
foreach ($invoiceItems as $invoiceItem) {
51+
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
52+
}
53+
}
54+
55+
public function prepareInvoiceConfigurableProductDataProvider()
56+
{
57+
return [
58+
'full invoice' => [2],
59+
'partial invoice' => [1]
60+
];
61+
}
62+
63+
/**
64+
* @param int $invoiceQty
65+
* @magentoDataFixture Magento/Sales/_files/order.php
66+
* @return void
67+
* @dataProvider prepareInvoiceSimpleProductDataProvider
68+
*/
69+
public function testPrepareInvoiceSimpleProduct(int $invoiceQty): void
70+
{
71+
/** @var OrderInterface $order */
72+
$order = Bootstrap::getObjectManager()->create(Order::class)->load('100000001', 'increment_id');
73+
$orderItems = $order->getItems();
74+
$invoiceQtys = [];
75+
foreach ($orderItems as $orderItem) {
76+
$invoiceQtys[$orderItem->getItemId()] = $invoiceQty;
77+
}
78+
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceQtys);
79+
$invoiceItems = $invoice->getItems();
80+
foreach ($invoiceItems as $invoiceItem) {
81+
$this->assertEquals($invoiceQty, $invoiceItem->getQty());
82+
}
83+
}
84+
85+
public function prepareInvoiceSimpleProductDataProvider()
86+
{
87+
return [
88+
'full invoice' => [2],
89+
'partial invoice' => [1]
90+
];
91+
}
92+
}

0 commit comments

Comments
 (0)