Taxjar_Salestaxautomation - Version 1.2.0

Version Notes

This release offers the following:
* Bug fixes with displaying admin view

Download this release

Release Info

Developer TaxJar
Extension Taxjar_Salestaxautomation
Version 1.2.0
Comparing to
See all releases


Code changes from version 1.1.1 to 1.2.0

app/code/community/Taxjar/SalesTax/Model/Comment.php CHANGED
@@ -18,6 +18,9 @@ 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 );
@@ -29,6 +32,31 @@ class Taxjar_SalesTax_Model_Comment {
29
 
30
  }
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  /**
33
  * Build String from State Abbr
34
  *
@@ -47,7 +75,7 @@ class Taxjar_SalesTax_Model_Comment {
47
  * @return $string
48
  */
49
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
50
- $htmlString = "<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></p><p>If you would like to uninstall TaxJar, remove the API Token from the box above, then save the config. This will remove all the rates. You can then uninstall in the Magento Connect Manager.</p>";
51
  return $htmlString;
52
  }
53
 
@@ -58,7 +86,7 @@ class Taxjar_SalesTax_Model_Comment {
58
  * @return $string
59
  */
60
  private function buildNotYetInstalledHtml( $regionName ) {
61
- $htmlString = "<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>";
62
  return $htmlString;
63
  }
64
 
@@ -71,13 +99,34 @@ class Taxjar_SalesTax_Model_Comment {
71
  private function buildStatesHtml( $states, $regionCode ) {
72
  $states[] = $regionCode;
73
  sort( $states );
74
-
75
  foreach ( array_unique( $states ) as $state ) {
76
  if ( ( $stateName = $this->fullStateName( $state ) ) && ! empty( $stateName ) ){
77
- $statesHtml .= '<li class="success-msg"><ul><li><span style="font-size: 1.4em;">' . $stateName . '</span></li></ul></li>';
 
 
 
 
 
 
 
 
 
 
 
 
78
  }
79
  };
80
 
 
 
 
 
 
 
 
 
 
81
  return $statesHtml;
82
  }
83
 
18
  $regionCode = Mage::getModel('directory/region')->load( $regionId )->getCode();
19
  $lastUpdate = Mage::getStoreConfig('taxjar/config/last_update');
20
 
21
+ // Plugin detect that state of nexus isn't in rates
22
+ // You should have at least X rates
23
+
24
  if( ! empty( $lastUpdate ) ){
25
  $states = unserialize( Mage::getStoreConfig('taxjar/config/states') );
26
  $statesHtml = $this->buildStatesHtml( $states, $regionCode );
32
 
33
  }
34
 
35
+ /**
36
+ * Get the number of rates loaded
37
+ *
38
+ * @param void
39
+ * @return $array
40
+ */
41
+ private function getNumberOfRatesLoaded( $states ) {
42
+ $rates = Mage::getModel("tax/calculation_rate");
43
+ $stateRatesLoadedCount = 0;
44
+ $ratesByState = array();
45
+ foreach ( array_unique( $states ) as $state ) {
46
+ $regionModel = Mage::getModel('directory/region')->loadByCode($state, 'US');
47
+ $regionId = $regionModel->getId();
48
+ $ratesByState[$state] = $rates->getCollection()->addFieldToFilter( 'tax_region_id', array( 'eq' => $regionId ) )->getSize();
49
+ }
50
+
51
+ $rateCalcs = array(
52
+ "total_rates" => array_sum($ratesByState),
53
+ "rates_loaded" => Mage::getModel("tax/calculation_rate")->getCollection()->getSize(),
54
+ "rates_by_state" => $ratesByState
55
+ );
56
+
57
+ return $rateCalcs;
58
+ }
59
+
60
  /**
61
  * Build String from State Abbr
62
  *
75
  * @return $string
76
  */
77
  private function buildInstalledHtml( $statesHtml, $lastUpdate ) {
78
+ $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>";
79
  return $htmlString;
80
  }
81
 
86
  * @return $string
87
  */
88
  private function buildNotYetInstalledHtml( $regionName ) {
89
+ $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>";
90
  return $htmlString;
91
  }
92
 
99
  private function buildStatesHtml( $states, $regionCode ) {
100
  $states[] = $regionCode;
101
  sort( $states );
102
+ $taxRatesByState = $this->getNumberOfRatesLoaded( $states );
103
  foreach ( array_unique( $states ) as $state ) {
104
  if ( ( $stateName = $this->fullStateName( $state ) ) && ! empty( $stateName ) ){
105
+ if ( $taxRatesByState["rates_by_state"][$state] == 1 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ){
106
+ $totalForState = 'Origin-based rates set';
107
+ $class = 'success';
108
+ }
109
+ elseif ( $taxRatesByState["rates_by_state"][$state] == 0 && ( $taxRatesByState['rates_loaded'] == $taxRatesByState['total_rates'] ) ) {
110
+ $class = 'error';
111
+ $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.';
112
+ }
113
+ else {
114
+ $class = 'success';
115
+ $totalForState = $taxRatesByState["rates_by_state"][$state] . " rates";
116
+ }
117
+ $statesHtml .= '<li class="' . $class . '-msg"><ul><li><span style="font-size: 1.4em;">' . $stateName . '</span>: ' . $totalForState . '</li></ul></li>';
118
  }
119
  };
120
 
121
+ if ( $taxRatesByState['rates_loaded'] != $taxRatesByState['total_rates'] ) {
122
+ $matches = 'error';
123
+ }
124
+ else {
125
+ $matches = 'success';
126
+ }
127
+
128
+ $statesHtml .= '<p class="' . $matches . '-msg" style="background: none !important;"><small>&nbsp;&nbsp;' . $taxRatesByState['total_rates'] . ' of ' . $taxRatesByState['rates_loaded'] . ' expected rates loaded.</small></p>';
129
+
130
  return $statesHtml;
131
  }
132
 
app/code/community/Taxjar/SalesTax/Model/Debug.php ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * TaxJar Debug UI
5
+ *
6
+ * @author Taxjar (support@taxjar.com)
7
+ */
8
+ class Taxjar_SalesTax_Model_Debug {
9
+
10
+ /**
11
+ * Display debug information
12
+ *
13
+ * @param void
14
+ * @return $string
15
+ */
16
+ public function getCommentText() {
17
+ $debug = Mage::getStoreConfig('taxjar/config/debug');
18
+
19
+ if ( $debug ) {
20
+ return "<p class='note'><span>If enabled, does not alter your tax rates or database and instead prints debug messages for use with TaxJar support.</span></p><br/>" . $this->getDebugHtmlString();
21
+ }
22
+ else {
23
+ return "<p class='note'><span>If enabled, does not alter your tax rates or database and instead prints debug messages for use with TaxJar support.</span></p>";
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Gather debug information
29
+ *
30
+ * @param void
31
+ * @return $string
32
+ */
33
+ private function getDebugHtmlString() {
34
+ $states = implode( ',', unserialize( Mage::getStoreConfig('taxjar/config/states') ) );
35
+ $apiUser = Mage::getModel('api/user');
36
+ $existingUserId = $apiUser->load('taxjar', 'username')->getUserId();
37
+ $pluginVersion = '1.2.0';
38
+ $phpMemory = @ini_get('memory_limit');
39
+ $phpVersion = @phpversion();
40
+ $magentoVersion = Mage::getVersion();
41
+ $lastUpdated = Mage::getStoreConfig('taxjar/config/last_update');
42
+ return "<ul> <li><strong>Additonal States:</strong> ". $states ."</li> <li><strong>API User ID:</strong> ". $existingUserId ."</li><li><strong>Memory:</strong> ". $phpMemory ."</li> <li><strong>TaxJar Version:</strong> ". $pluginVersion ."</li> <li><strong>PHP Version</strong> ". $phpVersion ."</li> <li><strong>Magento Version:</strong> ". $magentoVersion ."</li> <li><strong>Last Updated:</strong> ". $lastUpdated ."</li> </ul><br/><p><small><strong>Include the above information when emailing TaxJar support at support@taxjar.com</strong><small></p>";
43
+ }
44
+
45
+ }
46
+ ?>
app/code/community/Taxjar/SalesTax/Model/Observer.php CHANGED
@@ -23,10 +23,12 @@ class Taxjar_SalesTax_Model_Observer {
23
  $this->version = 'v1';
24
  $client = Mage::getModel('taxjar/client');
25
  $configuration = Mage::getModel('taxjar/configuration');
 
26
  $regionId = Mage::getStoreConfig('shipping/origin/region_id', $storeId);
27
  $this->storeZip = Mage::getStoreConfig('shipping/origin/postcode', $storeId);
28
  $this->regionCode = Mage::getModel('directory/region')->load( $regionId )->getCode();
29
  $validZip = preg_match( "/(\d{5}-\d{4})|(\d{5})/", $this->storeZip );
 
30
 
31
  if( isset( $this->regionCode ) ) {
32
  $configJson = $client->getResource( $apiKey, $this->apiUrl( 'config' ) );
@@ -35,7 +37,14 @@ class Taxjar_SalesTax_Model_Observer {
35
  throw new Exception( "Please check that you have set a Region/State in Shipping Settings." );
36
  }
37
 
38
- if( ! $configJson['allow_update'] ) {
 
 
 
 
 
 
 
39
  return;
40
  }
41
 
@@ -66,6 +75,7 @@ class Taxjar_SalesTax_Model_Observer {
66
 
67
  }
68
  else {
 
69
  $this->purgeExisting();
70
  $this->setLastUpdateDate(NULL);
71
  }
@@ -110,6 +120,7 @@ class Taxjar_SalesTax_Model_Observer {
110
  }
111
 
112
  @unlink( $filename );
 
113
  }
114
 
115
  /**
@@ -119,7 +130,7 @@ class Taxjar_SalesTax_Model_Observer {
119
  * @return $string
120
  */
121
  private function apiUrl( $type ) {
122
- $apiHost = 'https://api.taxjar.com/';
123
  $prefix = $apiHost . 'magento/' . $this->version . '/';
124
 
125
  if ( $type == 'config' ) {
@@ -144,7 +155,13 @@ class Taxjar_SalesTax_Model_Observer {
144
  $existingRecords = Mage::getModel($path)->getCollection();
145
 
146
  foreach( $existingRecords as $record ) {
147
- $record->delete();
 
 
 
 
 
 
148
  }
149
 
150
  }
23
  $this->version = 'v1';
24
  $client = Mage::getModel('taxjar/client');
25
  $configuration = Mage::getModel('taxjar/configuration');
26
+ $debug = Mage::getModel('taxjar/debug');
27
  $regionId = Mage::getStoreConfig('shipping/origin/region_id', $storeId);
28
  $this->storeZip = Mage::getStoreConfig('shipping/origin/postcode', $storeId);
29
  $this->regionCode = Mage::getModel('directory/region')->load( $regionId )->getCode();
30
  $validZip = preg_match( "/(\d{5}-\d{4})|(\d{5})/", $this->storeZip );
31
+ $debug = Mage::getStoreConfig('taxjar/config/debug');
32
 
33
  if( isset( $this->regionCode ) ) {
34
  $configJson = $client->getResource( $apiKey, $this->apiUrl( 'config' ) );
37
  throw new Exception( "Please check that you have set a Region/State in Shipping Settings." );
38
  }
39
 
40
+ if ( $debug ) {
41
+ Mage::getSingleton('core/session')->addNotice("Debug mode enabled. Tax rates have not been altered.");
42
+ return;
43
+ }
44
+
45
+ if( ! $configJson['allow_update'] ) {
46
+ $dateUpdated = Mage::getStoreConfig('taxjar/config/last_update');
47
+ Mage::getSingleton('core/session')->addNotice("Your rates are already up to date. Date of last update: " . $dateUpdated);
48
  return;
49
  }
50
 
75
 
76
  }
77
  else {
78
+ Mage::getSingleton('core/session')->addNotice("TaxJar has been uninstalled. All tax rates have been removed.");
79
  $this->purgeExisting();
80
  $this->setLastUpdateDate(NULL);
81
  }
120
  }
121
 
122
  @unlink( $filename );
123
+ Mage::getSingleton('core/session')->addSuccess("TaxJar has added new rates to your database! Thanks for using TaxJar!");
124
  }
125
 
126
  /**
130
  * @return $string
131
  */
132
  private function apiUrl( $type ) {
133
+ $apiHost = 'http://tax-rate-service.dev/';
134
  $prefix = $apiHost . 'magento/' . $this->version . '/';
135
 
136
  if ( $type == 'config' ) {
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
  }
app/code/community/Taxjar/SalesTax/etc/config.xml CHANGED
@@ -6,7 +6,7 @@
6
  -->
7
  <config>
8
  <modules>
9
- <Taxjar_SalesTax><version>0.2.0</version></Taxjar_SalesTax>
10
  </modules>
11
  <global>
12
  <helpers>
6
  -->
7
  <config>
8
  <modules>
9
+ <Taxjar_SalesTax><version>1.2.0</version></Taxjar_SalesTax>
10
  </modules>
11
  <global>
12
  <helpers>
app/code/community/Taxjar/SalesTax/etc/system.xml CHANGED
@@ -1,30 +1,30 @@
1
  <?xml version="1.0"?>
2
  <config>
3
- <tabs>
4
- <taxjar translate="label" module="taxjar">
5
- <label>TaxJar</label>
6
- <sort_order>0</sort_order>
7
- </taxjar>
8
- </tabs>
9
- <sections>
10
- <taxjar translate="label" module="taxjar">
11
- <label>Sales Tax Automation</label>
12
- <tab>taxjar</tab>
13
- <frontend_type>text</frontend_type>
14
- <sort_order>1000</sort_order>
15
- <show_in_default>1</show_in_default>
16
- <show_in_website>1</show_in_website>
17
- <show_in_store>1</show_in_store>
18
- <groups>
19
- <config translate="label">
20
- <label>TaxJar Options</label>
21
- <frontend_type>text</frontend_type>
22
- <sort_order>1</sort_order>
23
- <show_in_default>1</show_in_default>
24
- <show_in_website>1</show_in_website>
25
- <show_in_store>1</show_in_store>
26
- <expanded>1</expanded>
27
- <fields>
28
  <apikey translate="label">
29
  <label>API Token</label>
30
  <comment>
@@ -35,10 +35,22 @@
35
  <show_in_default>1</show_in_default>
36
  <show_in_website>1</show_in_website>
37
  <show_in_store>1</show_in_store>
38
- </apikey>
39
- </fields>
40
- </config>
41
- </groups>
42
- </taxjar>
43
- </sections>
 
 
 
 
 
 
 
 
 
 
 
 
44
  </config>
1
  <?xml version="1.0"?>
2
  <config>
3
+ <tabs>
4
+ <taxjar translate="label" module="taxjar">
5
+ <label>TaxJar</label>
6
+ <sort_order>0</sort_order>
7
+ </taxjar>
8
+ </tabs>
9
+ <sections>
10
+ <taxjar translate="label" module="taxjar">
11
+ <label>Sales Tax Automation</label>
12
+ <tab>taxjar</tab>
13
+ <frontend_type>text</frontend_type>
14
+ <sort_order>1000</sort_order>
15
+ <show_in_default>1</show_in_default>
16
+ <show_in_website>1</show_in_website>
17
+ <show_in_store>1</show_in_store>
18
+ <groups>
19
+ <config translate="label">
20
+ <label>TaxJar Options</label>
21
+ <frontend_type>text</frontend_type>
22
+ <sort_order>1</sort_order>
23
+ <show_in_default>1</show_in_default>
24
+ <show_in_website>1</show_in_website>
25
+ <show_in_store>1</show_in_store>
26
+ <expanded>1</expanded>
27
+ <fields>
28
  <apikey translate="label">
29
  <label>API Token</label>
30
  <comment>
35
  <show_in_default>1</show_in_default>
36
  <show_in_website>1</show_in_website>
37
  <show_in_store>1</show_in_store>
38
+ </apikey>
39
+ <debug translate="label">
40
+ <label>Debug Mode Enabled</label>
41
+ <comment>
42
+ <model>taxjar/debug</model>
43
+ </comment>
44
+ <source_model>adminhtml/system_config_source_yesno</source_model>
45
+ <frontend_type>select</frontend_type>
46
+ <sort_order>10</sort_order>
47
+ <show_in_default>1</show_in_default>
48
+ <show_in_website>1</show_in_website>
49
+ <show_in_store>1</show_in_store>
50
+ </debug>
51
+ </fields>
52
+ </config>
53
+ </groups>
54
+ </taxjar>
55
+ </sections>
56
  </config>
package.xml CHANGED
@@ -1,7 +1,7 @@
1
  <?xml version="1.0"?>
2
  <package>
3
  <name>Taxjar_Salestaxautomation</name>
4
- <version>1.1.1</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
@@ -11,9 +11,9 @@
11
  <notes>This release offers the following:&#xD;
12
  * Bug fixes with displaying admin view</notes>
13
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
14
- <date>2014-11-07</date>
15
- <time>07:09:38</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="Client.php" hash="6c3339bcc33670b0d41ded468b72e77b"/><file name="Comment.php" hash="dd7125784055fae71dce3140a6092b02"/><file name="Configuration.php" hash="1ed6e9467ac8c5ca6e906753071a9161"/><file name="Observer.php" hash="ae343a43043edc2c49ef7ef7bc3f7b65"/><file name="Rate.php" hash="4f1f62e6696f10f34f58d7104936223d"/><file name="Rule.php" hash="ae33149080b3182e62b56607f7b30da4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="c5a45ce71a64756cf987fc9bd079ac67"/><file name="system.xml" hash="ee3a92f70e11453ffcac2ef985654669"/></dir><file name=".DS_Store" hash="f291190ac228acaede15fefc49edb6e5"/></dir><file name=".DS_Store" hash="e385b6a995c1af38f899669fa136a12e"/></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.2.0</version>
5
  <stability>stable</stability>
6
  <license>MITL</license>
7
  <channel>community</channel>
11
  <notes>This release offers the following:&#xD;
12
  * Bug fixes with displaying admin view</notes>
13
  <authors><author><name>TaxJar</name><user>taxjar</user><email>support@taxjar.com</email></author></authors>
14
+ <date>2014-11-24</date>
15
+ <time>20:54:37</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="Client.php" hash="6c3339bcc33670b0d41ded468b72e77b"/><file name="Comment.php" hash="a854d09dcee27dae6b5beb43dcb8c11e"/><file name="Configuration.php" hash="1ed6e9467ac8c5ca6e906753071a9161"/><file name="Debug.php" hash="8eb2ce15c54b7e6e98cb23291c3104e1"/><file name="Observer.php" hash="2ac532260bef0c56a0247b688978f6ad"/><file name="Rate.php" hash="4f1f62e6696f10f34f58d7104936223d"/><file name="Rule.php" hash="ae33149080b3182e62b56607f7b30da4"/></dir><dir name="etc"><file name="adminhtml.xml" hash="4ea028ad6b00688d99531597e8d3c404"/><file name="config.xml" hash="6305f88837a4f4b34541dfdb7fe6886c"/><file name="system.xml" hash="8dc55519eef0349d487f4039eabda164"/></dir><file name=".DS_Store" hash="f291190ac228acaede15fefc49edb6e5"/></dir><file name=".DS_Store" hash="e385b6a995c1af38f899669fa136a12e"/></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>