Skip to main content

How to get cart count in php module

More
7 years 11 months ago #298897 by FilipHradil
-- HikaShop version -- : 4.0.
-- Joomla version -- : 3.8.13

Hello,

on my website I developed with your help simple module that says coun of products in cart:
Code:
$cartClass = hikashop_get('class.cart'); $oldCart = $cartClass->get(); if(!empty($oldCart)){ ..... }

But after update of Hikashop it doesn't work anymore. Please, could you tell how to get variable with cart count in custom module?

I know it can be done with your plugin, but for my needs I need this solution.


Thank you in advance for your time!

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

More
7 years 11 months ago #298915 by Mohamed Thelji
Hello,

You'll just have to calculate product quantity in the $oldCart->cart_products variable, using the following code will probably do the job :
Code:
$cartClass = hikashop_get('class.cart'); $oldCart = $cartClass->get(0); $cart_count = 0; if(!empty($oldCart)){ foreach($oldCart->cart_products as $cart_product){ $cart_count += $cart_product->cart_product_quantity; } } echo 'cart count : '. $cart_count;

Kind regards,
Mohamed Thelji.

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

More
7 years 11 months ago - 7 years 11 months ago #298952 by FilipHradil
Hello,

Thank you.

I only add this code from old extension:
Code:
$hikashopHelper = rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_hikashop'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php'; if(!file_exists($hikashopHelper) || !include_once($hikashopHelper)) return;
Is that okay?

And it works!

Thank you,
Filip
Last edit: 7 years 11 months ago by Jerome. Reason: [code] tag is nice

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

More
7 years 11 months ago #298954 by nicolas
Hi,

Yes it's ok !

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

Time to create page: 0.199 seconds
Powered by Kunena Forum