Taxjar_Salestaxautomation - Version 1.4.0

Version Notes

* Fix SQLSTATE constraint error when importing new rates and creating tax rules.
* Fix background exception when rendering list of imported states.
* Cache Magento region query while importing rates to improve performance.
* Provide more extension help and links.

Download this release

Release Info

Developer TaxJar
Extension Taxjar_Salestaxautomation
Version 1.4.0
Comparing to
See all releases


Code changes from version 1.3.0 to 1.4.0

app/code/community/Taxjar/SalesTax/Helper/Data.php CHANGED
@@ -5,7 +5,6 @@
5
  *
6
  * @author Taxjar (support@taxjar.com)
7
  */
8
- class Taxjar_SalesTax_Helper_Data extends Mage_Core_Helper_Abstract
9
- {
10
 
11
  }
5
  *
6
  * @author Taxjar (support@taxjar.com)
7
  */
8
+ class Taxjar_SalesTax_Helper_Data extends Mage_Core_Helper_Abstract {
 
9
 
10
  }
app/code/community/Taxjar/SalesTax/Model/Calculation.php CHANGED
@@ -37,4 +37,4 @@ class Taxjar_SalesTax_Model_Calculation extends Mage_Tax_Model_Resource_Calculat
37
  }
38
 
39
  }
40
- ?>
37
  }
38
 
39
  }
40
+
app/code/community/Taxjar/SalesTax/Model/Client.php CHANGED
@@ -24,7 +24,6 @@ class Taxjar_SalesTax_Model_Client {
24
  else {
25
  throw new Exception('Could not connect to TaxJar.');
26
  }
27
-
28
  }
29
 
30
  /**
@@ -43,4 +42,3 @@ class Taxjar_SalesTax_Model_Client {
43
 
44
  }
45
 
46
- ?>
24
  else {
25
  throw new Exception('Could not connect to TaxJar.');
26
  }
 
27
  }
28
 
29
  /**
42
 
43
  }
44
 
 
app/code/community/Taxjar/SalesTax/Model/Comment.php CHANGED
@@ -18,7 +18,7 @@ class Taxjar_SalesTax_Model_Comment {
18
  $regionCode = Mage::getModel('directory/region')->load( $regionId )->getCode();
19
  $lastUpdate = Mage::getStoreConfig('taxjar/config/last_update');
20
 
21
- if( ! empty( $lastUpdate ) ){
22
  $states = unserialize( Mage::getStoreConfig('taxjar/config/states') );
23
  $statesHtml = $this->buildStatesHtml( $states, $regionCode );
24
  return $this->buildInstalledHtml( $statesHtml, $lastUpdate );
@@ -72,7 +72,7 @@ class Taxjar_SalesTax_Model_Comment {
72
  * @return $string
73
  */
74
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
75
- $htmlString = "<p class='note'><span>TaxJar is installed. Check the Manage Tax Rules section to verify all installed states.</span></p><br/><p>TaxJar has <em>automatically</em> added rates for the following states to your Magento installation:<br/><ul class='messages'>". $statesHtml . "</ul>To manage your TaxJar states <a href='https://app.taxjar.com/account#states' target='_blank'>click here</a>.</p><p>Your sales tax rates were last updated on: <ul class='messages'><li class='info-msg'><ul><li><span style='font-size: 1.4em;'>" . $lastUpdate . "</span></li></ul></li></ul><small>Rates may be automatically or manually updated again once per month. Contact support@taxjar.com with the email address registered to your TaxJar account if you need assistance.</small></p><p><small>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all tax rates in your Magento store. You can then uninstall in the Magento Connect Manager.<small></p><p><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</p>";
76
  return $htmlString;
77
  }
78
 
