Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Add ability to set the from location dynamically #10

Open
codyjames opened this issue May 19, 2021 · 1 comment
Open

FR: Add ability to set the from location dynamically #10

codyjames opened this issue May 19, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@codyjames
Copy link

codyjames commented May 19, 2021

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_ or nexus_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.

@codyjames codyjames added the enhancement New feature or request label May 19, 2021
@mike-moreau
Copy link

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
            }
        );
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants