77
88namespace Magento \QuoteGraphQl \Model \Resolver ;
99
10+ use Magento \Framework \App \Config \ScopeConfigInterface ;
11+ use Magento \Framework \App \ObjectManager ;
1012use Magento \Framework \Exception \LocalizedException ;
1113use Magento \Framework \GraphQl \Config \Element \Field ;
1214use Magento \Framework \GraphQl \Query \ResolverInterface ;
1315use Magento \Framework \GraphQl \Schema \Type \ResolveInfo ;
1416use Magento \Quote \Model \Quote ;
1517use Magento \Quote \Model \Quote \Address \Total ;
1618use Magento \QuoteGraphQl \Model \Cart \TotalsCollector ;
19+ use Magento \Store \Model \ScopeInterface ;
20+ use Magento \Tax \Model \Config ;
1721
1822/**
1923 * @inheritdoc
@@ -25,13 +29,21 @@ class CartPrices implements ResolverInterface
2529 */
2630 private $ totalsCollector ;
2731
32+ /**
33+ * @var ScopeConfigInterface
34+ */
35+ private ScopeConfigInterface $ scopeConfig ;
36+
2837 /**
2938 * @param TotalsCollector $totalsCollector
39+ * @param ScopeConfigInterface|null $scopeConfig
3040 */
3141 public function __construct (
32- TotalsCollector $ totalsCollector
42+ TotalsCollector $ totalsCollector ,
43+ ScopeConfigInterface $ scopeConfig = null
3344 ) {
3445 $ this ->totalsCollector = $ totalsCollector ;
46+ $ this ->scopeConfig = $ scopeConfig ?? ObjectManager::getInstance ()->get (ScopeConfigInterface::class);
3547 }
3648
3749 /**
@@ -59,7 +71,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
5971 'subtotal_including_tax ' => ['value ' => $ cartTotals ->getSubtotalInclTax (), 'currency ' => $ currency ],
6072 'subtotal_excluding_tax ' => ['value ' => $ cartTotals ->getSubtotal (), 'currency ' => $ currency ],
6173 'subtotal_with_discount_excluding_tax ' => [
62- 'value ' => $ cartTotals -> getSubtotalWithDiscount () + $ cartTotals-> getDiscountTaxCompensationAmount ( ),
74+ 'value ' => $ this -> getSubtotalWithDiscountExcludingTax ( $ cartTotals ),
6375 'currency ' => $ currency
6476 ],
6577 'applied_taxes ' => $ this ->getAppliedTaxes ($ cartTotals , $ currency ),
@@ -110,4 +122,23 @@ private function getDiscount(Total $total, string $currency)
110122 'amount ' => ['value ' => $ total ->getDiscountAmount (), 'currency ' => $ currency ]
111123 ];
112124 }
125+
126+ /**
127+ * Get Subtotal with discount excluding tax.
128+ *
129+ * @param Total $cartTotals
130+ * @return float
131+ */
132+ private function getSubtotalWithDiscountExcludingTax (Total $ cartTotals ): float
133+ {
134+ $ discountIncludeTax = $ this ->scopeConfig ->getValue (
135+ Config::CONFIG_XML_PATH_DISCOUNT_TAX ,
136+ ScopeInterface::SCOPE_STORE
137+ ) ?? 0 ;
138+ $ discountExclTax = $ discountIncludeTax ?
139+ $ cartTotals ->getDiscountAmount () + $ cartTotals ->getDiscountTaxCompensationAmount () :
140+ $ cartTotals ->getDiscountAmount ();
141+
142+ return $ cartTotals ->getSubtotal () + $ discountExclTax ;
143+ }
113144}
0 commit comments