From fddd1b6136ed37f050729a20a3cff3a1a3008a00 Mon Sep 17 00:00:00 2001 From: Senthilkumar Muppidathi Date: Fri, 14 Nov 2025 13:12:50 +0530 Subject: [PATCH 1/2] #40235 - Conditionally process collectTotal only if the value of requested fields set during the collectTotals process --- .../Model/Resolver/CartItemPrices.php | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php index abbd81475e77d..a99b07376cc06 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php @@ -19,6 +19,7 @@ use Magento\QuoteGraphQl\Model\Cart\TotalsCollector; use Magento\QuoteGraphQl\Model\GetDiscounts; use Magento\QuoteGraphQl\Model\GetOptionsRegularPrice; +use Magento\Bundle\Model\Product\Type as BundleType; /** * @inheritdoc @@ -64,7 +65,13 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value } /** @var Item $cartItem */ $cartItem = $value['model']; - if (!$this->totals) { + // Collect totals only if discount, original item price and original rowtotal is there in the request + // avoid retrieve totals with the below keys if its not absolutely required + if (!$this->totals && !empty(array_intersect( + ['discounts', 'original_item_price', 'original_row_total'], + array_keys($info->getFieldSelection(1)) + )) + ) { // The totals calculation is based on quote address. // But the totals should be calculated even if no address is set $this->totals = $this->totalsCollector->collectQuoteTotals($cartItem->getQuote()); @@ -72,14 +79,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value $currencyCode = $cartItem->getQuote()->getQuoteCurrencyCode(); /** calculate bundle product discount */ - if ($cartItem->getProductType() == 'bundle') { - $discounts = $cartItem->getExtensionAttributes()->getDiscounts() ?? []; - $discountAmount = 0; - foreach ($discounts as $discount) { - $discountAmount += $discount->getDiscountData()->getAmount(); + $discountAmount = 0; + if ($cartItem->getProductType() == BundleType::TYPE_CODE) { + foreach ($cartItem->getChildren() as $childItem) { + $discountAmount += $childItem->getDiscountAmount(); } - } else { - $discountAmount = $cartItem->getDiscountAmount(); } return [ From b35222802e6b70660bc65c3457efef202e906022 Mon Sep 17 00:00:00 2001 From: Senthilkumar Muppidathi Date: Fri, 14 Nov 2025 13:14:34 +0530 Subject: [PATCH 2/2] #40235 - Adding the missed Discount --- app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php index a99b07376cc06..06eb09711ee6e 100644 --- a/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php +++ b/app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php @@ -86,6 +86,8 @@ public function resolve(Field $field, $context, ResolveInfo $info, ?array $value } } + $discountAmount += $cartItem->getDiscountAmount(); + return [ 'model' => $cartItem, 'price' => [