- Posts: 27
- Thank you received: 0
clear the cart on add product
I have a digital product that have 3 versions (with different prices)
I already configured the product with the vars.
I dont want to allow my customer to select quantity of product (like you did) so I removed it from the product page and the cart page.
The problem is, if a user decide to go back and add to cart again, he will have 2 quantity (same as if I click add Essential product, then go to the product page again and click add again, I will have 2 quantity), so I limited the quantity to 1 and the item quantity to 1, so only one product could be bought at the same time.
The problem is, if a user decide to go back and select a different version, and click on add to cart, the old version is still there.
I'm looking for a way to clear the cart every time an item is added to it, so the most resent item will be in the cart.
Thanks.
Please Log in or Create an account to join the conversation.
Please Log in or Create an account to join the conversation.
here is the way to do it, be advised this is hard coding for the system so it may break on updates and such, always keep a change log for changes you make!!!
this is really simple, please , hika support, if this is not correct let me know.
you should edit this file: administrator/components/com_hikashop/classes/cart.php
just insert this code:
Please Log in or Create an account to join the conversation.
Something like this at line 208 (not tried it - just a suggestion for further consideration).
In this case the resetCart() call (followed by return true) would go into the plugin.JPluginHelper::importPlugin( 'hikashop' );
$dispatcher =& JDispatcher::getInstance();
if (!$dispatcher->trigger( 'onBeforeUpdateCart', $this, $cart, $product_id, $quantity, $add, $type )) return false;
For consistency an 'onAfterUpdateCart' trigger might be worth including after line 264.
Please Log in or Create an account to join the conversation.
Will look in to it (as I never built a plugin before) as soon as I have time....
Please Log in or Create an account to join the conversation.
However, the idea of brainforge is great.
We'll add that to next release so you can go ahead and make it a hikashop plugin with the code proposed by brainforge.
Note that we'll change the trigger name to onBeforeCartUpdate in order to be consistent with the name of triggers already in HikaShop.
Please Log in or Create an account to join the conversation.
Just wanted to let you know I have edited my code as it had a "bug" when I entered coupon on the cart was also cleared.
so i just added a check to my line:
Please Log in or Create an account to join the conversation.
They are in the folder plugins/hikashop on your website. Open them and change all the names of the plugin (xml, class name, etc), then put your code, zip the package and you can then install it via the joomla installer.
Please Log in or Create an account to join the conversation.
I'm looking to build this plug-in now, can you help me do it with the fix i added at the end?
I have copied the history plugin and renamed it (and the files inside) to clear_cart.
the code on the xml file:
Please Log in or Create an account to join the conversation.
plgHikashopClear_cart as well as the constructor function name.
Please Log in or Create an account to join the conversation.
in cart.php i have removed my code and inserted this one instead on line 208 just before the closing of this if: if($this->cart->cart_id){
this is my clear_cart.php file:
what am i doing wrong?
Please Log in or Create an account to join the conversation.
If you don't see there, it means that you didn't install it. In that case, zip the files of the plugin and install the zip via the extension installer of Joomla. Then you will be able to publish it.
Please Log in or Create an account to join the conversation.