- Posts: 8
- Thank you received: 1
Get the Category Menu in Product Listing view
13 years 3 months ago - 13 years 3 months ago #110163
by pipedream
Get the Category Menu in Product Listing view was created by pipedream
In a random product list, I need to now the menu item associated to the category of each product.
The final goal is to always have the link of the product under the category link.
In more detail:
Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing_img_desc.php view. So, I replaced this line:
with:
Is it possible to validate this solution and also tell if there is another way of getting the category_id of the product in this view (without a database query)?
The final goal is to always have the link of the product under the category link.
In more detail:
- Each product belongs to a single category;
- Every category has its own menu item, so that the URLs look just as: /category1, /category2,... /categoryN;
- Every product should have an URL like: /category1/productA, /category1/productB,... /categoryN/productC;
a) This works inside the category page because the Product Sef name is empty;
b) This doesn't work if a product is accessed from the homepage where there is a module to present random products from all categories;
Since in the module it is only possible to configure an Itemid value, I fetched the Itemid of each product in the product/listing_img_desc.php view. So, I replaced this line:
Code:
$link = hikashop_completeLink('product&task=show&cid='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway);
with:
Code:
$database = JFactory::getDBO();
$menuClass = hikashop_get('class.menus');
$query = "SELECT category_id FROM ".hikashop_table('product_category').' WHERE product_id='.$this->row->product_id.' ORDER BY product_category_id ASC';
$database->setQuery($query);
$categories_id = $database->loadColumn();
$itemid = "&Itemid=".$menuClass->getItemidFromCategory($categories_id[0]);
$link = hikashop_completeLink('product&task=show&cid='.$this->row->product_id.'&name='.$this->row->alias.$itemid.$this->category_pathway);
Is it possible to validate this solution and also tell if there is another way of getting the category_id of the product in this view (without a database query)?
Last edit: 13 years 3 months ago by pipedream. Reason: text correction
Please Log in or Create an account to join the conversation.
13 years 3 months ago #110223
by Eliot
Replied by Eliot on topic Get the Category Menu in Product Listing view
Hi there,
Your method should work but you can also try with this, which seems to be an easier way:
Your method should work but you can also try with this, which seems to be an easier way:
Code:
$link = hikashop_completeLink('product&task=show&cid='.$this->row->product_id.'&name='.$this->row->alias.$this->element->category_id.$this->category_pathway);
Please Log in or Create an account to join the conversation.
13 years 3 months ago - 13 years 3 months ago #110263
by pipedream
Replied by pipedream on topic Get the Category Menu in Product Listing view
Hi Eliot,
$this->element->category_id returns only the parent category.
I have the module configured to return all the sub-categories under this parent category.
Also, if I don't find and insert the correct Itemid in the hikashop_completeLink function, the link returned has the format:
/component/hikashop/productAcategoryId
Ex.: /component/hikashop/33-product12
instead of the wanted:
/categoryName/33-product
$this->element->category_id returns only the parent category.
I have the module configured to return all the sub-categories under this parent category.
Also, if I don't find and insert the correct Itemid in the hikashop_completeLink function, the link returned has the format:
/component/hikashop/productAcategoryId
Ex.: /component/hikashop/33-product12
instead of the wanted:
/categoryName/33-product
Last edit: 13 years 3 months ago by pipedream.
Please Log in or Create an account to join the conversation.
13 years 3 months ago #110267
by Eliot
Replied by Eliot on topic Get the Category Menu in Product Listing view
My bad, I didn't understand the first time.
In this case your solution looks good.
You could make it cleaner by loading the categories for each product in the view.html.php so you object $this->row would already have the categories but it's not especially easy.
In this case your solution looks good.
You could make it cleaner by loading the categories for each product in the view.html.php so you object $this->row would already have the categories but it's not especially easy.
The following user(s) said Thank You: pipedream
Please Log in or Create an account to join the conversation.
13 years 3 months ago #110268
by pipedream
Replied by pipedream on topic Get the Category Menu in Product Listing view
Merci, Eliot!
Yes, I looked at view.html.php to copy the database query.
Even is less prettier, I prefer to have the code in the template, so that it can be easier to upgrade HikaShop.
Yes, I looked at view.html.php to copy the database query.
Even is less prettier, I prefer to have the code in the template, so that it can be easier to upgrade HikaShop.
Please Log in or Create an account to join the conversation.
Time to create page: 0.232 seconds