25 Dec 2014, 3:57 PM
Administrator
- Join Date:
- Sep 2009
- Location:
- Stuart, FL
- Posts:
- 14,067
- Plugin Contributions:
- 56
[Done v1.6.0] PHP Notify error in zen_has_products_attributes (admin general.php)
The subject function receives the following PHP notification on each execution ... if the requested product does not have attributes:
PHP Notice: Undefined property: queryFactoryResult::$fields in C:\xampp\htdocs\test\test_admin\includes\functions\general.php on line 2075
The issue is with the highlighted code since the **fields **array is not returned if the product has no attributes:
/**
* Check if product has attributes
*/
function zen_has_product_attributes($products_id, $not_readonly = 'true') {
global $db;
if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') {
// don't include READONLY attributes to determin if attributes must be selected to add to cart
$attributes_query = "select pa.products_attributes_id
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id
where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1";
} else {
// regardless of READONLY attributes no add to cart buttons
$attributes_query = "select pa.products_attributes_id
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
where pa.products_id = '" . (int)$products_id . "' limit 1";
}
$attributes = $db->Execute($attributes_query);
[B] if ($attributes->fields['products_attributes_id'] > 0) {[/B]
return true;
} else {
return false;
}
}
The notification can be corrected by the following change:
/**
* Check if product has attributes
*/
function zen_has_product_attributes($products_id, $not_readonly = 'true') {
global $db;
if (PRODUCTS_OPTIONS_TYPE_READONLY_IGNORED == '1' and $not_readonly == 'true') {
// don't include READONLY attributes to determin if attributes must be selected to add to cart
$attributes_query = "select pa.products_attributes_id
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa left join " . TABLE_PRODUCTS_OPTIONS . " po on pa.options_id = po.products_options_id
where pa.products_id = '" . (int)$products_id . "' and po.products_options_type != '" . PRODUCTS_OPTIONS_TYPE_READONLY . "' limit 1";
} else {
// regardless of READONLY attributes no add to cart buttons
$attributes_query = "select pa.products_attributes_id
from " . TABLE_PRODUCTS_ATTRIBUTES . " pa
where pa.products_id = '" . (int)$products_id . "' limit 1";
}
$attributes = $db->Execute($attributes_query);
[B] return !$attributes->EOF;[/B]
}