Skip to main content

category displayed in product listing

More
14 years 6 months ago #42044 by alain.roger
Hi,

on my front page, i would like to display not only the list of all products that my eshop sells, but for each product i would like to display the category to which it belongs too.
for example, if eshop dispaly 10 business cards, i don't want to see only their image, name, price and add to cart button but also the category "business card"

1. what is the template i should modify for that ?

when user clicks on a specific product to see its detailed information, i would like also to display its category in its details...

2. once again, what is the template i should modify for that ?

thx.

What does not kill you, makes you stronger.

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago #42187 by nicolas
Hi,

It will depend on the item box box layout you're using for your products listing. If it's the default one, 'image and title', it's the file "listing_img_title" of the view "product" that you should edit.
For the product page, it's the file "show_default" (or "show" before 1.5.6) of the view "product".
These view files can be edited via the menu Display->Views.
You will first have to load the category of the product with a mysql query before being able to display its name.

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago - 14 years 6 months ago #42224 by alain.roger
thank for your help.
so if i must write a MySQL request, where will be the best place to do it ?
i'm afraid to write a MySQL request directly to the listing_img_title php file.... because it could really slow the display of product listing, no ?

AFAIK, the SQL request should be something like:
Code:
select category_name, product_name from hikashop_category cat INNER JOIN hikashop_product_category pc INNER JOIN hikashop_product prod where cat.category_id = pc.category_id AND pc.product_id = prod.product_id;

in order to get the category name

What does not kill you, makes you stronger.
Last edit: 14 years 6 months ago by alain.roger.

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago - 14 years 6 months ago #42386 by alain.roger
Hi Nicolas,

basically i wrote the following code into the template called "listing_img_title"
Code:
<?php $db =& JFactory::getDBO(); $sqlreq = "SELECT category_name FROM ".$db->nameQuote('#__hikashop_category')." cat INNER JOIN ".$db->nameQuote('#__hikashop_product_category')." pc WHERE cat.category_id = pc.category_id AND pc.product_id =".$this->row->product_id.";"; $db->setQuery($sqlreq); $db->query(); $result = $db->loadResult(); ?> ... ... <?php unset($db); unset($result) ?>

What does not kill you, makes you stronger.
Last edit: 14 years 6 months ago by alain.roger.

Please Log in or Create an account to join the conversation.

More
14 years 6 months ago #42559 by nicolas
Yes. Indeed writing a more complex query/code in order to do it only once would be better performance-wise. I said that because it's simpler to do for you.

If you want to go the complex way, you will have to do the query in "listing" of the view "product", save the results in $this and then loop through them in the listing_img_title file in order to display the proper category name.

Please Log in or Create an account to join the conversation.

Time to create page: 0.236 seconds
Powered by Kunena Forum