Product Listing under Category List
Posted: Sun Apr 16, 2023 6:10 pm
Hi,
I have copied and changed the product_listing module to be an index_nested module so I can display products under sub categories.
What I would like to happen is it to only show products from the sub categories listed under the main category.
Could anyone suggest a change to this code to only show products from the sub categories
Thanks
I have copied and changed the product_listing module to be an index_nested module so I can display products under sub categories.
What I would like to happen is it to only show products from the sub categories listed under the main category.
Could anyone suggest a change to this code to only show products from the sub categories
Code: Select all
$listing_sql = sprintf(<<<'EOSQL'
SELECT m.*, %s
FROM
products p
LEFT JOIN specials s ON p.products_id = s.products_id
INNER JOIN products_description pd ON p.products_id = pd.products_id
LEFT JOIN (SELECT products_id, COUNT(*) AS attribute_count FROM products_attributes GROUP BY products_id) a ON p.products_id = a.products_id
EOSQL
, Product::COLUMNS);
// show the products of a specified manufacturer
if (empty($_GET['manufacturers_id'])) {
// show the products in a given category
if (isset($_GET['filter_id']) && !Text::is_empty($_GET['filter_id'])) {
// We are asked to show only a specific manufacturer
$listing_sql .= sprintf(<<<'EOSQL'
INNER JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
INNER JOIN products_to_categories p2c ON p.products_id = p2c.products_id
WHERE p.products_status = 1 AND m.manufacturers_id = %d AND pd.language_id = %d AND p2c.categories_id = %d
EOSQL
, (int)$_GET['filter_id'], (int)$_SESSION['languages_id'], (int)$current_category_id);
} else {
// We show them all
$listing_sql .= sprintf(<<<'EOSQL'
INNER JOIN products_to_categories p2c ON p.products_id = p2c.products_id
LEFT JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
WHERE p.products_status = 1 AND pd.language_id = %d AND p2c.categories_id = %d
EOSQL
, (int)$_SESSION['languages_id'], (int)$current_category_id);
}
} else {
if (isset($_GET['filter_id']) && !Text::is_empty($_GET['filter_id'])) {
// We are asked to show only a specific category
$listing_sql .= sprintf(<<<'EOSQL'
INNER JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
INNER JOIN products_to_categories p2c ON p.products_id = p2c.products_id
WHERE p.products_status = 1 AND m.manufacturers_id = %d AND pd.language_id = %d AND p2c.categories_id = %d
EOSQL
, (int)$_GET['manufacturers_id'], (int)$_SESSION['languages_id'], (int)$_GET['filter_id']);
} else {
// We show them all
$listing_sql .= sprintf(<<<'EOSQL'
INNER JOIN manufacturers m ON p.manufacturers_id = m.manufacturers_id
WHERE p.products_status = 1 AND pd.language_id = %d AND m.manufacturers_id = %d
EOSQL
, (int)$_SESSION['languages_id'], (int)$_GET['manufacturers_id']);
}
}