Get Item ID for a Given Category Id

  • Posts: 109
  • Thank you received: 5
9 years 7 months ago #172453

-- HikaShop version -- : 2.3.2
-- Joomla version -- : 3.3.3
-- Browser(s) name and version -- : IE 11

Hello, there.

Good afternoon!

I am trying to retrieve the Item ID for a given Category ID. Is there any update since the discussion on www.hikashop.com/forum/4-how-to/15169-get-the-itemid.html ? I.e. is there now a Hikashop function that I can call? If so, please could you provide the name of the class and method?

If not, please could you confirm that the best code to use will be the one that Nicolas stated in the discussion (see the link above)? I.e. the code is:

~~~~~~ START OF CODE ~~~~~~
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 == $category_id ){
return $match[1];
}
}
}
return false;
}

~~~~~~~ END OF CODE ~~~~~~~

Thanks.

Take care!

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

  • Posts: 13201
  • Thank you received: 2322
9 years 7 months ago #172467

Hi,

In fact, a category don't have attached item id, the item id is based on the menus.
So to have one item id per category you need to have one category listing menu associated to a category.

The code provided by Nicolas is still valid, it allow to have the item id of the attached category's menu.

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

  • Posts: 109
  • Thank you received: 5
9 years 7 months ago #172611

Bonjour, Xavier.

Good afternoon!

Thank you for your reply.

This is probably a silly question (but do not that I am not familiar with php).

I cannot get the function to run. After some debugging, it seems that the function gets stuck (stop executing) at the following line:

$config =& hikashop::config();

Is there some declaration that I need to do at the start of the function?

Thanks.

Take care!

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

  • Posts: 109
  • Thank you received: 5
9 years 7 months ago #172616

Bonjour, Xavier.

Good afternoon!

Just to let you know that I have figured it out. I included the following line at the start of the function and it's all honky dory now.

if(!@include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')){ return false; }

Thanks for your help.

Take care!

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

Time to create page: 0.079 seconds
Powered by Kunena Forum