Get the Itemid

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 7 months ago #15169

Hi there,

I am building a product scroller for hikashop. Everything is working correctly except the breadcrumb when we view the product. At the moment the scroller works with only category at a time. Currently when you click on the link to view a product we get the following breadcrumb

Home > product category > Category A > Category B > Category C > Product Name

I don't want 'product category' to appear. We want the breadcrumb to be:

Home > Category A > Category B > Category C > Product Name

To do so we need the Itemid value for Category A in the URL. Correct? Does Hikashop already have a function that allows you to obtain this value? Thanks

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #15178

Hi,

That's correct.
There is no function for that. What we do is that we usually have an option with the user can select the menu to use so that we can properly fill the Itemid parameter of the URLs. You can see that in the modules's hikashop options and the search plugin.
If you want to get automatically the Itemid based on a category you need to have something like that (not tested):

function getItemidFromCategory($category_id){
 $config =& hikashop::config();
 foreach($config->values as $key => $value){
  if(preg_match('#menu_([0-9]+)#',$key,$match)){
   if(is_string($value->config_value)) $value->config_value = unserialize(base64_decode($value->config_value));
   if($value->config_value['selectparentlisting'] == $category_id ){
     return $match[1];
   }
  }
 }
 return false;
}

Last edit: 13 years 7 months ago by nicolas.

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

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 7 months ago #15193

Hello Nicolas, thanks for the big pointer. Here is a working version.

function getItemidFromCategory($category_id) {
    $config = & hikashop::config();
    $values = $config->values;
    foreach ($values as $key => $value) {
      if (preg_match('#menu_([0-9]+)#', $key, $match)  && is_string($value->config_value)) {
        $options = unserialize(base64_decode($value->config_value));
        if ($options['selectparentlisting'] == $category_id) {
          return $match[1];
        }
      }
    }
    return false;
  }

However I would like to add. The Itemid parameter of the URLs that you can add in the product search plugin only works if all product categories share a common parent menu item. What do you do if you you don't follow this structure?

Last edit: 13 years 7 months ago by jameswadsworth.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
13 years 7 months ago #15196

I've updated the code in my post after your modifications. It should be better.

Concerning the search plugin that is indeed the case. You can always create a specific menu which is not displayed on your template with the main "product category" category as parent category and use that menu in the plugin

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

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 6 months ago #15305

Hi Nicolas, okay we took you improvements and we have added them tothe hikashop_products.php search file. So we now have perfect breadcrumbs from search results! Yay! We have worked on version 1.4.9

In line 132 we modified the line to:

$select = ' a.product_id AS id, a.product_name AS title, a.product_created AS created , a.product_description AS text, "'.$new_page.'" AS browsernav, b.category_id as category_id';

