Page 1 of 1

Display filter_id in product/category

Posted: Wed Mar 26, 2025 12:06 am
by Pat073
Version 3.0.4.0
Would like to display the filter_id from oc_product_filter table above product image on the category page.
It is on a development site where I need a way to scroll quickly the products and check my product filters. No need pull data from oc_filter... table, only have 1 group and 5 filters, so just the id would definitely help.
Thanks

Re: Display filter_id in product/category

Posted: Mon Jun 16, 2025 12:05 pm
by halfhope
Hi!

If you want to do it manually, you may look how someone made similar moment to show product attributes. But you should replace attribute models to filter models. Also needle functions (SQL code to request product's filter_id) may not exists(idk), so you should create it.

Re: Display filter_id in product/category

Posted: Mon Jun 16, 2025 6:02 pm
by paulfeakins
Pat073 wrote:
Wed Mar 26, 2025 12:06 am
Would like to display the filter_id from oc_product_filter table above product image on the category page.
Sounds like you might be doing something inadvisable. Give us a bit more info about what you're trying to do and why?

Re: Display filter_id in product/category

Posted: Sat Jun 28, 2025 5:09 am
by gogoweb
I wrote a quick function for you to place in the model/catalog/product (ModelCatalogProduct)
and call that from your category controller or where you want.
This will give you the ids and names of filters.
Simply pass the result to your view and you see the filter_id-filter_name,otherfilter_id-othername etc.

Code: Select all

	
	// accepts (int) product_id
	// returns filters as one string
	
	public function getProductFilters($product_id) {
		$sql = "SELECT p.product_id, GROUP_CONCAT(pf.filter_id,'-',fd.name) AS filters FROM `" . DB_PREFIX . "product` p
LEFT JOIN `" . DB_PREFIX . "product_filter` pf ON  p.product_id = pf.product_id 
LEFT JOIN `" . DB_PREFIX . "filter_description` fd ON  pf.filter_id = fd.filter_id
WHERE p.product_id = ".(int)$product_id."
GROUP BY p.product_id
";

		$query = $this->db->query($sql);
		return $query->row['filters'];
		
	}