Skip to content

Commit f0a55cb

Browse files
committed
WIP - BUG-AC-1084
1 parent b33b33f commit f0a55cb

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

app/code/Magento/QuoteGraphQl/Model/Resolver/CartPrices.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\App\ObjectManager;
1012
use Magento\Framework\Exception\LocalizedException;
1113
use Magento\Framework\GraphQl\Config\Element\Field;
1214
use Magento\Framework\GraphQl\Query\ResolverInterface;
1315
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1416
use Magento\Quote\Model\Quote;
1517
use Magento\Quote\Model\Quote\Address\Total;
1618
use 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

Comments
 (0)