I've encountered an issue when testing the github version on a new installation of Zen Cart 1.5.8
If i go to the admin page Catalog>Products with Attributes Stock (aka SBA)I get an SQL error warning.
Error log shows
PHP Fatal error: 1060:Duplicate column name 'products_model' :: SELECT count(*) as totalttt FROM (SELECT DISTINCT pa.products_id, pd.products_name, p.products_quantity, p.products_model, p.products_image, p.products_type, p.master_categories_id, p.products_model FROM zen_products_attributes pa, zen_products_description pd, zen_products p WHERE pd.language_id=1 AND pa.products_id = pd.products_id AND pa.products_id = p.products_id ORDER BY p.products_model ) countresults ==> (as called by) /Users/dev/Sites/localhost/sbatest/SBAAdin/includes/classes/split_page_results.php on line 220 <== in /Users/dev/Sites/localhost/sbatest/includes/classes/db/mysql/query_factory.php on line 667.
The count query seems to be built using ```
private function numberRows(string $sql)
where the content of $sql is
SELECT DISTINCT pa.products_id, pd.products_name, p.products_quantity, p.products_model, p.products_image, p.products_type, p.master_categories_id, p.products_model FROM zen_products_attributes pa, zen_products_description pd, zen_products p WHERE pd.language_id=1 AND pa.products_id = pd.products_id AND pa.products_id = p.products_id ORDER BY p.products_model
and yet the sql query built in admin/includes/classes/products_with_attributes_stock.php at line 348 is
$query_products = "SELECT DISTINCT pa.products_id, pd.products_name, p.products_quantity, p.products_model, p.products_image, p.products_type, p.master_categories_id, " . $search_order_by . " FROM " . TABLE_PRODUCTS_ATTRIBUTES . " pa, " . TABLE_PRODUCTS_DESCRIPTION . " pd, " . TABLE_PRODUCTS . " p WHERE pd.language_id=" . (int)$language_id . " AND pa.products_id = pd.products_id AND pa.products_id = p.products_id " . $w . " ORDER BY " . $search_order_by . " " . $SearchRange;
It seems that it is adding the order by content back into the main query.
It's not the first time I have seen this since beginning testing on 1.5.8 as I had an instance on the front end last week where adding p.products_model to a query (can't recall which one at the moment) resulted in the same error being logged on the store side. I discovered that it was writing the sort by fields to the query used for count.
This may be a bug in ZC core as I can't see any need to add additional fields other than what already existed in a query.
Peerhaps some form of check is required so that it doesn't lead to duplicate fields being used in the count query that gets built.
Zen Cart developer since 2009 — Zen Cart Solutions
Ecommerce development, integrations & automation — Junction Solutions