Skip to content

Commit

Permalink
Merge pull request #52 from surprisehighway/release/v4.0.0
Browse files Browse the repository at this point in the history
Release/v4.0.0
  • Loading branch information
imagehat authored Aug 5, 2024
2 parents 27ad6fa + dc90553 commit 98cb3c8
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 78 deletions.
1 change: 0 additions & 1 deletion .craftplugin

This file was deleted.

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/).

## 4.0.0 - 2024-07-29
### Added
- Craft 5 compatibility.

## 3.0.2 - 2024-07-29
### Changed
- Updated Avatax SDK to latest
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Avatax plugin for Craft CMS 4.x
# Avatax plugin for Craft CMS 5.x

Calculate and add sales tax to an order's base tax using Avalara's AvaTax service.

Expand All @@ -8,7 +8,7 @@ Calculate and add sales tax to an order's base tax using Avalara's AvaTax servic

## Requirements

This plugin requires Craft 4 and Commerce 4.0 or later.
This plugin requires Craft 5 and Commerce 5 or later.

## Installation

Expand Down Expand Up @@ -79,6 +79,10 @@ After completing the installation and configuration, AvaTax will calculate and a

![Avatax Tax Category Settings](resources/img/product-category.png)

> **Craft 5 Hint:** The Tax Category dropdown is no longer in the product details sidebar. You have to double-click a Variant to see see the Tax and Shipping Categories in the Variant flyout (and make sure the sidebar is visible). If you don't need to be able to use different Tax Categories for different products make sure Avatax is your default.
![Avatax Tax Category Settings](resources/img/product-category-craft5.png)

## Tax Codes

*E.g. 'P0000000' - Tangible personal property (TPP)*.
Expand Down
12 changes: 7 additions & 5 deletions 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": "3.0.2",
"version": "4.0.0",
"keywords": [
"craft",
"cms",
Expand All @@ -22,9 +22,11 @@
}
],
"require": {
"craftcms/commerce": "^4.0",
"craftcms/cms": "^4.0",
"avalara/avataxclient": "^22|^23|^24"
"php": "^8.2",
"avalara/avataxclient": "^24",
"craftcms/cms": "^5.0.0-beta.10",
"craftcms/commerce": "^5.0.0-beta.1"

},
"repositories": [
{
Expand Down Expand Up @@ -55,7 +57,7 @@
"craftcms/plugin-installer": true
},
"platform": {
"php": "8.0.2"
"php": "8.2"
}
}
}
Binary file added resources/img/product-category-craft5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
123 changes: 54 additions & 69 deletions src/Avatax.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use craft\fields\Dropdown;
use craft\fields\PlainText;
use craft\helpers\UrlHelper;
use craft\models\FieldGroup;
use craft\services\Plugins;
use craft\web\UrlManager;

Expand Down Expand Up @@ -231,84 +230,70 @@ public function onAfterInstall()
}
}

// Create an "avatax field group"
$group = new FieldGroup();
$group->name = 'Avatax';
// Create avataxTaxCode field
$field = Craft::$app->fields->createField([
'name' => 'AvaTax Tax Code',
'handle' => 'avataxTaxCode',
'type' => PlainText::class,
'instructions' => 'Specify an [Avalara Tax Code](https://taxcode.avatax.avalara.com) to use for this product.',
'settings' => [
'placeholder' => '',
'multiline' => false,
'initialRows' => '4',
'charLimit' => null,
]
]);

if( Craft::$app->fields->saveGroup($group) )
if (Craft::$app->fields->saveField($field))
{
Craft::info('Avatax field group created successfully.', 'avatax');

// Create avataxTaxCode field
$field = Craft::$app->fields->createField([
'groupId' => $group->id,
'name' => 'AvaTax Tax Code',
'handle' => 'avataxTaxCode',
'type' => PlainText::class,
'instructions' => 'Specify an [Avalara Tax Code](https://taxcode.avatax.avalara.com) to use for this product.',
'settings' => [
'placeholder' => '',
'multiline' => false,
'initialRows' => '4',
'charLimit' => null,
]
]);

if (Craft::$app->fields->saveField($field))
{
Craft::info('Avatax Tax Code field created successfully.', 'avatax');
}
else
{
Craft::warning('Could not save the Avatax Tax Code field.', 'avatax');
}
Craft::info('Avatax Tax Code field created successfully.', 'avatax');
}
else
{
Craft::warning('Could not save the Avatax Tax Code field.', 'avatax');
}

// Create avataxCustomerUsageType field
$field = Craft::$app->fields->createField([
'groupId' => $group->id,
'name' => 'AvaTax Customer Usage Type',
'handle' => 'avataxCustomerUsageType',
'type' => Dropdown::class,
'instructions' => 'Select an [Entity/Use Code](https://help.avalara.com/000_Avalara_AvaTax/Exemption_Reason_Matrices_for_US_and_Canada) to exempt this customer from tax.',
'settings' => [
'options' => [
['label' => '', 'value' => '', 'default' => ''],
['label' => 'A. Federal government (United States)', 'value' => 'A', 'default' => ''],
['label' => 'B. State government (United States)', 'value' => 'B', 'default' => ''],
['label' => 'C. Tribe / Status Indian / Indian Band (both)', 'value' => 'C', 'default' => ''],
['label' => 'D. Foreign diplomat (both)', 'value' => 'D', 'default' => ''],
['label' => 'E. Charitable or benevolent org (both)', 'value' => 'E', 'default' => ''],
['label' => 'F. Religious or educational org (both)', 'value' => 'F', 'default' => ''],
['label' => 'G. Resale (both)', 'value' => 'G', 'default' => ''],
['label' => 'H. Commercial agricultural production (both)', 'value' => 'H', 'default' => ''],
['label' => 'I. Industrial production / manufacturer (both)', 'value' => 'I', 'default' => ''],
['label' => 'J. Direct pay permit (United States)', 'value' => 'J', 'default' => ''],
['label' => 'K. Direct mail (United States)', 'value' => 'K', 'default' => ''],
['label' => 'L. Other (both)', 'value' => 'L', 'default' => ''],
['label' => 'M. Not Used', 'value' => 'M', 'default' => ''],
['label' => 'N. Local government (United States)', 'value' => 'N', 'default' => ''],
['label' => 'O. Not Used', 'value' => 'O', 'default' => ''],
['label' => 'P. Commercial aquaculture (Canada)', 'value' => 'P', 'default' => ''],
['label' => 'Q. Commercial Fishery (Canada)', 'value' => 'Q', 'default' => ''],
['label' => 'R. Non-resident (Canada)', 'value' => 'R', 'default' => ''],
]
// Create avataxCustomerUsageType field
$field = Craft::$app->fields->createField([
'name' => 'AvaTax Customer Usage Type',
'handle' => 'avataxCustomerUsageType',
'type' => Dropdown::class,
'instructions' => 'Select an [Entity/Use Code](https://knowledge.avalara.com/bundle/dqa1657870670369_dqa1657870670369/page/Exempt_reason_matrix_for_the_U.S._and_Canada_entity_use_code_list.html#pus1650667484575) to exempt this customer from tax.',
'settings' => [
'options' => [
['label' => '', 'value' => '', 'default' => ''],
['label' => 'A. Federal government (United States)', 'value' => 'A', 'default' => ''],
['label' => 'B. State government (United States)', 'value' => 'B', 'default' => ''],
['label' => 'C. Tribe / Status Indian / Indian Band (both)', 'value' => 'C', 'default' => ''],
['label' => 'D. Foreign diplomat (both)', 'value' => 'D', 'default' => ''],
['label' => 'E. Charitable or benevolent org (both)', 'value' => 'E', 'default' => ''],
['label' => 'F. Religious or educational org (both)', 'value' => 'F', 'default' => ''],
['label' => 'G. Resale (both)', 'value' => 'G', 'default' => ''],
['label' => 'H. Commercial agricultural production (both)', 'value' => 'H', 'default' => ''],
['label' => 'I. Industrial production / manufacturer (both)', 'value' => 'I', 'default' => ''],
['label' => 'J. Direct pay permit (United States)', 'value' => 'J', 'default' => ''],
['label' => 'K. Direct mail (United States)', 'value' => 'K', 'default' => ''],
['label' => 'L. Other (both)', 'value' => 'L', 'default' => ''],
['label' => 'M. Not Used', 'value' => 'M', 'default' => ''],
['label' => 'N. Local government (United States)', 'value' => 'N', 'default' => ''],
['label' => 'O. Not Used', 'value' => 'O', 'default' => ''],
['label' => 'P. Commercial aquaculture (Canada)', 'value' => 'P', 'default' => ''],
['label' => 'Q. Commercial Fishery (Canada)', 'value' => 'Q', 'default' => ''],
['label' => 'R. Non-resident (Canada)', 'value' => 'R', 'default' => ''],
]
]);
]
]);

if (Craft::$app->fields->saveField($field))
{
Craft::info('Avatax Customer Usage Type field created successfully.', 'Avatax');
}
else
{
Craft::warning('Could not save the Avatax Customer Usage Type field.', 'Avatax');
}
if (Craft::$app->fields->saveField($field))
{
Craft::info('Avatax Customer Usage Type field created successfully.', 'Avatax');
}
else
{
Craft::warning('Could not save the Avatax field group. ', 'Avatax');
Craft::warning('Could not save the Avatax Customer Usage Type field.', 'Avatax');
}


if (Craft::$app->getRequest()->getIsConsoleRequest()) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assetbundles/avatax/dist/js/Avatax.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Avatax.settings = {
'<div class="body">'+message+'</div>' +
'<div class="footer">' +
'<div class="buttons right">' +
'<input type="button" class="btn modal-cancel" value="Done"/>' +
'<button type="button" class="btn modal-cancel"><label>Done</label></button>' +
'</div>' +
'</div>' +
'</div>';
Expand Down

0 comments on commit 98cb3c8

Please sign in to comment.