evcz Posted October 16, 2013 Share Posted October 16, 2013 Hi, I'm trying to empty the cart before adding a new product to it. Basically I want the cart to just keep one product in it and always remove whatever is in it. I've tried an hook like: function empty_cart() { unset($_SESSION["cart"]); } add_hook("ShoppingCartValidateProductUpdate",1,"empty_cart"); but that does nothing as products keeps getting added to the cart one after the other and they never get delete. Any suggestion? I'm fine paying for this if someone has a clean and easy solution, just contact me Thank you 0 Quote Link to comment Share on other sites More sharing options...
ditto Posted October 16, 2013 Share Posted October 16, 2013 This is what I do: I add &cc=1 to the end of the url to the product, so it can look like this: cart.php?a=add&pid=1&cc=1 Then I create a new php file wich I call clearcart.php with the following content: <?php if ($_REQUEST["cc"] == "1") { unset($_SESSION["cart"]); } ?> Then I upload clearcart.php to this path: /includes/hooks/clearcart.php This way the cart will be empty every time you click on a order link with &cc=1 at the end of the url. Maybe you can change this to fit your needs. 0 Quote Link to comment Share on other sites More sharing options...
jonnyg Posted October 17, 2013 Share Posted October 17, 2013 Thanks ditto, I was looking for exactly this when I found your post. Works a treat! 0 Quote Link to comment Share on other sites More sharing options...
evcz Posted October 17, 2013 Author Share Posted October 17, 2013 that solutions cannot work with ajaxcart the only way to do something similar (but still broken) I've found is adding this code: {php} if(sizeof($_SESSION['cart']['products']) > 1){ {/php} {literal} <script type="text/javascript"> jQuery.post("cart.php", 'a=remove&r=p&i=0',function() { recalcsummary(); }); </script> {/literal} {php} } {/php} At the very end of templates/orderforms/ajaxcart/cartsummary.tpl but it is broken... it empty the whole cart deleting both products and not just the older (id=0) one!!! I'm really out of ideas right now A hook like this: if($_REQUEST['a'] == 'confproduct'){ while(sizeof($_SESSION['cart']['products']) > 1){ array_shift($_SESSION['cart']['products']); $_SESSION['cart']['cartsummarypid'] = $_SESSION['cart']['products'][0]['pid']; $_SESSION['cart']['domainoptionspid'] = $_SESSION['cart']['products'][0]['pid']; //unset($_SESSION['cart']['newproduct']); } } doesn't work at all with ajax cart resulting in costant errors (not loading the DIV with the options) 0 Quote Link to comment Share on other sites More sharing options...
evcz Posted October 18, 2013 Author Share Posted October 18, 2013 Ok, to get it working you need to place the code I pasted above {php} if(sizeof($_SESSION['cart']['products']) > 1){ {/php} {literal} <script type="text/javascript"> jQuery.post("cart.php", 'a=remove&r=p&i=0',function() { recalcsummary(); }); </script> {/literal} {php} } {/php} at the very end of templates/orderforms/ajaxcart/configureproduct.tpl it will properly remove the previous products, there's only a little issue left: ajaxcart is broken! As soon as you remove a previous product the cart stop working (cannot proceed, nor change current product options) Awaiting a fix from whmcs... 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.