Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storefront, manufacturers: PHP Fatal error: Not unique table/alias: 'p2c' #6216

Closed
torvista opened this issue Feb 11, 2024 · 2 comments
Closed

Comments

@torvista
Copy link
Member

Choose a manufacturer, from the sidebox, in this case Fox:
image

#1 D:\GitHub\zencart\includes\classes\db\mysql\query_factory.php(714): trigger_error()
#2 D:\GitHub\zencart\includes\classes\db\mysql\query_factory.php(659): queryFactory->show_error()
#3 D:\GitHub\zencart\includes\classes\db\mysql\query_factory.php(299): queryFactory->set_error()
#4 D:\GitHub\zencart\includes\templates\responsive_classic\templates\tpl_index_product_list.php(52): queryFactory->Execute()
#5 D:\GitHub\zencart\includes\modules\pages\index\main_template_vars.php(232): require('D:\GitHub\zenca...')
#6 D:\GitHub\zencart\includes\templates\responsive_classic\common\tpl_main_page.php(178): require('D:\GitHub\zenca...')
#7 D:\GitHub\zencart\index.php(94): require('D:\GitHub\zenca...')
--> PHP Fatal error: MySQL error 1066: Not unique table/alias: 'p2c' :: SELECT p.products_image, pd.products_name, p.products_quantity, p.products_id, p.products_type, p.master_categories_id,
p.manufacturers_id, p.products_price, p.products_tax_class_id, pd.products_description,
IF(s.status = 1, s.specials_new_products_price, NULL) AS specials_new_products_price,
IF(s.status = 1, s.specials_new_products_price, p.products_price) AS final_price,
p.products_sort_order, p.product_is_call, p.product_is_always_free_shipping, p.products_qty_box_status
FROM products p
LEFT JOIN specials s ON s.products_id = p.products_id
LEFT JOIN products_description pd ON pd.products_id = p.products_id AND pd.language_id = 1
LEFT JOIN manufacturers m ON m.manufacturers_id = p.manufacturers_id
LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id WHERE p.products_status = 1
AND m.manufacturers_id = 4 AND p2c.categories_id = p.master_categories_id AND m.manufacturers_id = 4 AND p2c.categories_id = p.master_categories_id
ORDER BY p.products_sort_order, pd.products_name ==> (as called by) D:\GitHub\zencart\includes\templates\responsive_classic\templates\tpl_index_product_list.php on line 52 <== in D:\GitHub\zencart\includes\classes\db\mysql\query_factory.php on line 714.

I think is this is due to default_filter being parsed twice (as previously noted #5396)
and this getting repeated:

LEFT JOIN products_to_categories p2c ON p2c.products_id = p.products_id

$and = $and ?? '';
$sql_joins = $sql_joins ?? '';
// show the products of a specified manufacturer
if (isset($_GET['manufacturers_id']) && $_GET['manufacturers_id'] > 0) {
// We show them all
$and .= " AND m.manufacturers_id = " . (int)$_GET['manufacturers_id'] . " ";
if (isset($_GET['filter_id']) && zen_not_null($_GET['filter_id'])) {
// We are asked to show only a specific category
$sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
$and .= " AND p2c.categories_id = " . (int)$_GET['filter_id'] . " ";
} else {
$sql_joins .= " LEFT JOIN " . TABLE_PRODUCTS_TO_CATEGORIES . " p2c ON p2c.products_id = p.products_id ";
$and .= ' AND p2c.categories_id = p.master_categories_id ';

Started happening a few days ago so it's probably SNAF-related.

@scottcwilson
Copy link
Sponsor Contributor

Guys, thanks for finding and taking care of these so quickly.

@torvista
Copy link
Member Author

Should not the test suite be able to detect this?...I assume it simulates pressing all the buttons and selecting things like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants