Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions app/code/Magento/QuoteGraphQl/Model/Resolver/CartItemPrices.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,24 +65,29 @@ 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());
}
$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();
}

$discountAmount += $cartItem->getDiscountAmount();

return [
'model' => $cartItem,
'price' => [
Expand Down