How to get cart count in php module

  • Posts: 217
  • Thank you received: 4
6 years 1 month ago #298897

-- 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:

$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.

  • Posts: 12953
  • Thank you received: 1778
6 years 1 month ago #298915

Hello,

You'll just have to calculate product quantity in the $oldCart->cart_products variable, using the following code will probably do the job :

$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.

  • Posts: 217
  • Thank you received: 4
6 years 1 month ago #298952

Hello,

Thank you.

I only add this code from old extension:

$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: 6 years 1 month ago by Jerome. Reason: [code] tag is nice

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

  • Posts: 82867
  • Thank you received: 13373
  • MODERATOR
6 years 1 month ago #298954

Hi,

Yes it's ok !

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

Time to create page: 0.074 seconds
Powered by Kunena Forum