Disable VAT/Taxes on specific cases #989
-
Is it possible to overwrite the vat/tax rules in some order cases? I want to add a field to each order with company and VAT ID, then when the VAT ID is valid (check via external API) the VAT should be disabled for this order and recalculate the totals. What is the best approach for this?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey 👋 Which tax engine are you using? Basic or Standard? (it'll tell you if you run |
Beta Was this translation helpful? Give feedback.
-
I believe you should be able to achieve this by creating your own tax engine, which extends the "Standard Tax Engine" you're already using. You first need to create your tax engine class - I've just put mine in The As a really basic example, I've got the <?php
namespace App;
use DuncanMcClean\SimpleCommerce\Contracts\Order;
use DuncanMcClean\SimpleCommerce\Orders\LineItem;
use DuncanMcClean\SimpleCommerce\Tax\TaxCalculation;
class CustomTaxEngine extends \DuncanMcClean\SimpleCommerce\Tax\Standard\TaxEngine
{
public function calculateForLineItem(Order $order, LineItem $lineItem): TaxCalculation
{
$hasValidVat = true;
if ($hasValidVat) {
return new TaxCalculation(0, 0, false);
}
return parent::calculateForLineItem($order, $lineItem);
}
} Then, all you need to do is swap over the // config/simple-commerce.php
'tax_engine' => \App\CustomTaxEngine::class, ^ btw, I've just tagged v6 so you may need to replace |
Beta Was this translation helpful? Give feedback.
I believe you should be able to achieve this by creating your own tax engine, which extends the "Standard Tax Engine" you're already using.
You first need to create your tax engine class - I've just put mine in
app
and called itCustomTaxEngine
, feel free to call it whatever you want.The
calculateForLineItem
method is responsible for calculating the tax for each line item.As a really basic example, I've got the
$hasValidVat
variable which, whentrue
, will return a 0% tax rate for the line item. Otherwise, it'll fallback to the normal standard tax engine logic. You can obviously change this as needed.