- Posts: 217
- Thank you received: 4
Disable cart or cart memory
- FilipHradil
-
Topic Author
- Offline
Hello,
I am starting eshop with wedding dresses. So I assume that customer won't buy more than 1 product.
I have hidden cart and after adding item to cart customer is redirected to checkout.
But when customer quit his checkout and buy item again he have to pay for both two items.
I need to disable cart, or its memory in order to pay just for one item (last added to cart).
Thank you
Filip
Please Log in or Create an account to join the conversation.
Click on the "limit" button of the products listing in your backend. There, create a new limit. In it, set the "period" to "cart", the "type" to "quantity" and the "value" to "1" and that will only allow one item in the cart.
When the user will try to add a second product in the cart, it will display an error message to the user.
That's the closest you can get to what you need without any coding.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
I hope you understand me.
Thank you in advance
F
Please Log in or Create an account to join the conversation.
In that case, you should not use a limit and develop a HikaShop plugin implementing in it the onBeforeCartUpdate trigger where you would call $cartClass->resetCart in order to reset the cart whenever a user would add a product to the cart.
As I said in my previous message, the limit configuration is the closest to what you want without coding anything.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
I did plugin exacly by developers documentation.
Thank you
Please Log in or Create an account to join the conversation.
- Posts: 12953
- Thank you received: 1778
Are you sure that you have correctly published your plugin ? if yes, you should probably add some debug code on your plugin to see if it's really called.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
yes plugin is really published.
Could you send me example of debug?
Many thanks
FILIP
Please Log in or Create an account to join the conversation.
You should remove the line:
$cartClass = hikashop_get('class.cart');
as $cartClass is already given to you.
And you don't want the redirect either or the product wouldn't be added to the cart at all.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
Thank you very much I will try it as soon as I get home.
I need on current procedure to remove existing items to cart,
add new item and go to checkout.
Thank you
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
I think the trigger isn't called or plugin isn't loaded.
Could you check it please? I am helpless

Please log in or register to see it.
Please Log in or Create an account to join the conversation.
take.ms/TcZxf
So the trigger is called just fine.
Note that if you turned on the "Use AJAX when possible for add to cart buttons" option of the HikaShop configuration, the add to cart will be done in ajax and thus you won't see your debug text and even without that, the message won't display on the page if you do a redirect just after that.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
thank you.
I have display Use AJAX..... in hikashop configuration.
I don't know if I code the plugin correctly, its my first plugin.
I installed it in joomla extension manager, allowed it and after I checked that is allowed in hikashop plugins.
Have I forgotten something?
Thank you
Filip
Please Log in or Create an account to join the conversation.
You have done all the needed steps to use the plugin.
As Nicolas said, to check if the plugin is called, you have to disable the AJax option in HikaShop and add an "exit;" after the "it works!" text to see the result.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
But cart will be reseted and clicked item wasn't added. Even if the code is in onBeforeCartUpdate procedure.
Can somebody advise me method which remove oldest product in cart?
Thank you
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
Is there any method which removes only 1 item from cart (first added)?
Thank you
Please Log in or Create an account to join the conversation.
I'm guessing that some other variables should be reset in the cartClass variable.
Maybe a simpler solution would be to do the add to cart yourself after the reset like that:
$cartClass = hikashop_get('class.cart');
$cartClass->resetCart();
$cartContent = $cartClass->get();
$cartClass->updateEntry($quantity,$cartContent,(int)$product_id,1,false,$type,$force);
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
I place your code in onBeforeCartUpdate procedure but after clicking button "add to cart"
the blank page with this url was open (........product/updatecart)
Maybe some redirect to cart needed?
Thank you
Please Log in or Create an account to join the conversation.
There was a typo in my code. I've edited my post to fix it. That should avoid the blank page.
Please Log in or Create an account to join the conversation.
- FilipHradil
-
Topic Author
- Offline
- Posts: 217
- Thank you received: 4
thank you!!!
There was just little problem but if condition made it
Please, last little query, how can I logout user (just logout - without redirecting)
Thank you!
Please Log in or Create an account to join the conversation.