FR: Add ability to set the from location dynamically
Opened this issue · 1 comments
Description
We're wanting to use this plugin for a marketplace (peer-to-peer selling) website. However, I think we need the ability to set the FROM address on a per-cart basis.
From TaxJar (https://support.taxjar.com/article/165-what-if-i-dont-know-the-from-address-at-time-of-tax-estimation):
It is highly recommended to use the FROM address of the merchant selling the product (or multiple addresses) using the
from_
ornexus_addresses
parameters with the /v2/taxes endpoint. This will provide the most accurate sales tax calculation and determine if sales tax is actually due.
Can this plugin provide a way to do that?
The current FROM location is pulled from this setting, I think:
Go to Commerce → Store Settings → Store Location, and ensure that everything is set correctly there. The plugin will use this info to populate the from address when getting tax info from TaxJar.
You may be able to achieve what you are after by modifying the request params sent to TaxJar using the ModifyRequestEvent
in a Module.
https://github.com/craftcms/commerce-taxjar/blob/develop/src/adjusters/TaxJar.php#L184
<?php
// In your custom module
use yii\base\Module;
use craft\commerce\taxjar\adjusters\TaxJar as TaxJarAdjuster;
use craft\commerce\taxjar\events\ModifyRequestEvent as TaxJarModifyRequestEvent;
class General extends Module
{
public function init()
{
// ....
/**
* Listen for the TaxJar Plugin's tax Adjuster, and modify the request
* to the TaxJar API.
*/
Event::on(
TaxJarAdjuster::class,
TaxJarAdjuster::EVENT_MODIFY_TAX_FOR_ORDER_REQUEST,
function (TaxJarModifyRequestEvent $event) {
// ...add or change params here...
// $event->requestParams = ...
// $event->order and $event->address are available too
}
);
}
}