11
11
use Magento \Sales \Model \Order \Creditmemo ;
12
12
use Magento \Sales \Model \Order \Email \Sender \CreditmemoSender ;
13
13
use Magento \Catalog \Model \Product \Type \AbstractType ;
14
+ use Magento \Sales \Model \Order \Creditmemo \Item ;
14
15
16
+ /**
17
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18
+ */
15
19
class Save extends \Magento \Backend \App \Action implements HttpPostActionInterface
16
20
{
17
21
/**
@@ -156,11 +160,7 @@ private function adjustCreditMemoItemQuantities(Creditmemo $creditMemo): void
156
160
$ parentQuantities = [];
157
161
foreach ($ items as $ item ) {
158
162
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 )) {
164
164
continue ;
165
165
}
166
166
if (empty ($ parentQuantities [$ parentId ])) {
@@ -179,4 +179,21 @@ private function adjustCreditMemoItemQuantities(Creditmemo $creditMemo): void
179
179
}
180
180
}
181
181
}
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
+ }
182
199
}
0 commit comments