Re: tax_rate undefined index
Quote:
Originally Posted by
Dave224
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;
}
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
Re: tax_rate undefined index
The change works great.
Dave
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.