Jump to content

AJAXCART: Empty the cart BEFORE adding a new product


evcz

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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) :(

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated