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

#   How to get cart count in php module

##

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

Less More

- Posts: 217
- Thank you received: 4
-
-

8 years 1 month ago [\#298897](#298897) by [FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")  *[How to get cart count in php module](/forum/27-checkout/895918-how-to-get-cart-count-in-php-module#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:  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!")* was created by *[FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")*

-- 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-&gt;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](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NTkxOC1ob3ctdG8tZ2V0LWNhcnQtY291bnQtaW4tcGhwLW1vZHVsZT90bXBsPW1hcmtkb3du) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")**
- [![Mohamed Thelji's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar6861.png)](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")
- [ Offline](/forum/user/6861-mohamed-thelji)

Less More

- Posts: 12953
- Thank you received: 1778
-
-
-

8 years 1 month ago [\#298915](#298915) by [Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")  Replied by *[Mohamed Thelji](/forum/user/6861-mohamed-thelji "View Mohamed Thelji's Profile")* on topic *[How to get cart count in php module](/forum/27-checkout/895918-how-to-get-cart-count-in-php-module#298915 "-- 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:  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!")*

Hello,

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

$cartClass = hikashop_get('class.cart'); $oldCart = $cartClass-&gt;get(0); $cart_count = 0; if(!empty($oldCart)){ foreach($oldCart-&gt;cart_products as $cart_product){ $cart_count += $cart_product-&gt;cart_product_quantity; } } echo 'cart count : '. $cart_count;

Kind regards,
Mohamed Thelji.

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

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

Less More

- Posts: 217
- Thank you received: 4
-
-

8 years 1 month ago -  8 years 1 month ago [\#298952](#298952) by [FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")  Replied by *[FilipHradil](/forum/user/36153-filiphradil "View FilipHradil's Profile")* on topic *[How to get cart count in php module](/forum/27-checkout/895918-how-to-get-cart-count-in-php-module#298952 "-- 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:  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!")*

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) &#124;&#124; !include_once($hikashopHelper)) return;

Is that okay?

And it works!

Thank you,
Filip

Last edit: 8 years 1 month ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile"). Reason: [code] tag is nice

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NTkxOC1ob3ctdG8tZ2V0LWNhcnQtY291bnQtaW4tcGhwLW1vZHVsZT90bXBsPW1hcmtkb3du) 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: 86587
- Thank you received: 14326
-
-

8 years 1 month ago [\#298954](#298954) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[How to get cart count in php module](/forum/27-checkout/895918-how-to-get-cart-count-in-php-module#298954 "-- 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:  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!")*

Hi,

Yes it's ok !

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

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