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:
- 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:
$link = hikashop_completeLink('product&task=show&cid='.$this->row->product_id.'&name='.$this->row->alias.$this->itemid.$this->category_pathway);
with:
$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)?