Get the categories

  • Posts: 96
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
2 days 16 hours ago #366845

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

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

  • Posts: 83672
  • Thank you received: 13545
  • MODERATOR
2 days 11 hours ago #366847

Hi,

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

$cart = $view->checkoutHelper->getCart();
Once you have the $cart object, you can access the data of the products in it in $cart->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:
$productClass = hikashop_get('class.product');
$categoryIds = $productClass->getCategories($product_id);
And then, if you need the data of the category, you can load it like this:
$categoryClass = hikashop_get('class.category');
$category = $categoryClass->get($category_id);

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

  • Posts: 96
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
1 day 18 hours ago #366868

Ok - a few more questions.

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

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

Last edit: 1 day 18 hours ago by rbuelund.

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

  • Posts: 83672
  • Thank you received: 13545
  • MODERATOR
1 day 15 hours ago #366870

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

$categoryIds will indeed be an array of category ids.

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

  • Posts: 96
  • Thank you received: 4
  • Hikashop Business Hikashop Essential
19 hours 14 minutes ago #366879

Thank you, I got it working.

The following user(s) said Thank You: nicolas

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

Time to create page: 0.066 seconds
Powered by Kunena Forum