1

I have a question about adjusters: I am working on a shop which has two tax zones (Switzerland and EU) and two tax rates (8% and 19%). The tax should always be included in the item price. From my understanding that is not possible for both tax zones at the same time. So I am having my eye on the adjusters.

I would use an adjuster to do the following: The client facing cart on the front end gets no adjustments. Only after the shipping address has been confirmed I would apply either one or the other adjustment (8% or 19% included) conditionally via the plugin to the order.

Does that make sense? Is that possible and if so is this even the best way to go or am I missing something which is more awesome?

If the answer is yes then I would invest more time and just dig into it.

Thanks in advance!

2

Answer is yes, you could use an adjuster to try and make the price "even" while in the cart.

1

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 [];
        };
      }
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.