|
3 | 3 | * Copyright © 2016 Magento. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 |
| - |
7 | 6 | namespace Magento\Sales\Model\Order;
|
8 | 7 |
|
9 | 8 | /**
|
@@ -59,15 +58,7 @@ public function createByOrder(\Magento\Sales\Model\Order $order, array $data = [
|
59 | 58 | if ($orderItem->isDummy()) {
|
60 | 59 | $qty = 1;
|
61 | 60 | 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']); |
71 | 62 | }
|
72 | 63 | $orderItem->setLockedDoShip(true);
|
73 | 64 | } else {
|
@@ -145,15 +136,7 @@ public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, arr
|
145 | 136 | if ($orderItem->isDummy()) {
|
146 | 137 | $qty = 1;
|
147 | 138 | 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']); |
157 | 140 | }
|
158 | 141 | } else {
|
159 | 142 | if (isset($qtys[$orderItem->getId()])) {
|
@@ -267,4 +250,24 @@ protected function initData($creditmemo, $data)
|
267 | 250 | $creditmemo->setAdjustmentNegative($data['adjustment_negative']);
|
268 | 251 | }
|
269 | 252 | }
|
| 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 | + } |
270 | 273 | }
|
0 commit comments