Answer the question
In order to leave comments, you need to log in
Opencart2 How to get product filter by category and brand?
Good afternoon!
Please tell me how to generate a false JSON query to the opencart2 (mysql) database to get
All filters (standard) by category and manufacturer.
As a result, they should have an array of filter groups (with their values) for products in the current category, filtered by manufacturer, for further processing by controllers.
Answer the question
In order to leave comments, you need to log in
I figured it out myself!
Returns filter groups by category and brand
$category_id = 1;
$manufacturer_id = 5;
$query = $this->db->query("SELECT DISTINCT f.name, f.filter_group_id FROM ".DB_PREFIX."filter_group_description f
LEFT JOIN ".DB_PREFIX."filter l ON(f.filter_group_id = l.filter_group_id)
LEFT JOIN ".DB_PREFIX."product_filter t ON(l.filter_id = t.filter_id)
LEFT JOIN ".DB_PREFIX."product p ON(t.product_id = p.product_id)
LEFT JOIN ".DB_PREFIX."product_to_category c ON(p.product_id = c.product_id)
WHERE c.category_id = '".(int)$category_id."' AND p.manufacturer_id = '".(int)$manufacturer_id."'");
$category_id = 1;
$manufacturer_id = 5;
$filter_group_id;
$query2 = $this->db->query("SELECT DISTINCT l.filter_id, l.filter_group_id, l.name FROM ".DB_PREFIX."filter_description l
LEFT JOIN ".DB_PREFIX."product_filter t ON(l.filter_id = t.filter_id)
LEFT JOIN ".DB_PREFIX."product p ON(t.product_id = p.product_id)
LEFT JOIN ".DB_PREFIX."product_to_category c ON(p.product_id = c.product_id)
WHERE l.filter_group_id = '" . $filter_group_id ."' AND c.category_id = '".(int)$category_id."' AND p.manufacturer_id = '".(int)$manufacturer_id."'");
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question