Forums / Bug Reports / Potential zen_has_product_attributes_values() error

Potential zen_has_product_attributes_values() error

Started by gjh42 on 4 Apr 2011, 1:11 PM · Views: 953

Results 1 to 6 of 6
4 Apr 2011, 1:11 PM
#1
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Potential zen_has_product_attributes_values() error

I noticed that in /includes/functions/functions_lookups.php, this function could apparently return a false negative if there were two or more attributes with equal and opposite total values (e.g. one adds $5.00 to base price and the other subtracts $5.00 from base).```php
/*

  • Check if product has attributes values
    */
    function zen_has_product_attributes_values($products_id) {
    global $db;
    $attributes_query = "select sum(options_values_price) as total
    from " . TABLE_PRODUCTS_ATTRIBUTES . "
    where products_id = '" . (int)$products_id . "'";

    $attributes = $db->Execute($attributes_query);

    if ($attributes->fields['total'] != 0) {
    return true;
    } else {
    return false;
    }
    }

"select sum(options_values_price)
"select sum((abs)options_values_price) or whatever is correct syntax for mysql.
4 Apr 2011, 1:23 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Potential zen_has_product_attributes_values() error

Another possibility would be to test in the query:```php
$attributes_query = "select options_values_price
from " . TABLE_PRODUCTS_ATTRIBUTES . "
where products_id = '" . (int)$products_id . "'"
and options_values_price != 0
limit 1;

4 Apr 2011, 5:10 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Potential zen_has_product_attributes_values() error

Could you give a real world example of where this is producing a problem? :unsure:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

4 Apr 2011, 11:30 PM
#4
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,874
Plugin Contributions:
8

Re: Potential zen_has_product_attributes_values() error

No, I haven't tested it, but if you had
(e.g. one adds $5.00 to base price and the other subtracts $5.00 from base)
would this not trigger it, acting as if there were no attribute price values?

I presume the value returned from this function matters in some situation, or else why have it at all?

/includes/templates/template_default/templates/tpl_product_info_display.php

Line #70 : echo $one_time . ((zen_has_product_attributes_values((int)$_GET['products_id']) and $flag_show_product_info_starting_at == 1) ? TEXT_BASE_PRICE : '') . zen_get_products_display_price((int)$_GET['products_id']);

5 Apr 2011, 12:57 AM
#6
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Potential zen_has_product_attributes_values() error

I am trying to come up with a real world example where this can happen ... and so far, that only works if I have one Color Red for 5.00 and Size Small for -5.00 and no other choices ...

If you come up with a good test example let us know ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!