@@ -83,7 +83,7 @@ class Taxjar_SalesTax_Model_Comment {
83
  * @return $string
84
  */
85
  private function buildNotYetInstalledHtml( $regionName ) {
86
- $htmlString = "<p class='note'><span>Enter your TaxJar API Token</span></p><br/><p>Enter your TaxJar API Token to import current sales tax rates for all zip codes in " . $regionName . ", your state of origin as set in Shipping Settings. We will also retrieve all other states from your TaxJar account. To get an API Token, go to <a href='https://app.taxjar.com/account' target='_blank'>TaxJar's Account Screen.</a></p><p>For more information on how your tax settings are changed, <a href='http://taxjar.com/magento/tax-settings' target='_blank'>click here</a>.</p><p><small><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</small></p>";
87
  return $htmlString;
88
  }
89
 
@@ -95,23 +95,27 @@ class Taxjar_SalesTax_Model_Comment {
95
  */
96
  private function buildStatesHtml( $states, $regionCode ) {
97
  $states[] = $regionCode;
 
 
98
  sort( $states );
 
99
  $taxRatesByState = $this->getNumberOfRatesLoaded( $states );
 
100
  foreach ( array_unique( $states ) as $state ) {
101
  if ( ( $stateName = $this->fullStateName( $state ) ) && ! empty( $stateName ) ){
102
- if ( $taxRatesByState["rates_by_state"][$state] == 1 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ){
103
- $totalForState = 'Origin-based rates set';
104
- $class = 'success';
105
- }
106
- elseif ( $taxRatesByState["rates_by_state"][$state] == 0 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ) {
107
- $class = 'error';
108
- $totalForState = '<a href="https://app.taxjar.com/account#states" target="_blank">Click here</a> and add a zip code for this state to load rates.';
109
- }
110
- else {
111
- $class = 'success';
112
- $totalForState = $taxRatesByState["rates_by_state"][$state] . " rates";
113
- }
114
- $statesHtml .= '<li class="' . $class . '-msg"><ul><li><span style="font-size: 1.4em;">' . $stateName . '</span>: ' . $totalForState . '</li></ul></li>';
115
  }
116
  };
117
 
@@ -128,4 +132,4 @@ class Taxjar_SalesTax_Model_Comment {
128
  }
129
 
130
  }
131
- ?>
18
  $regionCode = Mage::getModel('directory/region')->load( $regionId )->getCode();
19
  $lastUpdate = Mage::getStoreConfig('taxjar/config/last_update');
20
 
21
+ if ( ! empty( $lastUpdate ) ) {
22
  $states = unserialize( Mage::getStoreConfig('taxjar/config/states') );
23
  $statesHtml = $this->buildStatesHtml( $states, $regionCode );
24
  return $this->buildInstalledHtml( $statesHtml, $lastUpdate );
72
  * @return $string
73
  */
74
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
75
+ $htmlString = "<p class='note'><span>TaxJar is installed. Check the <a href='" . Mage::helper('adminhtml')->getUrl('adminhtml/tax_rule/index') . "'>Manage Tax Rules section</a> to verify all installed states.</span></p><br/><p>TaxJar has <em>automatically</em> added rates for the following states to your Magento installation:<br/><ul class='messages'>". $statesHtml . "</ul>To manage your TaxJar states <a href='https://app.taxjar.com/account#states' target='_blank'>click here</a>.</p><p>Your sales tax rates were last updated on: <ul class='messages'><li class='info-msg'><ul><li><span style='font-size: 1.4em;'>" . $lastUpdate . "</span></li></ul></li></ul><small>Rates may be automatically or manually updated again once per month. For more information on how your tax settings are changed, <a href='http://taxjar.com/magento/tax-settings' target='_blank'>click here</a>. Contact <a href='mailto:support@taxjar.com'>support@taxjar.com</a> with the email address registered to your TaxJar account if you need assistance.</small></p><p><small>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all tax rates in your Magento store. You can then uninstall in the Magento Connect Manager.<small></p><p><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</p>";
76
  return $htmlString;
77
  }
78
 
83
  * @return $string
84
  */
85
  private function buildNotYetInstalledHtml( $regionName ) {
86
+ $htmlString = "<p class='note'><span>Enter your TaxJar API Token</span></p><br/><p>Enter your TaxJar API Token to import current sales tax rates for all zip codes in <b>" . $regionName . "</b>, your state of origin as set in <a href='" . Mage::helper('adminhtml')->getUrl('adminhtml/system_config/edit/section/shipping') . "'>Shipping Settings</a>. We will also retrieve all other states from your TaxJar account. To get an API Token, go to <a href='https://app.taxjar.com/account' target='_blank'>TaxJar's Account Screen.</a></p><p>For more information on how your tax settings are changed, <a href='http://taxjar.com/magento/tax-settings' target='_blank'>click here</a>.</p><p><small><strong>Important Notice</strong>: Your API key may be used to install rates on only <em>one</em> Magento installation at a time.</small></p>";
87
  return $htmlString;
88
  }
89
 
95
  */
96
  private function buildStatesHtml( $states, $regionCode ) {
97
  $states[] = $regionCode;
98
+ $statesHtml = '';
99
+
100
  sort( $states );
101
+
102
  $taxRatesByState = $this->getNumberOfRatesLoaded( $states );
103
+
104
  foreach ( array_unique( $states ) as $state ) {
105
  if ( ( $stateName = $this->fullStateName( $state ) ) && ! empty( $stateName ) ){
106
+ if ( $taxRatesByState["rates_by_state"][$state] == 1 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ){
107
+ $totalForState = 'Origin-based rates set';
108
+ $class = 'success';
109
+ }
110
+ elseif ( $taxRatesByState["rates_by_state"][$state] == 0 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ) {
111
+ $class = 'error';
112
+ $totalForState = '<a href="https://app.taxjar.com/account#states" target="_blank">Click here</a> and add a zip code for this state to load rates.';
113
+ }
114
+ else {
115
+ $class = 'success';
116
+ $totalForState = $taxRatesByState["rates_by_state"][$state] . " rates";
117
+ }
118
+ $statesHtml .= '<li class="' . $class . '-msg"><ul><li><span style="font-size: 1.4em;">' . $stateName . '</span>: ' . $totalForState . '</li></ul></li>';
119
  }
120
  };
121
 
132
  }
133
 
134
  }
135
+
app/code/community/Taxjar/SalesTax/Model/Configuration.php CHANGED
@@ -328,4 +328,4 @@ class Taxjar_SalesTax_Model_Configuration {
328
  }
329
 
330
  }
