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

#   Get the categories

##

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

Less More

- Posts: 107
- Thank you received: 4
-
-

1 year 7 months ago [\#366845](#366845) by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")  *[Get the categories](/forum/31-development/909364-get-the-categories#366845 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")* was created by *[rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")*

How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwOTM2NC1nZXQtdGhlLWNhdGVnb3JpZXM/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: 86586
- Thank you received: 14325
-
-

1 year 7 months ago [\#366847](#366847) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#366847 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Hi,

In onCheckoutStepDisplay you can get the cart data with such code: Code:

$cart = $view-&gt;checkoutHelper-&gt;getCart();

Once you have the $cart object, you can access the data of the products in it in $cart-&gt;products which is an array of product objects.
So, you want to loop on this array, get the product_id of each product and if the product_type of the product is equal to "variant", you want to use product_parent_id instead.
Then, you can use such code to load the id of the categories of a product: Code:

$productClass = hikashop_get('class.product'); $categoryIds = $productClass-&gt;getCategories($product_id);

And then, if you need the data of the category, you can load it like this: Code:

$categoryClass = hikashop_get('class.category'); $category = $categoryClass-&gt;get($category_id);

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

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

Less More

- Posts: 107
- Thank you received: 4
-
-

1 year 7 months ago -  1 year 7 months ago [\#366868](#366868) by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")  Replied by *[rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#366868 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Ok - a few more questions.
Code:

$productClass = hikashop_get('class.product'); $categoryIds = $productClass-&gt;getCategories($product_id);

How do I get the "hikashop_get" in a plugin ?? and $categoryIds - will this be an array ?

Last edit: 1 year 7 months ago by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwOTM2NC1nZXQtdGhlLWNhdGVnb3JpZXM/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: 86586
- Thank you received: 14325
-
-

1 year 7 months ago [\#366870](#366870) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#366870 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Hi,

If you're developing a plugin implementing the event onCheckoutStepDisplay, I suppose the group of the plugin is "hikashop". In that case, before your plugin is loaded by HikaShop, HikaShop's main functions are already loaded, hikashop_get being one of them.
So you don't need anything to be able to use it.
If you're writing code for a Joomla website outside of a HikaShop plugin, and there is a possibility HikaShop itself is not loaded, you can load it by calling its main helper, as explained at the beginning of our "PHP code samples" documentation:
[ www.hikashop.com/support/documentation/6...umentation.html#code](https://www.hikashop.com/support/documentation/62-hikashop-developer-documentation.html#code)

$categoryIds will indeed be an array of category ids.

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

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

Less More

- Posts: 107
- Thank you received: 4
-
-

1 year 7 months ago [\#366879](#366879) by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")  Replied by *[rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#366879 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Thank you, I got it working.

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

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

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

Less More

- Posts: 107
- Thank you received: 4
-
-

1 year 6 months ago [\#367038](#367038) by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")  Replied by *[rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#367038 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

And now another question for this. I need to show alle the hikashop categorynames in a multiselectbox in the settings of the plugin. The custom dropdown field itself is no problem, but how do I populate it with the Hikashop categories with parent categories, sub category 1, sub category 2... etc and then if you select a parent all of the sub should also be selected?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwOTM2NC1nZXQtdGhlLWNhdGVnb3JpZXM/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: 86586
- Thank you received: 14325
-
-

1 year 6 months ago [\#367040](#367040) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#367040 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Hi,

There is no ready made element for this exactly.

In HikaShop Business, you have the "Google Products" plugin which you can configure via the Joomla plugins manager.
If you edit it, you'll see an option "categories" where you can select categories so that the XML file generated by the plugin will only contain products from the selected categories.
Using that selector in your own plugin is easy. If you look at the XML of the Google Products plugin ( folder plugins/hikashop/google_products/ ), you'll see this option implemented like this: Code:

&lt;field name="categories" multiple="true" namebox_type="category" type="hikanamebox" default="" label="PRODUCT_CATEGORIES" description="GOOGLE_PRODUCTS_CATEGORIES" /&gt;

Joomla has a list of standard field types here: [ docs.joomla.org/standard\_form\_field\_types](https://docs.joomla.org/standard_form_field_types)
You can see that the type "hikanamebox" is not among them. It's a custom type HikaShop makes available so that you can use the advanced selectors available in the interface of HikaShop here and there.
Note also that to be able to use it, the plugin XML file also has this line: Code:

&lt;fields name="params" addfieldpath="/components/com_hikashop/fields"&gt;

The folder /components/com_hikashop/fields/ is where HikaShop has its custom field types, including the file hikanamebox.php hich defines that type. If you check that file, you'll see that it loads HikaShop and uses the type.namebox of HikaShop and follows the recommendations here: [ docs.joomla.org/Creating\_a\_custom\_form\_field\_type](https://docs.joomla.org/Creating_a_custom_form_field_type)

So, the quick solution is to add in your plugin XML the same addfieldpath attribute, and you'll be able to use the type "hikanamebox" with the "namebox_type" attribute set to "category" and the "multiple" attribute set to true. That way, you'll get the same category selector.
And, building on all of this, you can also have your own fields folder in your plugin, and have your own custom type file in it, so that your plugin can reference it in its XML. With your own type, you can run the MySQL queries you want, run the PHP code you want, and output the option with checkboxes, the auto select of the children radios with some javascript code, etc. It will be quite a lot more work than reusing the hikanamebox type, but maybe it's worth it.

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

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

Less More

- Posts: 107
- Thank you received: 4
-
-

1 year 6 months ago -  1 year 6 months ago [\#367046](#367046) by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")  Replied by *[rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#367046 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

Ok thank you - that was easy to implement. But now I need the piece of code that checks each selected categori, so that if it is a parent, all of the sub, and sub sub, and so on.. categories musty also be added to my array? Do you have an idea for that ? I will have to implement that in my main plugin code.

Last edit: 1 year 6 months ago by [rbuelund](/forum/user/65065-rbuelund "View rbuelund's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwOTM2NC1nZXQtdGhlLWNhdGVnb3JpZXM/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: 86586
- Thank you received: 14325
-
-

1 year 6 months ago [\#367051](#367051) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Get the categories](/forum/31-development/909364-get-the-categories#367051 "How would I get the categories of all the products in the basket with this Checkout API: onCheckoutStepDisplay($layoutName, &amp;$html, &amp;$view)")*

You can use this code to get the data of the children categories: Code:

$categoryClass = hikashop_get('class.category'); $children = $categoryClass-&gt;getChildren($id, true);

The second parameter defines if you want only the direct sub categories (with false) or all the sub categories regardless of the depth level (with true).

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtL2RldmVsb3BtZW50LzkwOTM2NC1nZXQtdGhlLWNhdGVnb3JpZXM/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.090 seconds

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