Skip to content

Commit f83ac29

Browse files
committed
MAGETWO-59074: Creditmemo return to stock only one unit of configurable product
1 parent d707052 commit f83ac29

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

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

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* Copyright © 2016 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\Sales\Model\Order;
87

98
/**
@@ -59,15 +58,7 @@ public function createByOrder(\Magento\Sales\Model\Order $order, array $data = [
5958
if ($orderItem->isDummy()) {
6059
$qty = 1;
6160
if (isset($data['qtys'][$orderItem->getParentItemId()])) {
62-
$productOptions = $orderItem->getProductOptions();
63-
if (isset($productOptions['bundle_selection_attributes'])) {
64-
$bundleSelectionAttributes = unserialize(
65-
$productOptions['bundle_selection_attributes']
66-
);
67-
if ($bundleSelectionAttributes) {
68-
$qty = $bundleSelectionAttributes['qty'] * $data['qtys'][$orderItem->getParentItemId()];
69-
}
70-
}
61+
$qty = $this->calculateProductOptions($orderItem, $data['qtys']);
7162
}
7263
$orderItem->setLockedDoShip(true);
7364
} else {
@@ -145,15 +136,7 @@ public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, arr
145136
if ($orderItem->isDummy()) {
146137
$qty = 1;
147138
if (isset($data['qtys'][$orderItem->getParentItemId()])) {
148-
$productOptions = $orderItem->getProductOptions();
149-
if (isset($productOptions['bundle_selection_attributes'])) {
150-
$bundleSelectionAttributes = unserialize(
151-
$productOptions['bundle_selection_attributes']
152-
);
153-
if ($bundleSelectionAttributes) {
154-
$qty = $bundleSelectionAttributes['qty'] * $data['qtys'][$orderItem->getParentItemId()];
155-
}
156-
}
139+
$qty = $this->calculateProductOptions($orderItem, $data['qtys']);
157140
}
158141
} else {
159142
if (isset($qtys[$orderItem->getId()])) {
@@ -267,4 +250,24 @@ protected function initData($creditmemo, $data)
267250
$creditmemo->setAdjustmentNegative($data['adjustment_negative']);
268251
}
269252
}
253+
254+
/**
255+
* @param \Magento\Sales\Api\Data\OrderItemInterface $orderItem
256+
* @param array $qtys
257+
* @return int
258+
*/
259+
private function calculateProductOptions(\Magento\Sales\Api\Data\OrderItemInterface $orderItem, $qtys)
260+
{
261+
$qty = 1;
262+
$productOptions = $orderItem->getProductOptions();
263+
if (isset($productOptions['bundle_selection_attributes'])) {
264+
$bundleSelectionAttributes = unserialize(
265+
$productOptions['bundle_selection_attributes']
266+
);
267+
if ($bundleSelectionAttributes) {
268+
$qty = $bundleSelectionAttributes['qty'] * $qtys[$orderItem->getParentItemId()];
269+
}
270+
}
271+
return $qty;
272+
}
270273
}

0 commit comments

Comments
 (0)