Empty Cart Button

  • Posts: 202
  • Thank you received: 2
13 years 8 months ago #14276

Is there a way to add a button into the cart view that will allow a user to clear all the contents of the cart with one click?

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 8 months ago #14277

Sure:
<a href="<?php echo hikashop::completeLink('product&task=cleancart'); ?>">Empty Cart</a>

Please Log in or Create an account to join the conversation.

  • Posts: 202
  • Thank you received: 2
13 years 8 months ago #14278

Thanks!!

Please Log in or Create an account to join the conversation.

  • Posts: 202
  • Thank you received: 2
13 years 8 months ago #14322

Nicolas,

I inserted this in the front-end Checkout->Cart file. It adds the link and is certainly clearing the cart. However, when the page refreshes the cart items still show on that screen, but browsing to another page (where the cart module is displayed) shows an empty cart. Is there a way to have the cart itself refresh and clear?

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
13 years 8 months ago #14324

In that case, you need to add a return parameter to the URL:
<a href="<?php echo hikashop::completeLink('product&task=cleancart&return_url='. urlencode(base64_encode(hikashop::currentURL('url')))); ?>">Empty Cart</a>

Please Log in or Create an account to join the conversation.

  • Posts: 202
  • Thank you received: 2
13 years 8 months ago #14325

Man, you are truly amazing!! Thanks!!!

Please Log in or Create an account to join the conversation.

  • Posts: 107
  • Thank you received: 3
12 years 6 months ago #54343

Hi. Where exatly may I put this code? I tried to put it in Views->Checkout->Cart ot the Frontend, but nothing happens. Could you help me please?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
12 years 6 months ago #54370

That view file is for the cart on the checkout. If you want the cart module, it should be the file "cart" of the view "product".
Also, make sure that you're doing it for your front end template and not another template.

Please Log in or Create an account to join the conversation.

  • Posts: 107
  • Thank you received: 3
12 years 6 months ago #54376

Thanks Nicolas. Yes, It was for the checkout module. Now I have my 'Empty Cart' link, but Is there a way for that link to appears like a button (like the 'Checkout' button)?

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
12 years 6 months ago #54440

Everything is possible. You could use that code instead for that:

<input name="Empty Cart" value="Empty Cart" onclick="window.location='<?php echo hikashop::completeLink('product&task=cleancart&return_url='. urlencode(base64_encode(hikashop::currentURL('url')))); ?>';return false;"/>

Please Log in or Create an account to join the conversation.

  • Posts: 107
  • Thank you received: 3
12 years 6 months ago #54469

WOWWWW!! Amazing!

Really everything is possible. It works perfectly, but I needed to add:

type="submit" class="button" before the name var, so the code looks:

<input type="submit" class="button" name="Empty Cart" value="Empty Cart" onclick="window.location='<?php echo hikashop::completeLink('product&task=cleancart&return_url='. urlencode(base64_encode(hikashop::currentURL('url')))); ?>';return false;"/>

and it works exactly as I wanted.

I think it's the fastest and the best support for the price I've ever had for a software bought. I don't know how you manage to answer so many posts so fast.

Thanks again Nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 263
  • Thank you received: 11
10 years 10 months ago #141464

When I use this code in templates/../html/checkout/cart.php and I click the new link, I know that the cart is empty.

<a href="<?php echo hikashop::completeLink('product&task=cleancart&return_url='. urlencode(base64_encode(hikashop::currentURL('url')))); ?>">Empty Cart</a>

But I still see item in cart until I refresh another time...

Last edit: 10 years 10 months ago by Flooder.

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
10 years 10 months ago #141569

Hi there,

You should try with hikashop_completeLink instead of hikashop::completeLink.
If if doesn't work, please give us a link to the page where we could test it.

The following user(s) said Thank You: Flooder

Please Log in or Create an account to join the conversation.

  • Posts: 263
  • Thank you received: 11
10 years 10 months ago #141695

your account is created and you received a private message. Thks

Please Log in or Create an account to join the conversation.

  • Posts: 263
  • Thank you received: 11
10 years 10 months ago #141719

This problem is solved for me with :

$lienredir = urlencode(base64_encode('index.php?option=com_hikashop&ctrl=checkout'));
		$url = 'index.php?option=com_hikashop&ctrl=product&task=cleancart&return_url='. $lienredir;
		
		?>
		<a class="btn button" href="<?php echo $url; ?>">Vider le panier</a>

I think SEF was my problem. I disabled it, found the real links, and reactivated it.

Please Log in or Create an account to join the conversation.

  • Posts: 2334
  • Thank you received: 403
10 years 10 months ago #141821

I'm glad you fixed it, thanks for sharing your solution!

Please Log in or Create an account to join the conversation.

  • Posts: 15
  • Thank you received: 0
10 years 6 months ago #161191

incase the above fails, as it did with mine, just delete from the database via a query. works best


:)


fFull-stack

Please Log in or Create an account to join the conversation.

  • Posts: 8
  • Thank you received: 0
1 year 7 months ago #351948

How would this code look if I want to return to a specifiek page after emptying the cart?

<a href="<?php echo hikashop::completeLink('product&task=cleancart'); ?>">

I would want to return to page: www.ev8.shop/#sp-main-body

Please Log in or Create an account to join the conversation.

  • Posts: 83024
  • Thank you received: 13403
  • MODERATOR
1 year 7 months ago #351952

Hi,

You can change the line:

$lienredir = urlencode(base64_encode('index.php?option=com_hikashop&ctrl=checkout'));
to:
$lienredir = urlencode(base64_encode('https://www.ev8.shop/#sp-main-body'));
in the code posted above.

Please Log in or Create an account to join the conversation.

  • Posts: 8
  • Thank you received: 0
1 year 6 months ago #351973

nicolas wrote: Hi,



You can change the line:
$lienredir = urlencode(base64_encode('index.php?option=com_hikashop&ctrl=checkout'));
to:
$lienredir = urlencode(base64_encode(' www.ev8.shop/#sp-main-body '));

in the code posted above.




Thank you. Can you help me just one step further? As I do not know how to do this. What I want is a custom button to empty the card, and then return to a specifiec page. I managed to empty the cart with this code:
<a class="btnbtn-rich" href="<?php echo hikashop::completeLink('product&amp;task=cleancart'); ?>">Start over</a>

But now I want an extra button somewhere else that brings the user back to ' www.ev8.shop/#sp-main-body ' after pressing the custom 'empty cart button".

I just do not understand how to integrate your suggested code into the code. Can you add the return url for me into:
<a class="btnbtn-rich" href="<?php echo hikashop::completeLink('product&amp;task=cleancart'); ?>">Start over</a>

Or suggest a tutorial where I can learn about it? I have googled but can't find any suitable.

Last edit: 1 year 6 months ago by loovanloon. Reason: clarifications and typo's

Please Log in or Create an account to join the conversation.

Time to create page: 0.155 seconds
Powered by Kunena Forum