Then after line 187 - foreach ( $rows as $k => $row ) {
if(empty($item_id)){
          $Itemid = $this->getItemidFromCategory($rows[$k]->category_id);
          if(!empty($Itemid)){
            $item_id='&Itemid='.$Itemid;
            if($this->params->get('full_path',1)){
              $menuClass = dacshop::get('class.menus');
              $menuData = $menuClass->get($item_id);
              if(!empty($menuData->dacshop_params['selectparentlisting'])){
                $parent = '&category_pathway='.(int)$menuData->dacshop_params['selectparentlisting'];
              }
            }                     
          }
        }

we put the function getItemidFromCategory($category_id) at end. Comments welcome

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
13 years 6 months ago #15311

We'll integrate that for next release.

The , b.category_id as category_id code should not be added in the $select variable but directly in the query:
$query = ' SELECT '.$select.', b.category_id as category_id FROM '.hikashop::table('product') . ' AS a '.$leftjoin.' WHERE '.implode(' AND ',$filters).' ORDER BY '.$order;

Otherwise, it will break the query:
$query = ' SELECT DISTINCT '.$select.' FROM '.hikashop::table('jf_content',false) . ' AS b LEFT JOIN '.hikashop::table('product').' AS a ON b.reference_id=a.product_id WHERE '.implode(' AND ',$filters2).' ORDER BY '.$order;
when joomfish is installed.

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

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 2 months ago #25658

I see this solutaion for obtaining the itemid has been removed in version 1.5.3. This now results in blank pages when the user searches for a category and clicks to display the category. In the category search plugin we have not set the Itemid because our menu structure is:

Home
Category1 > Subcategory1 > AnotherSubcategory1
Category2 > Subcategory2 > AnotherSubcategory2
Category3 > Subcategory3 > AnotherSubcategory3
Category4 > Subcategory4 > AnotherSubcategory4

So you can we don't have single itemid that satisfies the setting for each view. The solution in these posts worked well. I presume when the the manufacture option was added it was removed for some reason. (edit - sorry, getting confused. This was implemented for the product search - now I am going see if something similar can be implemented to get the itemid if the itemid is not set in the category plugin.)

Last edit: 13 years 2 months ago by jameswadsworth.

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

  • Posts: 82906
  • Thank you received: 13378
  • MODERATOR
13 years 2 months ago #25665

Indeed. That was never implemented for the categories search plugin.

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

  • Posts: 272
  • Thank you received: 3
  • Hikashop Business
13 years 2 months ago #25668

Okay. I seem to have a solution that is working for the categories search and have also resolved a bug with the product search. I am sending you them by email.

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

  • Posts: 99
  • Thank you received: 2
10 years 5 months ago #158052

Hello,
does it comes to a solution to find the correct menu-itemid for each product listed ?
Is there a function that could be used to retrieve it in Content Display module to set the itemid in the $link variable ?

I suppose it should be updated in the code of listing_img_title.php as an override ...
... an option in module that say "auto get product item-id if exists !" would also be a great way !

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
10 years 5 months ago #158103

Hi,

It is what we done using the "product canonical url" and the new option in HikaShop 1.4.1

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

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

  • Posts: 99
  • Thank you received: 2
10 years 5 months ago #158540

Hello,
I've set "Force canonical URLs on listings = Use canonical URL and generate it if missing"
but the Itemid is always still the same for each product in list.
Looking at the code of listing_img_title.php doesn't seems to try to get the menu item anywhere,
it couldn't be easy to find, not just with a simple query, because I suppose we have to search in all menu items for a param like {product_id: ... }

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

  • Posts: 99
  • Thank you received: 2
10 years 5 months ago #158579

I've made a fast update of the code to try to retrieve the menu item id.
I've updated two files in components/com_hikashop/views/product/tmpl/
(I think that once these becomes working these could be put as overrides in template joomla dir)

Add this code to listing_div.php

$db = JFactory::getDbo();
	$query = $db->getQuery(true);
	$query->select('*');
	$query->from($db->quoteName('#__menu'));
	$query->where($db->quoteName('link')." = ".$db->quote('index.php?option=com_hikashop&view=product&layout=show'));	 
	$db->setQuery($query);
	$result_menu = $db->loadAssocList();	
	$prod_arr = array();
	foreach ($result_menu as $res_item)
	{
		$prod_param = json_decode($res_item['params']);
		$prod_id = $prod_param->product_id;
		$prod_arr[$prod_id] = $res_item['id'];
	}
	//print_r($prod_arr);
	$this->prod_arr = $prod_arr;

and updated the $link variable in listing_img_title.php like:
	$itemid = (int)$this->prod_arr[$this->row->product_id];
	$link = hikashop_completeLink('product&task=show&cid='.$this->row->product_id.'&name='.$this->row->alias."&Itemid=".$itemid);

What do you think about it ?
I know it's not really a good coding and not so good for performance, because it retrieves many menu items without filtering over the category on the query.

Thank you for any suggestion !

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

  • Posts: 846
  • Thank you received: 92
9 years 6 months ago #200532

Hi
can i have more information about
- the itemid : id of the menu ( module) or one of the id of a menu ( one of the list title of the menu )
- the relation beetween itemid and Canonical URL ?

thank's

Attachments:

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

  • Posts: 26159
  • Thank you received: 4028
  • MODERATOR
9 years 6 months ago #200538

Hi,

- An Itemid is an Itemid... It's a Joomla menu.
- There is no relation between them.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.
The following user(s) said Thank You: lionel75

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

  • Posts: 99
  • Thank you received: 2
9 years 6 months ago #200699

I think he's asking what kind of id is the itemid we're talking about,
then it is the id of each menu item useful when you need to enable a module for a certain page by the settings of the module itself.
If this element isn't present in the url the module will not be loaded.

The following user(s) said Thank You: lionel75

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

Time to create page: 0.078 seconds
Powered by Kunena Forum