1111use Magento \Sales \Model \Order \Creditmemo ;
1212use Magento \Sales \Model \Order \Email \Sender \CreditmemoSender ;
1313use Magento \Catalog \Model \Product \Type \AbstractType ;
14+ use Magento \Sales \Model \Order \Creditmemo \Item ;
1415
16+ /**
17+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
18+ */
1519class 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