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

#   Count the items in mini cart

##

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

Less More

- Posts: 129
- Thank you received: 0
-
-

10 years 4 months ago [\#242280](#242280) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#242280 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")* was created by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")*

-- HikaShop version -- : 2.6.3
-- Joomla version -- : 3.5.1

hi,
i'm using this code to return the number of items in my mini cart, Code:

if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; $cartClass = hikashop_get('class.cart'); $fullCart = $cartClass-&gt;loadFullCart(); $nbProducts = 0; foreach($fullCart-&gt;products as $product){ $nbProducts += $product-&gt;cart_product_quantity; } echo $nbProducts;

first i want you to tell me if my code is wrong or correct ?
then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

10 years 4 months ago [\#242282](#242282) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#242282 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

also i want an if condition like this:

if user has an item in cart {do this }
else { do that }

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODQ5NTItY291bnQtdGhlLWl0ZW1zLWluLW1pbmktY2FydD90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

10 years 4 months ago -  10 years 4 months ago [\#242285](#242285) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#242285 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hi,

Yes, the code is correct.
To skip the options, you want to add the line:
if($group &amp;&amp; $row-&gt;cart_product_option_parent_id) continue;
before the line:
$nbProducts += $product-&gt;cart_product_quantity;

And for your second question:
if($nbProducts){do this }
else { do that }

Last edit: 10 years 4 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

10 years 3 months ago [\#244833](#244833) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#244833 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

okay then
so i should use this code: Code:

&lt;?php if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; $cartClass = hikashop_get('class.cart'); $fullCart = $cartClass-&gt;loadFullCart(); $nbProducts = 0; foreach($fullCart-&gt;products as $product){ if($group &amp;&amp; $row-&gt;cart_product_option_parent_id) continue; $nbProducts += $product-&gt;cart_product_quantity; } echo $nbProducts; ?&gt;

but it returns "0" while i have 3 product with selected options in my cart.

when i remove this line : Code:

if($group &amp;&amp; $row-&gt;cart_product_option_parent_id) continue;

it returns"11" which is my product count + their options.

i want the code to return "3" as the count of only my main products in cart!

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

10 years 3 months ago [\#244835](#244835) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#244835 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

i also want the mini cart to show up the shop-card ul list with a message of "nothing in cart" inside it.
but when shopping cart is empty nothing happens when i click on mini card icon.

can you give me a help on this too ?

thanks

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODQ5NTItY291bnQtdGhlLWl0ZW1zLWluLW1pbmktY2FydD90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

10 years 3 months ago -  10 years 3 months ago [\#244834](#244834) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#244834 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

The variable $group is not defined in your code.
You first need to add the code:
$config = hikashop_config();
$group = $config-&gt;get('group_options');

I don't know how you built your mini cart module so hard to say.
By default with the mini cart module of HikaShop, when you click on the link of the mini cart, it directs you to the checkout. And if there is no products in the cart, the mini cart displays by default a message saying that the cart is empty, and there is no link.

Last edit: 10 years 3 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 9 months ago [\#260068](#260068) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#260068 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

how can i make hikashoping cart module to show up when its empty and show me a message like "cart is empty" instead of not doing anything at all when it's empty !
it's like a corrupted cart when nothing is in cart nothing will happen when user clicks on the logo !

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODQ5NTItY291bnQtdGhlLWl0ZW1zLWluLW1pbmktY2FydD90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

9 years 9 months ago [\#260074](#260074) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#260074 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hi,

The default HikaShop cart module of HikaShop, that is installed by default with HikaShop already display a message "the cart is empty" when the cart is empty.
Also, if you click on the "proceed to checkout" button of the cart module, or on its link when in mini cart mode, it will redirect you to the checkout. And if the checkout finds that the current cart is empty, it will redirect you to the URL that you set in "URL where you will be redirected when the cart is empty" setting of the HikaShop configuration and will also display a message saying that the cart is empty.

So I don't see what you're talking about.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 9 months ago [\#260211](#260211) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#260211 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

my hikashop version is 2.6.3
in this version hikashop cart is not loading anything when cart is empty !
i think this ability that u are saying is on 2.6.4 right ?

if so can you please tell me how to only update the hika cart module ?

thanks

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODQ5NTItY291bnQtdGhlLWl0ZW1zLWluLW1pbmktY2FydD90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

9 years 9 months ago [\#260216](#260216) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#260216 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hi,

No. This ability has been in the HikaShop cart module since HikaShop 1.0.0 and was also there in the 2.6.3.
So if you don't see any message in your cart when empty it's etiher:
- That you have a translation override of that text to remove it
- That you've changed the option for the cart empty message in the HikaShop cart module
- That you or your template provider have customized the layout of the cart to not display that message in the cart
- That's you're using a third party cart module which doesn't display that message
Updating HikaShop won't help.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 4 months ago -  9 years 4 months ago [\#271324](#271324) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271324 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello Nicolas,
on a new project, i'm trying to show the numbers of Main Product inside the cart at bottom of cart drop down.
i'm using this line of codes but it counts the product Options too.
for example with i have two product with Option and Characteristic it count it as 3 instead of 1 !
how can i remove Characteristic and Options from Product count in this code? Code:

&lt;?php $config = hikashop_config(); $group = $config-&gt;get('group_options'); if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; $cartClass = hikashop_get('class.cart'); $fullCart = $cartClass-&gt;loadFullCart(); $nbProducts = 0; foreach($fullCart-&gt;products as $product){ if($group &amp;&amp; $row-&gt;cart_product_option_parent_id) continue; $nbProducts += $product-&gt;cart_product_quantity; } echo $nbProducts; ?&gt;

Last edit: 9 years 4 months ago by [Jerome](/forum/user/80-jerome "View Jerome's Profile").

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

9 years 4 months ago [\#271361](#271361) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271361 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello,

"product_parent_id" indicates if the element is a main (0) or a variant (not 0).
"cart_product_quantity" indicates if the element is used or just used to have content data (when a variant do not have a data, the data is taken from the parent ; so the parent is in the cart but with no quantity to not interact with the display)

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 4 months ago [\#271533](#271533) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271533 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello Jerome,
thanks for your explanation you are right cause I have variants (Product Type) assigned to the main product,
with this explanations.
is there any way to count only the main products?
i don't want the variants (Type Product or not) to be counted as a product (Main) in the cart ! ![:-(](/media/kunena/emoticons/22.png ":-(")
is there any trick or hint you can tell me?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI2LXByb2R1Y3QtY2F0ZWdvcnktZGlzcGxheS84ODQ5NTItY291bnQtdGhlLWl0ZW1zLWluLW1pbmktY2FydD90bXBsPW1hcmtkb3du) 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")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14278
-
-

9 years 4 months ago [\#271541](#271541) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271541 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hi,

As Jerome said, "product_parent_id" indicates if the element is a main (0) or a variant (not 0).
So you can use:
if(!$product-&gt;product_parent_id) continue;
To skip variants in your counting.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 4 months ago -  9 years 4 months ago [\#271566](#271566) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271566 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello Nicolas,
Thank you for your answer,
i've tried to skip the variants from counting as you said but i think there is something wrong or something i'm mistaking about.

i tried this line of codes and it's still counting the variant with the main product.

&lt;?php
$cartClass = hikashop_get('class.cart');
$fullCart = $cartClass-&gt;loadFullCart();
$nbProducts = 0;
foreach($fullCart-&gt;products as $product){
if(!$product-&gt;product_parent_id) continue;
$nbProducts += $product-&gt;cart_product_quantity;

}
echo $nbProducts;

?&gt;

i'm sorry if i'm asking to much but i rally appreciate it if you can tell me what i'm doing wrong with these line of codes ?

Thanks ![:-)](/media/kunena/emoticons/3.png ":-)")

Last edit: 9 years 4 months ago by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile").

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

9 years 4 months ago [\#271567](#271567) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271567 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello,

Why not simply using the data from the cart object ?
If you update to HikaShop 3 ; you will be able to access to the $cart-&gt;quantity-&gt;total and $cart-&gt;quantity-&gt;items.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 4 months ago [\#271597](#271597) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271597 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello Jerome,
I tried that but it's not giving me the count of ONLY main products yet!

can you please do me a favor at giving me the exact line of codes that can echo the count of the main product inside cart?
or tell me how to use $cart-&gt;quantity-&gt;total and $cart-&gt;quantity-&gt;items and filter the variants and options from count ?

P.S: i'm using the latest version of Hikashop.

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

- **[Jerome](/forum/user/80-jerome "View Jerome's Profile")**
- [![Jerome's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar80.png)](/forum/user/80-jerome "View Jerome's Profile")
- [ Offline](/forum/user/80-jerome)
- HikaShop core developer

Less More

- Posts: 26394
- Thank you received: 4078
-
- [](http://obsi.dev)
-

9 years 4 months ago [\#271598](#271598) by [Jerome](/forum/user/80-jerome "View Jerome's Profile")  Replied by *[Jerome](/forum/user/80-jerome "View Jerome's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271598 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello,

I gave you the required code for latest version of HikaShop (3.x) in my previous message.
Afterwards, I'm afraid that I'm not following you.

Regards,

---

Jerome - Obsidev.com
HikaMarket &amp; HikaSerial developer / HikaShop core dev team.

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

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

Less More

- Posts: 129
- Thank you received: 0
-
-

9 years 4 months ago -  9 years 4 months ago [\#271720](#271720) by [nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")  Replied by *[nic7071](/forum/user/42433-nic7071 "View nic7071's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271720 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hi,
I have HikaShop 3.1.1 installed.
I want to add a code to show the number of main products inside the cart!
My problem is that the line of codes I'm using and you are saying are counting the product variant and options too.
For example, when I add a product to cart with 12-month warranty (Options) and software package (Variants) the counter shows 3 instead of one!
I want the counter to only count the main product.
You have done me a favor and told me to use this code $cart-&gt;quantity-&gt;total or $cart-&gt;quantity-&gt;items but these codes are also counting the variants and options too.

this is my final code and it returens 3 instead of 1 : Code:

&lt;?php $config = hikashop_config(); $group = $config-&gt;get('group_options'); if(!defined('DS')) define('DS', DIRECTORY_SEPARATOR); if(!include_once(rtrim(JPATH_ADMINISTRATOR,DS).DS.'components'.DS.'com_hikashop'.DS.'helpers'.DS.'helper.php')) return true; $cartClass = hikashop_get('class.cart'); $fullCart = $cartClass-&gt;loadFullCart(); $nbProducts = 0; foreach($fullCart-&gt;products as $product){ if($group &amp;&amp; $row-&gt;cart_product_option_parent_id) continue; $nbProducts += $product-&gt;cart_product_quantity; } echo $nbProducts; echo $cart-&gt;quantity-&gt;total; echo $cart-&gt;quantity-&gt;items; ?&gt; &lt;?php $cart-&gt;quantity-&gt;items ?&gt;

Last edit: 9 years 4 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

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

- **[Philip](/forum/user/34318-philip "View Philip's Profile")**
- [![Philip's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar34318_2015-11-18-2.png)](/forum/user/34318-philip "View Philip's Profile")
- [ Offline](/forum/user/34318-philip)

Less More

- Posts: 4820
- Thank you received: 654
-
-

9 years 4 months ago -  9 years 4 months ago [\#271755](#271755) by [Philip](/forum/user/34318-philip "View Philip's Profile")  Replied by *[Philip](/forum/user/34318-philip "View Philip's Profile")* on topic *[Count the items in mini cart](/forum/26-product-category-display/884952-count-the-items-in-mini-cart#271755 "-- HikaShop version -- : 2.6.3 -- Joomla version -- : 3.5.1  hi, i'm using this code to return the number of items in my mini cart,  first i want you to tell me if my code is wrong or correct ? then i want to exclude the options from count. i want to only count the main products my current code returns 3 when i have a product with to options in my cart. i want it to return 1 instead of 3 .")*

Hello,

I will go back your aim :
Is to have a mini cart with the number item (without variants &amp; options), right ?
So, **without** override view or custom... Let's try to go to **Main** HikaShop Configuration (in **Components** =&gt; **HikaShop** =&gt; **Configuration**) and in **Product** part switch **ON** "**Group options with product**"
As result, I get this :

[ ![minCart.png](/forum/attachment/38615) ](/forum/attachment/38615 "minCart.png")

Hope this will fit your needs.

Regards

- [ ![minCart.png](/forum/attachment/38615) ](/forum/attachment/38615 "minCart.png") [ ](/forum/attachment/38615?download=1 "minCart.png")

Last edit: 9 years 4 months ago by [Philip](/forum/user/34318-philip "View Philip's Profile").

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

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

[](#top)
