diff --git a/vendor/magento/module-quote-graph-ql/Model/Resolver/Discounts.php b/vendor/magento/module-quote-graph-ql/Model/Resolver/Discounts.php index 703015fd7dd..d0c69b8b544 100644 --- a/vendor/magento/module-quote-graph-ql/Model/Resolver/Discounts.php +++ b/vendor/magento/module-quote-graph-ql/Model/Resolver/Discounts.php @@ -41,18 +41,18 @@ class Discounts implements ResolverInterface { $discountValues=[]; $address = $quote->getShippingAddress(); - $totalDiscounts = $address->getExtensionAttributes()->getDiscounts(); - if ($totalDiscounts && is_array($totalDiscounts)) { - foreach ($totalDiscounts as $value) { - $discount = []; - $amount = []; - $discount['label'] = $value->getRuleLabel() ?: __('Discount'); - /* @var \Magento\SalesRule\Api\Data\DiscountDataInterface $discountData */ - $discountData = $value->getDiscountData(); - $amount['value'] = $discountData->getAmount(); - $amount['currency'] = $quote->getQuoteCurrencyCode(); - $discount['amount'] = $amount; - $discountValues[] = $discount; + $totals = $address->getTotals(); + if ($totals && is_array($totals)) { + foreach ($totals as $total) { + if (stripos($total->getCode(), 'total') === false && $total->getValue() < 0.00) { + $discount = []; + $amount = []; + $discount['label'] = $total->getTitle() ?: __('Discount'); + $amount['value'] = $total->getValue() * -1; + $amount['currency'] = $quote->getQuoteCurrencyCode(); + $discount['amount'] = $amount; + $discountValues[] = $discount; + } } return $discountValues; } diff --git a/vendor/magento/module-quote-graph-ql/etc/schema.graphqls b/vendor/magento/module-quote-graph-ql/etc/schema.graphqls index 1dc66531fba..2815a95a9bd 100644 --- a/vendor/magento/module-quote-graph-ql/etc/schema.graphqls +++ b/vendor/magento/module-quote-graph-ql/etc/schema.graphqls @@ -167,7 +167,7 @@ type CartPrices @doc(description: "Contains details about the final price of it discount: CartDiscount @deprecated(reason: "Use discounts instead.") subtotal_with_discount_excluding_tax: Money @doc(description: "The subtotal with any discounts applied, but not taxes.") applied_taxes: [CartTaxItem] @doc(description: "An array containing the names and amounts of taxes applied to each item in the cart.") - discounts: [Discount] @doc(description:"An array containing all discounts applied to the cart.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Discounts") + discounts: [Discount] @doc(description:"An array containing cart rule discounts, store credit and gift cards applied to the cart.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\Discounts") } type CartTaxItem @doc(description: "Contains tax information about an item in the cart.") {