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

#   Problem with Cart ID on new Cart...

##

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

Less More

- Posts: 23
- Thank you received: 0
-
-

15 years 7 months ago [\#13423](#13423) by [luciomonter](/forum/user/673-luciomonter "View luciomonter's Profile")  *[Problem with Cart ID on new Cart...](/forum/4-how-to/13423-problem-with-cart-id-on-new-cart#13423 "Hi everybody, Hi Nicolas! Got this problem... from this code:  $cartClass = hikashop::get('class.cart');  if(!($cartClass-&gt;hasCart())){ $cartClass-&gt;initCart(); }  $currentCartId = $cartClass-&gt;cart-&gt;cart&#95;id;  Well, if I have to instance a new cart, entering the IF clause, I get an ID (for example: 230) while if a Cart already exist, for example the second time I add a product to the cart i created before, I get the ID + 1 (for example: 231). From the third time on I get always the &quot;right&quot; ID that is the same as the second (for example: 231)  Any ideas??! Cheers")* was created by *[luciomonter](/forum/user/673-luciomonter "View luciomonter's Profile")*

Hi everybody, Hi Nicolas!
Got this problem... from this code:

*$cartClass = hikashop::get('class.cart');

if(!($cartClass-&gt;hasCart())){
$cartClass-&gt;initCart();
}

$currentCartId = $cartClass-&gt;cart-&gt;cart\_id;*

Well, if I have to instance a new cart, entering the IF clause, I get an ID (for example: 230)
while if a Cart already exist, for example the second time I add a product to the cart i created before, I get the ID + 1 (for example: 231).
From the third time on I get always the "right" ID that is the same as the second (for example: 231)

Any ideas??!
Cheers

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

15 years 7 months ago [\#13472](#13472) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Re: Problem with Cart ID on new Cart...](/forum/4-how-to/13423-problem-with-cart-id-on-new-cart#13472 "Hi everybody, Hi Nicolas! Got this problem... from this code:  $cartClass = hikashop::get('class.cart');  if(!($cartClass-&gt;hasCart())){ $cartClass-&gt;initCart(); }  $currentCartId = $cartClass-&gt;cart-&gt;cart&#95;id;  Well, if I have to instance a new cart, entering the IF clause, I get an ID (for example: 230) while if a Cart already exist, for example the second time I add a product to the cart i created before, I get the ID + 1 (for example: 231). From the third time on I get always the &quot;right&quot; ID that is the same as the second (for example: 231)  Any ideas??! Cheers")*

Hi,

I don't understand why you have such code ?

There is no such code in hikashop.

We never initialize the cart from the outside of the cart class because when we call the update function of that class to add/modify a product in it, the cart is initialized automatically.

you should not have the code:
if(!($cartClass-&gt;hasCart())){
$cartClass-&gt;initCart();
}

but just:
$cartClass-&gt;initCart();

like in the update function.

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

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