331
- ?>
328
  }
329
 
330
  }
331
+
app/code/community/Taxjar/SalesTax/Model/Debug.php CHANGED
@@ -43,4 +43,4 @@ class Taxjar_SalesTax_Model_Debug {
43
  }
44
 
45
  }
46
- ?>
43
  }
44
 
45
  }
46
+
app/code/community/Taxjar/SalesTax/Model/Observer.php CHANGED
@@ -103,12 +103,14 @@ class Taxjar_SalesTax_Model_Observer {
103
 
104
  foreach( $ratesJson as $rateJson ) {
105
  $rateIdWithShippingId = $rate->create( $rateJson );
 
 
 
 
106
 
107
  if ( $rateIdWithShippingId[1] ) {
108
  $this->freightTaxableRates[] = $rateIdWithShippingId[1];
109
  }
110
-
111
- $this->newRates[] = $rateIdWithShippingId[0];
112
  }
113
 
114
  $this->setLastUpdateDate( date( 'm-d-Y' ) );
@@ -138,7 +140,6 @@ class Taxjar_SalesTax_Model_Observer {
138
  elseif ( $type == 'rates' ) {
139
  return $prefix . 'get_rates/' . $this->regionCode . '/' . $this->storeZip;
140
  }
141
-
142
  }
143
 
144
  /**
@@ -152,20 +153,16 @@ class Taxjar_SalesTax_Model_Observer {
152
 
153
  foreach( $paths as $path ) {
154
  $existingRecords = Mage::getModel($path)->getCollection();
155
-
156
  foreach( $existingRecords as $record ) {
157
-
158
  try {
159
  $record->delete();
160
  }
161
  catch (Exception $e) {
162
  Mage::getSingleton('core/session')->addError("There was an error deleting from Magento model " . $path);
163
  }
164
-
165
  }
166
-
167
  }
168
-
169
  }
170
 
171
  /**
@@ -189,4 +186,4 @@ class Taxjar_SalesTax_Model_Observer {
189
  }
190
 
191
  }
192
- ?>
103
 
104
  foreach( $ratesJson as $rateJson ) {
105
  $rateIdWithShippingId = $rate->create( $rateJson );
106
+
107
+ if ( $rateIdWithShippingId[0] ) {
108
+ $this->newRates[] = $rateIdWithShippingId[0];
109
+ }
110
 
111
  if ( $rateIdWithShippingId[1] ) {
112
  $this->freightTaxableRates[] = $rateIdWithShippingId[1];
113
  }
 
 
114
  }
115
 
116
  $this->setLastUpdateDate( date( 'm-d-Y' ) );
140
  elseif ( $type == 'rates' ) {
141
  return $prefix . 'get_rates/' . $this->regionCode . '/' . $this->storeZip;
142
  }
 
143
  }
144
 
145
  /**
153
 
154
  foreach( $paths as $path ) {
155
  $existingRecords = Mage::getModel($path)->getCollection();
156
+
157
  foreach( $existingRecords as $record ) {
 
158
  try {
159
  $record->delete();
160
  }
161
  catch (Exception $e) {
162
  Mage::getSingleton('core/session')->addError("There was an error deleting from Magento model " . $path);
163
  }
 
164
  }
 
165
  }
 
166
  }
167
 
168
  /**
186
  }
187
 
188
  }
189
+
app/code/community/Taxjar/SalesTax/Model/Rate.php CHANGED
@@ -7,6 +7,12 @@
7
  */
8
  class Taxjar_SalesTax_Model_Rate {
9
 
 
 
 
 
 
 
10
  /**
11
  * Try to create the rate
12
  *
@@ -18,17 +24,24 @@ class Taxjar_SalesTax_Model_Rate {
18
  $zip = $rateJson['zip'];
19
  $regionCode = $rateJson['state'];
20
  $rate = $rateJson['rate'];
21
-
22
  if ( isset( $rateJson['country'] ) ) {
23
  $countryCode = $rateJson['country'];
24
  }
25
  else {
26
  $countryCode = 'US';
27
  }
28
-
29
- $regionId = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode)->getId();
 
 
 
 
 
 
 
 
30
  $rateModel = Mage::getModel('tax/calculation_rate');
31
-
32
  $rateModel->setTaxCountryId($countryCode);
33
  $rateModel->setTaxRegionId($regionId);
34
  $rateModel->setTaxPostcode($zip);
@@ -46,11 +59,11 @@ class Taxjar_SalesTax_Model_Rate {
46
  return array( $rateModel->getId(), $shippingRateId );
47
  }
48
  catch ( Exception $e ) {
49
- Mage::getSingleton('core/session')->addNotice("There was an error encountered while loading rate with code " . $rateModel->getCode() . ". This is most likely due to duplicate codes and can be safely ignored if lots of other rates were loaded. If the error persists, email support@taxjar.com with a screenshot of any Magento errors displayed." );
50
  unset( $rateModel );
51
  return;
52
  }
53
- }
54
-
55
  }
56
- ?>
7
  */
8
  class Taxjar_SalesTax_Model_Rate {
9
 
10
+ private $cache;
11
+
12
+ public function __construct() {
13
+ $this->cache = Mage::getSingleton('core/cache');
14
+ }
15
+
16
  /**
17
  * Try to create the rate
18
  *
24
  $zip = $rateJson['zip'];
25
  $regionCode = $rateJson['state'];
26
  $rate = $rateJson['rate'];
27
+
28
  if ( isset( $rateJson['country'] ) ) {
29
  $countryCode = $rateJson['country'];
30
  }
31
  else {
32
  $countryCode = 'US';
33
  }
34
+
35
+ if ($this->cache->load('regionId') && $regionCode == $this->cache->load('regionCode') && $countryCode == $this->cache->load('countryCode')) {
36
+ $regionId = $this->cache->load('regionId');
37
+ } else {
38
+ $regionId = Mage::getModel('directory/region')->loadByCode($regionCode, $countryCode)->getId();
39
+ $this->cache->save($regionId, 'regionId');
40
+ $this->cache->save($regionCode, 'regionCode');
41
+ $this->cache->save($countryCode, 'countryCode');
42
+ }
43
+
44
  $rateModel = Mage::getModel('tax/calculation_rate');
 
45
  $rateModel->setTaxCountryId($countryCode);
46
  $rateModel->setTaxRegionId($regionId);
47
  $rateModel->setTaxPostcode($zip);
59
  return array( $rateModel->getId(), $shippingRateId );
60
  }
61
  catch ( Exception $e ) {
62
+ Mage::getSingleton('core/session')->addNotice( "There was an error encountered while loading rate with code " . $rateModel->getCode() . ". This is most likely due to duplicate codes and can be safely ignored if lots of other rates were loaded. If the error persists, email support@taxjar.com with a screenshot of any Magento errors displayed." );
63
  unset( $rateModel );
64
  return;
65
  }
66
+ }
67
+
68
  }
69
+
app/code/community/Taxjar/SalesTax/Model/Rule.php CHANGED
@@ -32,4 +32,4 @@ class Taxjar_SalesTax_Model_Rule {
32
  }
33
 
34
  }
35
- ?>
32
  }
33
 
34
  }
35
+
package.xml CHANGED
@@ -1,19 +1,21 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Taxjar_Salestaxautomation</name>
4
- <version>1.3.0</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Easily collect sales tax without altering your Magento store&#x2019;s checkout experience or performance.</summary>
10
  <description>TaxJar for Magento allows you to install rates for multiple origin or destination-based states without affecting your store's checkout experience.</description>
11
- <notes>* Adds support for zip plus four rate calculations to Magento.&#xD;
12
- * Rates may now only be installed on one Magento installation at a time.</notes>
 
 
13
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
14
- <date>2015-03-10</date>
15
- <time>13:48:00</time>
16
- <contents><target name="magecommunity"><dir name="Taxjar"><dir name="SalesTax"><dir name="Helper"><file name="Data.php" hash="565812e7d6927df4c91bfb69b79b1b09"/></dir><dir name="Model"><file name="Calculation.php" hash="170fd255c7bdf2d3d7cfa258e08dcc91"/><file name="Client.php" hash="6c3339bcc33670b0d41ded468b72e77b"/><file name="Comment.php" hash="b02f877f10934f3596215fbc6a4ce08e"/><file name="Configuration.php" hash="1ed6e9467ac8c5ca6e906753071a9161"/><file name="Debug.php" hash="096b1fb2e45e808845d50f2ad371953a"/><file name="Observer.php" hash="fd0a35937096c2d8b6eb97405eb54460"/><file name="Rate.php" hash="30b07e73624405c5acba6965c0f6b2f6"/><file name="Rule.php" hash="ae33149080b3182e62b56607f7b30da4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="60802c2569b2a5b7178d527e35d43175"/><file name="system.xml" hash="8dc55519eef0349d487f4039eabda164"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Taxjar_SalesTax.xml" hash="60b211e28d8b9d4cc49d1dd746d4aa46"/></dir></target></contents>
17
  <compatible/>
18
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
19
  </package>
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Taxjar_Salestaxautomation</name>
4
+ <version>1.4.0</version>
5
  <stability>stable</stability>
6
  <license>MIT</license>
7
  <channel>community</channel>
8
  <extends/>
9
  <summary>Easily collect sales tax without altering your Magento store&#x2019;s checkout experience or performance.</summary>
10
  <description>TaxJar for Magento allows you to install rates for multiple origin or destination-based states without affecting your store's checkout experience.</description>
11
+ <notes>* Fix SQLSTATE constraint error when importing new rates and creating tax rules.&#xD;
12
+ * Fix background exception when rendering list of imported states.&#xD;
13
+ * Cache Magento region query while importing rates to improve performance.&#xD;
14
+ * Provide more extension help and links.</notes>
15
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
16
+ <date>2015-11-10</date>
17
+ <time>22:22:45</time>
18
+ <contents><target name="magecommunity"><dir name="Taxjar"><dir name="SalesTax"><dir name="Helper"><file name="Data.php" hash="ac18fc627650990eac98f5627ff51749"/></dir><dir name="Model"><file name="Calculation.php" hash="8ed668d8db488d7e48bef11434f09060"/><file name="Client.php" hash="fd88676a448fd29e2fffff08e460e0ca"/><file name="Comment.php" hash="d57814eb90d75a6929bdc648a31bb40d"/><file name="Configuration.php" hash="4cca6c1cd99a0feab9f359cdfddfb028"/><file name="Debug.php" hash="3b91c9036dd3aedc806644d34503e0a7"/><file name="Observer.php" hash="7c000d433041a238f9ee71ef80f21f5e"/><file name="Rate.php" hash="1171640b851841ce6d325e21ce1b1601"/><file name="Rule.php" hash="0175c047a5d2052bb8ba21242981e9ac"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="60802c2569b2a5b7178d527e35d43175"/><file name="system.xml" hash="8dc55519eef0349d487f4039eabda164"/></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Taxjar_SalesTax.xml" hash="60b211e28d8b9d4cc49d1dd746d4aa46"/></dir></target></contents>
19
  <compatible/>
20
  <dependencies><required><php><min>5.0.0</min><max>6.0.0</max></php></required></dependencies>
21
  </package>