I put together an example adjuster that checks for a shipping address in Switzerland or the EU, and then applies the 8% or 19% adjustment to the order's item subtotal. It does not include shipping in the tax amount.
You would still need to register this via a plugin, see this thread for an example.
<?php
namespace Commerce\Adjusters;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;
class MyAdjuster implements Commerce_AdjusterInterface {
public function adjust(Commerce_OrderModel &$order, array $lineItems = []){
$euCountries = array(
'AT', 'BE', 'HR', 'BG', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GR', 'HU', 'IE',
'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE', 'GB'
);
if($order->shippingMethodHandle !== NULL && sizeof($order->lineItems) > 0)
{
$countryCode = $order->shippingAddress->getCountry()->iso;
if(in_array($countryCode, $euCountries))
{
// Country is in EU
$salesTax = $order->itemSubtotal * 0.19;
}
else if ( $countryCode == "CH" )
{
// Country is Switzerland
$salesTax = $order->itemSubtotal * 0.08;
}
else
{
return [];
}
$order->baseTax = $order->baseTax + $salesTax;
$taxAdjuster = new Commerce_OrderAdjustmentModel();
$taxAdjuster->type = "Tax";
$taxAdjuster->name = "Sales Tax";
$taxAdjuster->description = "Adds "+$salesTax+" of tax to the order";
$taxAdjuster->amount = +$salesTax;
$taxAdjuster->orderId = $order->id;
// If your Adjuster affects lineItems rather than the total, you record the ids here
$taxAdjuster->optionsJson = [ 'lineItemsAffected' => null ];
$taxAdjuster->included = false;
return [$taxAdjuster];
} else {
return [];
};
}
}