Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default tax_rate undefined index

    I'm trying to track down an undefined index error on 'tax_rate' in functions_taxes.php in function zen_get_tax_rate_from_desc on line 274. The input to this function is "Sales Tax" (TEXT_UNKNOWN_TAX_RATE). It appears that $class_id may be incorrect in function zen_get_tax_description($class_id, $country_id = -1, $zone_id = -1) which retrieves the tax description for function zen_get_tax_rate_from_desc. The product non-taxable. country_id and zone_id are correct and match the tax class country and zone. I do not get the error in an unmodified zc v157c.

    Can someone please summarize the processing path associated with tax rate determination for both non-taxable and taxable products at checkout for zc 157c?

    Thank you!

  2. #2
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: tax_rate undefined index

    Quote Originally Posted by Dave224 View Post
    I'm trying to track down an undefined index error on 'tax_rate' in functions_taxes.php in function zen_get_tax_rate_from_desc on line 274. The input to this function is "Sales Tax" (TEXT_UNKNOWN_TAX_RATE). It appears that $class_id may be incorrect in function zen_get_tax_description($class_id, $country_id = -1, $zone_id = -1) which retrieves the tax description for function zen_get_tax_rate_from_desc. The product non-taxable. country_id and zone_id are correct and match the tax class country and zone. I do not get the error in an unmodified zc v157c.

    Can someone please summarize the processing path associated with tax rate determination for both non-taxable and taxable products at checkout for zc 157c?

    Thank you!
    Well, believe it or not, that function: zen_get_tax_rate_from_desc is not even used in the core ZC code... As such, it basically hasn't been "corrected" to account for the "generic" TEXT_UNKNOWN_TAX_RATE which appears to otherwise have a tax rate of 0.

    So, an important comment here is that in an unmodified store this problem doesn't occur... So, how is this store modified? What is really being sought. My short summary of what happens is that product is applied to the shopping_cart class which then feeds the order class for populating the product. The order class processing then attempts to determine the tax(es) to be applied to each product. Then at some point later when it is desired to see what the taxes are the order_totals ot_tax module retrieves information from the order to be able to display/store the tax information in a retrievable form...

    Note that some time ago, the function zen_get_multiple_tax_rates was updated to return an array object to address that TEXT_UNKNOWN_TAX_RATE was not being properly addressed in stricter settings which prompted the return of $rates_array[TEXT_UNKNOWN_TAX_RATE] = 0; instead of $rates_array[0] = TEXT_UNKNOWN_TAX_RATE.

    What I see as a solution to this issue, considering it is expected that TEXT_UNKNOWN_TAX_RATE would not be defined in the database would be:

    Code:
     function zen_get_tax_rate_from_desc($tax_desc) {
        global $db;
        $tax_rate = 0.00;
    
    
        $tax_descriptions = explode(' + ', $tax_desc);
        foreach ($tax_descriptions as $tax_description) {
          $tax_query = "SELECT tax_rate
                        FROM " . TABLE_TAX_RATES . "
                        WHERE tax_description = :taxDescLookup";
          $tax_query = $db->bindVars($tax_query, ':taxDescLookup', $tax_description, 'string'); 
    
    
          $tax = $db->Execute($tax_query);
    
          if ($tax->EOF) {
            $tax->fields['tax_rate'] = 0.0;
          }
    
          $tax_rate += $tax->fields['tax_rate'];
        }
    
    
        return $tax_rate;
      }
    OR:
    Code:
     function zen_get_tax_rate_from_desc($tax_desc) {
        global $db;
        $tax_rate = 0.00;
    
    
        $tax_descriptions = explode(' + ', $tax_desc);
        foreach ($tax_descriptions as $tax_description) {
          $tax_query = "SELECT tax_rate
                        FROM " . TABLE_TAX_RATES . "
                        WHERE tax_description = :taxDescLookup";
          $tax_query = $db->bindVars($tax_query, ':taxDescLookup', $tax_description, 'string'); 
    
    
          $tax = $db->Execute($tax_query);
    
          if (!$tax->EOF) {
            $tax_rate += $tax->fields['tax_rate'];
          }
    
        }
    
    
        return $tax_rate;
      }
    Last edited by mc12345678; 21 May 2021 at 08:08 PM. Reason: To not encourage/force the tax to become an integer.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  3. #3
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: tax_rate undefined index

    The following add-ons in my store call function zen_get_tax_rate_from_desc:
    edit orders
    ot_better_together
    ot_bigspender_discount
    ot_quantity_discount
    Only ot_quantity discount was active during my current tests. I'll try your changes and report back. I'll leave it to the entire zen cart team to determine the best solution, either in the add-ons or to the function.
    Thank you!
    Dave

  4. #4
    Join Date
    Jun 2012
    Posts
    412
    Plugin Contributions
    0

    Default Re: tax_rate undefined index

    The change works great.
    Dave

  5. #5
    Join Date
    Jul 2012
    Posts
    16,732
    Plugin Contributions
    17

    Default Re: tax_rate undefined index

    I've submitted a PR for each 1.5.7 and 1.5.8 as the variable name(s) changed between the two.

    1.5.7: Remove php notice when searching for non-existent description by mc12345678 · Pull Request #4346 · zencart/zencart (github.com)
    1.5.8: Remove php notice when searching for non-existent description by mc12345678 · Pull Request #4347 · zencart/zencart (github.com)

    I explained why I chose the method I did within the PR description, but there was yet a third option which would address TEXT_UNKNOWN_TAX_RATE but not any other attempt to look up a tax rate by a description not in the database.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 

Similar Threads

  1. v157 v157b PHP Notice: Undefined index: SSL_SESSION_ID
    By marton_1 in forum Upgrading to 1.5.x
    Replies: 2
    Last Post: 17 Apr 2021, 03:45 PM
  2. v157 PHP Notice: Undefined index
    By yueli7 in forum Upgrading to 1.5.x
    Replies: 1
    Last Post: 24 Jul 2020, 06:56 PM
  3. v155 Undefined index: shipping in classes/order.php
    By torvista in forum Bug Reports
    Replies: 3
    Last Post: 11 Sep 2017, 04:09 PM
  4. Replies: 0
    Last Post: 2 Feb 2014, 03:12 PM
  5. v151 Undefined index: path in configure.php (using Apsona)
    By torvista in forum All Other Contributions/Addons
    Replies: 2
    Last Post: 5 Apr 2013, 06:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR