Some customers with a domestic shipping address within Germany are still tax exempt (e.g. NATO, or US Army). Since this is considered an export delivery.
How can this be implemented? The only solution I have found is to completely override/replace CartRuleLoader
What I have done so far: I created a custom field in Customers, where a store editor can specify a customer as tax free (even within Germany).
Then I overwrote the class TaxDetector:
class TaxDetector extends \Shopware\Core\Checkout\Cart\Tax\TaxDetector
{
public function isNetDelivery(SalesChannelContext $context): bool
{
$customer = $context->getCustomer();
if ($customer && ($cf = $customer->getCustomFields()) && !empty($cf['mycustomfield']) && $cf['mycustomfield'] === 'nato') {
return true;
}
return parent::isNetDelivery($context);
}
public function getTaxState(SalesChannelContext $context): string
{
$customer = $context->getCustomer();
if ($customer && ($cf = $customer->getCustomFields()) && !empty($cf['mycustomfield']) && $cf['mycustomfield'] === 'nato') {
return CartPrice::TAX_STATE_FREE;
}
return parent::getTaxState($context);
}
}
The problem is that Shopware 6 checks the validity of the tax status in CartRuleLoader when completing an order. And here the test is done in private functions that I cannot override.
load -> validateTaxFree -> detectTaxType
Any suggestions on how to solve this more eligant and futerprove then override all CartRuleLoader?