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?