<p>I'm not sure but this jumped out at me</p>

<p><code>$myAdjuster-&gt;amount = -$order-&gt;totalTax;</code>  </p>

<p>I don't think you can "negative" a variable in that way.</p>

<p>Try  <code>$myAdjuster-&gt;amount = $order-&gt;totalTax * -1;</code> instead</p>

CC BY-SA 4.0
2018-09-25T17:00:37.730Z
2018-09-25T17:00:37.730Z
foamcow
<p>It seems you're setting the adjuster <code>$taxAdjuster-&gt;amount</code> to zero.  This should be the correct adjuster code...</p>

<pre><code>namespace Commerce\Adjusters;

use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class TaxExempt_TaxAdjuster implements Commerce_AdjusterInterface
{
    public function adjust(Commerce_OrderModel &amp;$order, array $lineItems = [])
    {
        $taxAdjuster = new Commerce_OrderAdjustmentModel();

        if (craft()-&gt;userSession-&gt;getUser()-&gt;getContent()-&gt;getAttribute('userTaxExempt')) {
            $originalTax = $order-&gt;baseTax;
            $order-&gt;baseTax = 0;

            $taxAdjuster-&gt;type = "Tax";
            $taxAdjuster-&gt;name = "Tax Exempt";
            $taxAdjuster-&gt;description = "Tax Exempt";
            $taxAdjuster-&gt;amount = $originalTax;
            $taxAdjuster-&gt;orderId = $order-&gt;id;
            $taxAdjuster-&gt;optionsJson = ['lineItemsAffected' =&gt; null];
            $taxAdjuster-&gt;included = false;

            return [$taxAdjuster];
        }

        return [];
    }
}
</code></pre>

CC BY-SA 4.0
2018-10-09T19:45:12.100Z
2018-10-09T19:45:12.100Z
user2170627
<p>I'm attempting to add a very basic tax adjuster to specific users based on a custom lightswitch field. I currently have a simple plugin with two classes for the plugin and adjuster that mirror the example in the <a href="https://craftcommerce.com/docs/adjusters" rel="nofollow noreferrer">adjuster documentation</a>. </p>

<p><strong>craft/plugins/taxexemptadjuster/TaxExemptAdjusterPlugin.php</strong>
    

<pre><code>namespace Craft;

require_once('Adjusters/TaxExempt_TaxAdjuster.php');

class TaxExemptAdjusterPlugin extends BasePlugin
{
    ...

    public function commerce_registerOrderAdjusters()
    {
        return [
            601 =&gt; new \Commerce\Adjusters\TaxExempt_TaxAdjuster
        ];
    }
}
</code></pre>

<p><strong>craft/plugins/taxexemptadjuster/Adjusters/TaxExempt_TaxAdjuster.php</strong>
    

<pre><code>namespace Commerce\Adjusters;

use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class TaxExempt_TaxAdjuster implements Commerce_AdjusterInterface
{
    public function adjust(Commerce_OrderModel &amp;$order, array $lineItems = [])
    {
        $taxAdjuster = new Commerce_OrderAdjustmentModel();

        if (craft()-&gt;userSession-&gt;getUser()-&gt;getContent()-&gt;getAttribute('userTaxExempt')) {
            $order-&gt;baseTax = $order-&gt;baseTax - $order-&gt;baseTax;

            $taxAdjuster-&gt;type = "Tax";
            $taxAdjuster-&gt;name = "Tax Exempt";
            $taxAdjuster-&gt;description = "Tax Exempt";
            $taxAdjuster-&gt;amount = -$order-&gt;baseTax;
            $taxAdjuster-&gt;orderId = $order-&gt;id;
            $taxAdjuster-&gt;optionsJson = ['lineItemsAffected' =&gt; null];
            $taxAdjuster-&gt;included = false;

            return [$taxAdjuster];
        }

        return [];
    }
}
</code></pre>

<p>Based on the examples I've found in the adjusters documentation this should zero out the baseTax and totalTax values if an authenticated user has the custom userTaxExempt lightswitch field enabled. I've tried removing the conditional to see if there was an issue with the custom field on the user profile but even then none of the adjustments are applied.</p>

<p>What have I overlooked?</p>

<plugin-craftcommerce><adjusters>
Tax Exempt Adjuster
# Tax Exempt Adjuster

(Asked by: username_0 on 2018-09-25)

I'm attempting to add a very basic tax adjuster to specific users based on a custom lightswitch field. I currently have a simple plugin with two classes for the plugin and adjuster that mirror the example in the adjuster documentation. 
craft/plugins/taxexemptadjuster/TaxExemptAdjusterPlugin.php
namespace Craft;

require_once('Adjusters/TaxExempt_TaxAdjuster.php');

class TaxExemptAdjusterPlugin extends BasePlugin
{
    ...

    public function commerce_registerOrderAdjusters()
    {
        return [
            601 => new \Commerce\Adjusters\TaxExempt_TaxAdjuster
        ];
    }
}

craft/plugins/taxexemptadjuster/Adjusters/TaxExempt_TaxAdjuster.php
namespace Commerce\Adjusters;

use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class TaxExempt_TaxAdjuster implements Commerce_AdjusterInterface
{
    public function adjust(Commerce_OrderModel &$order, array $lineItems = [])
    {
        $taxAdjuster = new Commerce_OrderAdjustmentModel();

        if (craft()->userSession->getUser()->getContent()->getAttribute('userTaxExempt')) {
            $order->baseTax = $order->baseTax - $order->baseTax;

            $taxAdjuster->type = "Tax";
            $taxAdjuster->name = "Tax Exempt";
            $taxAdjuster->description = "Tax Exempt";
            $taxAdjuster->amount = -$order->baseTax;
            $taxAdjuster->orderId = $order->id;
            $taxAdjuster->optionsJson = ['lineItemsAffected' => null];
            $taxAdjuster->included = false;

            return [$taxAdjuster];
        }

        return [];
    }
}

Based on the examples I've found in the adjusters documentation this should zero out the baseTax and totalTax values if an authenticated user has the custom userTaxExempt lightswitch field enabled. I've tried removing the conditional to see if there was an issue with the custom field on the user profile but even then none of the adjustments are applied.
What have I overlooked?

**Tags:** plugin-craftcommerce, adjusters


---

## 2 answers

### Answer by username_1 on 2018-09-25. Score: 1

I'm not sure but this jumped out at me

`$myAdjuster->amount = -$order->totalTax;`

I don't think you can "negative" a variable in that way.

Try `$myAdjuster->amount = $order->totalTax * -1;` instead


---

### Answer by username_2 on 2018-10-09. Score: 1

It seems you're setting the adjuster $taxAdjuster->amount to zero.  This should be the correct adjuster code...
namespace Commerce\Adjusters;

use Craft\Commerce_LineItemModel;
use Craft\Commerce_OrderAdjustmentModel;
use Craft\Commerce_OrderModel;

class TaxExempt_TaxAdjuster implements Commerce_AdjusterInterface
{
    public function adjust(Commerce_OrderModel &$order, array $lineItems = [])
    {
        $taxAdjuster = new Commerce_OrderAdjustmentModel();

        if (craft()->userSession->getUser()->getContent()->getAttribute('userTaxExempt')) {
            $originalTax = $order->baseTax;
            $order->baseTax = 0;

            $taxAdjuster->type = "Tax";
            $taxAdjuster->name = "Tax Exempt";
            $taxAdjuster->description = "Tax Exempt";
            $taxAdjuster->amount = $originalTax;
            $taxAdjuster->orderId = $order->id;
            $taxAdjuster->optionsJson = ['lineItemsAffected' => null];
            $taxAdjuster->included = false;

            return [$taxAdjuster];
        }

        return [];
    }
}


---

