Skip to content

Commit ef2b8bd

Browse files
committed
ACP2E-4157: Error when create credit memo for offline refund
1 parent 00b7ccf commit ef2b8bd

File tree

1 file changed

+22
-5
lines changed
  • app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo

1 file changed

+22
-5
lines changed

app/code/Magento/Sales/Controller/Adminhtml/Order/Creditmemo/Save.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
use Magento\Sales\Model\Order\Creditmemo;
1212
use Magento\Sales\Model\Order\Email\Sender\CreditmemoSender;
1313
use Magento\Catalog\Model\Product\Type\AbstractType;
14+
use Magento\Sales\Model\Order\Creditmemo\Item;
1415

16+
/**
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+
*/
1519
class Save extends \Magento\Backend\App\Action implements HttpPostActionInterface
1620
{
1721
/**
@@ -156,11 +160,7 @@ private function adjustCreditMemoItemQuantities(Creditmemo $creditMemo): void
156160
$parentQuantities = [];
157161
foreach ($items as $item) {
158162
if ($parentId = $item->getOrderItem()->getParentItemId()) {
159-
$parentOrderItem = $item->getOrderItem()->getParentItem();
160-
if ($parentOrderItem && $parentOrderItem->getProductType() === 'bundle' &&
161-
($parentOptions = $parentOrderItem->getProductOptions()) &&
162-
isset($parentOptions['product_calculations']) &&
163-
$parentOptions['product_calculations'] == AbstractType::CALCULATE_PARENT) {
163+
if ($this->shouldSkipQuantityAccumulation($item)) {
164164
continue;
165165
}
166166
if (empty($parentQuantities[$parentId])) {
@@ -179,4 +179,21 @@ private function adjustCreditMemoItemQuantities(Creditmemo $creditMemo): void
179179
}
180180
}
181181
}
182+
183+
/**
184+
* Check if quantity accumulation should be skipped for bundle products with fixed pricing
185+
*
186+
* @param Item $item
187+
* @return bool
188+
*/
189+
private function shouldSkipQuantityAccumulation(Item $item): bool
190+
{
191+
$parentOrderItem = $item->getOrderItem()->getParentItem();
192+
if (!$parentOrderItem || $parentOrderItem->getProductType() !== 'bundle') {
193+
return false;
194+
}
195+
$parentOptions = $parentOrderItem->getProductOptions();
196+
return isset($parentOptions['product_calculations']) &&
197+
$parentOptions['product_calculations'] == AbstractType::CALCULATE_PARENT;
198+
}
182199
}

0 commit comments

Comments
 (0)