Skip to content

Commit

Permalink
Merge pull request #41 from surprisehighway/release/v2.1.7
Browse files Browse the repository at this point in the history
Release/v2.1.7
  • Loading branch information
imagehat authored Jul 28, 2021
2 parents 13eb4cf + 8fdc217 commit 3381744
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## 2.1.7
### Added
- Added the ability to override the Tax Calculation setting using hidden form inputs. [#40](https://github.com/surprisehighway/craft-avatax/issues/40)

## 2.1.6
### Fixed
- Fixed an issue where after install event breaks automated testing - thanks @davist11. [#37](https://github.com/surprisehighway/craft-avatax/issues/37)
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,34 @@ return [
];
```

## Form Input Overrides

You can use hidden form input fields to override the plugin Tax Calculation setting.

To disable tax calculation for a form even if the plugin’s Tax Calculation setting is enabled add the following input to your form:

```
<input type="hidden" name="avatax_disable_tax_calculation" value="1">
```
...or the twig helper
```
{{ hiddenInput('avatax_disable_tax_calculation', 1) }}
```

To force tax calculation for a form even if the plugin’s Tax Calculation setting is disabled add the following input to your form:

```
<input type="hidden" name="avatax_disable_tax_calculation" value="1">
```
...or the twig helper
```
{{ hiddenInput('avatax_force_tax_calculation', 1) }}
```

> Note: This setting will not force a new API request if the Avatax response is already cached. It will just force the plugin to behave as if the setting was enabled.
The values are parsed using the PHP validate filter [FILTER_VALIDATE_BOOLEAN](https://www.php.net/manual/en/filter.filters.validate.php) so values return true for "1", "true", "on" and "yes". Returns false otherwise.

## Ajax Examples

There is a JSON controller endpoint you can use for AJAX lookups/validation on the front-end. Currently the only endpoints are for address validation and [CertCapture](https://certcapture6xrest.docs.apiary.io) customer lookup by customer number.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "surprisehighway/craft-avatax",
"description": "Calculate and add sales tax to an order's base tax using Avalara's Avatax service.",
"type": "craft-plugin",
"version": "2.1.6",
"version": "2.1.7",
"keywords": [
"craft",
"cms",
Expand Down
18 changes: 16 additions & 2 deletions src/services/SalesTaxService.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ public function connectionTest($settings)
*
*/
public function createSalesOrder(Order $order)
{
if(!$this->settings->enableTaxCalculation)
{
// check for form overrides to plugin settings and bail if disabled
$disabled = $this->parseOverrideParam('avatax_disable_tax_calculation');
$enabled = $this->parseOverrideParam('avatax_force_tax_calculation');

if((!$this->settings->enableTaxCalculation || $disabled) && !$enabled)
{
Avatax::info(__FUNCTION__.'(): Tax Calculation is disabled.');

Expand Down Expand Up @@ -774,4 +778,14 @@ private function getAddressSignature(Address $address)

return md5($address1.$address2.$city.$state.$zipCode.$country);
}

/**
* Parse override form parameters
*/
private function parseOverrideParam($param)
{
$value = Craft::$app->getRequest()->getParam($param);

return filter_var($value, FILTER_VALIDATE_BOOLEAN);
}
}

0 comments on commit 3381744

Please sign in to comment.