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

#   Clear Cart before adding a product

##

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

Less More

- Posts: 259
- Thank you received: 22
-
-

7 years 11 months ago -  7 years 11 months ago [\#301358](#301358) by [rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")  *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#301358 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")* was created by *[rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")*

I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in the cart to just 1 which I can do in the configuration, however when a customer decides to change their selection they are not understanding that they need to remove the first product before adding a replacement. Is it possible for me to force the cart to be emptied each time before the plugin adds a product?

Last edit: 7 years 11 months ago by [rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile"). Reason: Correctec plugin name

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NjQwNS1jbGVhci1jYXJ0LWJlZm9yZS1hZGRpbmctYS1wcm9kdWN0P3RtcGw9bWFya2Rvd24=) 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: 14327
-
-

7 years 11 months ago [\#301374](#301374) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#301374 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hi,

That plugin doesn't add the product to the cart.
It only changes the price of a product in the cart based on a custom item field value attached to that product.

The add to cart process is done, I suppose, by a redirect of your custom component to the add to cart URL of the product with the custom item field value, or with custom code in the custom component which directly adds the product to the cart and then redirects to the checkout. In both cases, the best is to add some code before all that in the custom component to clear the cart. It can be done easily with such code once HikaShop's helper is loaded: Code:

$cartClass = hikashop_get('class.cart'); $cart_id = $cartClass-&gt;getCurrentCartId(); if(!empty($cart_id)) $cartClass-&gt;delete($cart_id);

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

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

Less More

- Posts: 259
- Thank you received: 22
-
-

7 years 11 months ago [\#301417](#301417) by [rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")  Replied by *[rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#301417 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Thanks Nicolas,
yes we do a redirect to the cart with the product details in the url.(/index.php?option=com_hikashop&amp;ctrl=product&amp;task=updatecart&amp;quantity=1&amp;product_id=1&amp;data[item][amount]=$invoiceAmount&amp;....)
That code snippet looks to be exactly what I was hoping for. Will test it today.

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

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

Less More

- Posts: 259
- Thank you received: 22
-
-

7 years 11 months ago [\#301419](#301419) by [rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")  Replied by *[rodfarrell](/forum/user/5859-rodfarrell "View rodfarrell's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#301419 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

That code gives me an error "Call to undefined function hikashop_get()"
Do I have to call the Hikashop helper first?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NjQwNS1jbGVhci1jYXJ0LWJlZm9yZS1hZGRpbmctYS1wcm9kdWN0P3RtcGw9bWFya2Rvd24=) 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: 14327
-
-

7 years 11 months ago [\#301425](#301425) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#301425 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hi,

Yes, that's what I was saying in my previous message ![:)](/media/kunena/emoticons/3.png ":)")
You can do it like that: 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;

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

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

Less More

- Posts: 267
- Thank you received: 5
-
-
-
-

5 years 5 days ago [\#337393](#337393) by [dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile")  Replied by *[dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#337393 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hi Nicolas,
I have the same problem, I have the cart option so that only one product can be added.
When someone selects a product and then selects a different one, it does not change and the original product remains in the cart.
I see that you explain the solution in this query, but I don't know very well where to make the modification. Could you help me on this?
Thanks!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NjQwNS1jbGVhci1jYXJ0LWJlZm9yZS1hZGRpbmctYS1wcm9kdWN0P3RtcGw9bWFya2Rvd24=) 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: 14327
-
-

5 years 5 days ago [\#337396](#337396) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#337396 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hi,

I doubt you have the same problem as the problem was linked to some customization.
Could you provide a link to the shop with the issue and instructions to reproduce your issue so that I can have a look at the situation and understand what's going on ?

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

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

Less More

- Posts: 267
- Thank you received: 5
-
-
-
-

5 years 5 days ago -  5 years 5 days ago [\#337400](#337400) by [dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile")  Replied by *[dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#337400 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hello Nicolas,

when you choose a product from this page ...

[ www.universidadpopular.es/actividades-cu...es/eventos-en-la-upl](https://www.universidadpopular.es/actividades-culturales/eventos-en-la-upl)

.... the product is added correctly the first time. If you return to the page and choose another of the products in the cart, the first product remains. (Occurs with the products of the forum of spirituality).

Thanks!

Last edit: 5 years 5 days ago by [dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0Lzg5NjQwNS1jbGVhci1jYXJ0LWJlZm9yZS1hZGRpbmctYS1wcm9kdWN0P3RtcGw9bWFya2Rvd24=) 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: 14327
-
-

5 years 5 days ago [\#337401](#337401) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Clear Cart before adding a product](/forum/27-checkout/896405-clear-cart-before-adding-a-product#337401 "I'm using the Donations/Custom Price plugin to pass orders from a custom component to the Hikashop cart which works beautifully 99% of the time. I would like to limit the number of items allowed in...")*

Hi,

So I checked your page. From what I understand, you've configured your shop, probably with a limit, so that the customer cannot add several products of that page in the same cart.
After I add a product to the cart on your website, I'm getting automatically redirected to the checkout, without any notification box.
Normally in HikaShop you have a blue notification box which tells you that the product was successuflly add to the cart, or a red one which tells you that there is a problem.
The fact that you don't get it probably indicates that you've disabled the HikaShop cart notification plugin via the joomla plugins manager.
That's unfortunate because this leads to the system not displaying the error message when you add the second product to the cart.
If I manually access the add to cart URL of the second product, I get this:
[ i.imgur.com/rSt86K4.png](https://i.imgur.com/rSt86K4.png)
which tells me about the limit you must have configured.
So I would recommend to enable back this plugin. If you want HikaShop to redirect to the checkout after the add to cart, you can do it with that plugin activated, you just need to configure it accordingly. It will have the benefit of displaying an error message when there is a problem instead of directing you to the checkout without any indication of what's going on.

And regarding the limitation I can recommend several solutions:
- one would be to do like rodfarrell and develop a custom plugin to clear the cart before the add to cart process. Possible but it requires a developer to work on that for you.
- another would be to remove the limit, and add it instead as a shipping/payment method maximum quantity restriction. That way, the user would be able to add several products to the cart without problem, but he would be blocked on the checkout with an error message that can be customized to tell them that they have to remove from the cart some of the products to proceed. And you can configure the checkout workflow to display the cart view at this place so that they can easily do that.
- another solution would be to leave the limit like this, enable to cart notification plugin to get the error message when adding a second product and stay on the current page, and configure the HikaShop cart module, via the joomla plugins manager to display on that products listing so that the user can easily remove the product already in the cart.

The following user(s) said Thank You: [dvddvd](/forum/user/7721-dvddvd "View dvddvd's Profile")

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

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