[Skip to main content](#vessel-content)

#   how get Category name in custom Plugin

##

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

4 years 3 months ago [\#344217](#344217) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344217 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")* was created by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")*

-- HikaShop version -- : 4.6.1
-- Joomla version -- : 4.1.5
-- PHP version -- : 7.4
-- Browser(s) name and version -- : chrome

hi,
I developing new plugin(system) for Hikashop.
how can get Category name of Product ?
this is my code: Code:

function getProductHikashopInfo() { //load HikaShop if not already loaded if(!defined('DS')) define('DS',DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; //get product id $product_id = (int)hikashop_getCID('product_id'); if(empty($product_id )) return true; // load product $productClass = hikashop_get('class.product'); $categoryClass = hikashop_get('class.category'); $product_category = $categoryClass-&gt;get($product_id )-&gt;category_name; echo $product_category; // echo "Root" }

this code output ===&gt; "Root" instead of product category name

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

4 years 3 months ago [\#344220](#344220) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344220 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

Hi,

Your code should be: Code:

function getProductHikashopInfo() { //load HikaShop if not already loaded if(!defined('DS')) define('DS',DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; //get product id $product_id = (int)hikashop_getCID('product_id'); if(empty($product_id )) return true; $categoryClass = hikashop_get('class.category'); $categories = $categoryClass-&gt;getCategories($product_id); $product_category = reset($categories)-&gt;category_name; echo $product_category; }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

4 years 3 months ago [\#344225](#344225) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  Replied by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344225 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

thanks for reply.
but i get this error: Code:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM t50ow_hikashop_category WHERE category_id IN (3)' at line 1

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

4 years 3 months ago [\#344231](#344231) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344231 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

Hi,

That error doesn't come from the code I provided.
Normally, if you activate the "debug" setting of the Joomla configuration, you should get the call stack of the error so you should be able to see in which line of which file the issue is.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

4 years 3 months ago -  4 years 3 months ago [\#344254](#344254) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  Replied by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344254 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

i attached screen of debug.please see

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

- [ ![2022-08-30&#95;153524.png](/forum/attachment/55428) ](/forum/attachment/55428 "...-30&#95;153524.png") [ ](/forum/attachment/55428?download=1 "...-30&#95;153524.png")

Last edit: 4 years 3 months ago by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

4 years 3 months ago [\#344257](#344257) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344257 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

Hi,

I know, I gave you:
$categoryClass = hikashop_get('class.category');
$categories = $categoryClass-&gt;getCategories($product_id);
but it should be:
$productClass = hikashop_get('class.product');
$categories = $productClass-&gt;getCategories($product_id);

The following user(s) said Thank You: [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")**
- [![aminweb's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar38602.png)](/forum/user/38602-aminweb "View aminweb's Profile") Topic Author
- [ Offline](/forum/user/38602-aminweb)
- Amin

Less More

- Posts: 138
- Thank you received: 4
-
-
-

4 years 3 months ago [\#344267](#344267) by [aminweb](/forum/user/38602-aminweb "View aminweb's Profile")  Replied by *[aminweb](/forum/user/38602-aminweb "View aminweb's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#344267 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

thank you

---

Joomla Developer \| am.ebrahimzadeh\[at\]gmail.com

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[lencse](/forum/user/82892-lencse "View lencse's Profile")**
- [![lencse's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/82892-lencse "View lencse's Profile")
- [ Offline](/forum/user/82892-lencse)

Less More

- Posts: 3
- Thank you received: 0
-
-

10 months 3 weeks ago -  10 months 3 weeks ago [\#369950](#369950) by [lencse](/forum/user/82892-lencse "View lencse's Profile")  Replied by *[lencse](/forum/user/82892-lencse "View lencse's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#369950 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

Hello.

How can I get the current (displayed) category id in a custom plugin without knowing the product id or anything else?
(product listing view)

Ty.

Last edit: 10 months 3 weeks ago by [lencse](/forum/user/82892-lencse "View lencse's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86593
- Thank you received: 14334
-
-

10 months 3 weeks ago [\#369956](#369956) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[how get Category name in custom Plugin](/forum/26-product-category-display/904923-how-get-category-name-in-custom-plugin#369956 "-- HikaShop version -- : 4.6.1 -- Joomla version -- : 4.1.5 -- PHP version -- : 7.4 -- Browser(s) name and version -- : chrome  hi, I developing new plugin(system) for Hikashop. how can get Category name of Product ? this is my code:  this code output ===&gt; &quot;Root&quot; instead of product category name")*

Hi,

In the product listing view, you can get the current category ID from the URL parameter using: Code:

$category_id = hikaInput::get()-&gt;getInt('cid');

If you want to get the category object with its name: Code:

if(!defined('DS')) define('DS',DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return; $category_id = hikaInput::get()-&gt;getInt('cid'); if(!empty($category_id)) { $categoryClass = hikashop_get('class.category'); $category = $categoryClass-&gt;get($category_id); echo $category-&gt;category_name; }

Note that if you are in the context of a HikaShop view file (like a listing template), the category ID is often already available in the $this-&gt;pageInfo-&gt;filter-&gt;cid variable.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS85MDQ5MjMtaG93LWdldC1jYXRlZ29yeS1uYW1lLWluLWN1c3RvbS1wbHVnaW4/dG1wbD1tYXJrZG93bg==) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.067 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
