simon1066:
I have applied the above changes to a v1.5.5f site, it seems that the changes to includes/classes/class.products_with_attributes_class_stock.php are causing problems. The error I get when adding a SBA attributed product to the cart (from the product info page) is
[23-Sep-2018 15:08:12 Europe/London] Request URI: /my-category/my-product?number_of_uploads=0&action=add_product, IP address: 127.0.0.1
#1 trigger_error() called at [\www\mydomain.co.uk\includes\classes\class.products_with_attributes_class_stock.php:793]
#2 products_with_attributes_class_stock->zen_sba_attribs_no_text() called at [\www\mydomain.co.uk\includes\extra_cart_actions\stock_by_attributes.php:787]
#3 include(\www\mydomain.co.uk\includes\extra_cart_actions\stock_by_attributes.php) called at [\www\mydomain.co.uk\includes\main_cart_actions.php:26]
#4 require(\www\mydomain.co.uk\includes\main_cart_actions.php) called at [\www\mydomain.co.uk\includes\init_includes\init_cart_handler.php:44]
#5 require(\www\mydomain.co.uk\includes\init_includes\init_cart_handler.php) called at [\www\mydomain.co.uk\includes\autoload_func.php:48]
#6 require(\www\mydomain.co.uk\includes\autoload_func.php) called at [\www\mydomain.co.uk\includes\application_top.php:170]
#7 require(\www\mydomain.co.uk\includes\application_top.php) called at [\www\mydomain.co.uk\index.php:26]
[23-Sep-2018 15:08:12 Europe/London] PHP Warning: SBA product can not have any attributes in \www\mydomain.co.uk\includes\classes\class.products_with_attributes_class_stock.php on line 793
[23-Sep-2018 15:08:12 Europe/London] PHP Stack trace:
[23-Sep-2018 15:08:12 Europe/London] PHP 1. {main}() \www\mydomain.co.uk\index.php:0
[23-Sep-2018 15:08:12 Europe/London] PHP 2. require() \www\mydomain.co.uk\index.php:26
[23-Sep-2018 15:08:12 Europe/London] PHP 3. require() \www\mydomain.co.uk\includes\application_top.php:170
[23-Sep-2018 15:08:12 Europe/London] PHP 4. require() \www\mydomain.co.uk\includes\autoload_func.php:48
[23-Sep-2018 15:08:12 Europe/London] PHP 5. require() \www\mydomain.co.uk\includes\init_includes\init_cart_handler.php:44
[23-Sep-2018 15:08:12 Europe/London] PHP 6. include() \www\mydomain.co.uk\includes\main_cart_actions.php:26
[23-Sep-2018 15:08:12 Europe/London] PHP 7. products_with_attributes_class_stock->zen_sba_attribs_no_text() \www\mydomain.co.uk\includes\extra_cart_actions\stock_by_attributes.php:787
[23-Sep-2018 15:08:12 Europe/London] PHP 8. trigger_error() \www\mydomain.co.uk\includes\classes\class.products_with_attributes_class_stock.php:793
>
> To my inexperienced eye it would appear that this code, lines 762 - 788, are behind the issue, only because reverting to the SBA's previous version of this code gives no errors.
> ```php
if (!isset($this->_isSBA[(int)$products_id]['sql'])) {
if (PRODUCTS_OPTIONS_SORT_ORDER=='0') {
$options_order_by= ' order by LPAD(popt.products_options_sort_order,11,"0"), popt.products_options_name';
} else {
$options_order_by= ' order by popt.products_options_name';
}
//get the option/attribute list
$sql = "select distinct popt.products_options_id, popt.products_options_name, popt.products_options_sort_order,
popt.products_options_type, popt.products_options_length, popt.products_options_comment,
popt.products_options_size,
popt.products_options_images_per_row,
popt.products_options_images_style,
popt.products_options_rows
from " . TABLE_PRODUCTS_OPTIONS . " popt
left join " . TABLE_PRODUCTS_ATTRIBUTES . " patrib ON (patrib.options_id = popt.products_options_id)
where patrib.products_id= :products_id:
and popt.language_id = :languages_id: " .
$options_order_by;
$sql = $db->bindVars($sql, ':products_id:', $products_id, 'integer');
$sql = $db->bindVars($sql, ':languages_id:', $_SESSION['languages_id'], 'integer');
$products_options_names = $db->Execute($sql);
$this->_isSBA[(int)$products_id]['sql'] = $products_options_names;
} else {
$products_options_names = $this->_isSBA[(int)$products_id]['sql'];
}
There doesn't seem to be anything special about the product's attributes. Product is priced by attributes, one dropdown option name with three option values (the first of which is display only)
I would say that you are correct in the section of code. It would seem that the issue is in the else section of that. The reason I state that is because the first part generates a result from the query and as the error message that is generated suggests, the error message should not be generated when a product is tracked by SBA.
So that leaves one to ask, how then is it that this error is being generated? Well, in the else section, a previous sql result is being accessed. More than likely (which I'll take a closer look at), the query was fully iterated before being stored. What that means is that in order to reuse the result, the query needs to be rewound. Because this software is compatible with older ZC versions, there are two ways to do this.
Changing:
} else {
$products_options_names = $this->_isSBA[(int)$products_id]['sql'];
}
To:
} else {
$products_options_names = $this->_isSBA[(int)$products_id]['sql'];
if (method_exists($products_options_names, 'rewind')) {
$products_options_names->Rewind();
} else {
$products_options_names->Move(0);
$products_options_names->MoveNext();
}
}
Will likely resolve the issue for ZC 1.5.5 (in the first section) and pre-ZC 1.5.5 (in the else section that has been added).
Thank you though for reporting this, I hadn't come across such an issue after having addressed other strict associated messages. I did review the list of plugins and considering the error and where it has occurred, I don't believe that they contribute to the issue.