Post by goldndelicious » Sun Jan 24, 2010 5:37 am

Hi All,

Can anyone suggest how to code a button, or link where by when clicked, it will empty the entire contents of the cart without the user having to got to the basket?

Ideally i'd like to place this in the cart module if possible.

Thanks

personalised car signs
personalised bedroom door signs
personalised gifts for kids


New member

Posts

Joined
Sun Oct 04, 2009 8:22 am

Post by i2Paq » Sun Jan 24, 2010 4:49 pm

Have a look: Here.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by dbstr » Sun Jan 24, 2010 5:21 pm

i2Paq wrote:Have a look: Here.
Sorry but how is that thread relevant?

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by dbstr » Sun Jan 24, 2010 6:04 pm

This will only work (and show up) if you got ajax cart enabled.

Edit: catalog/controller/module/cart.php

Find this (at the bottom of the file)

Code: Select all

}
?>
Right above it, insert:

Code: Select all

    public function clear() {
        $this->language->load('module/cart'); 
        
        if ($this->request->server['REQUEST_METHOD'] == 'POST') {
            if (isset($this->request->post['clearcart'])) { 
                $this->cart->clear();
                
                $output = '<div style="text-align: center;">' . $this->language->get('text_empty')  . '</div>';
        
                $this->response->setOutput($output, $this->config->get('config_compression'));
            }
        }
    } 
Edit: catalog/view/theme/yourtemplate/template/module/cart.tpl
Find

Code: Select all

<div class="bottom">&nbsp;</div> 
Right above it, insert:

Code: Select all

  <?php if ($ajax) { ?>   
  <div style="text-align: right; border-left: 1px solid #DDDDDD; border-right: 1px solid #DDDDDD;">
    <form action="<?php echo $this->url->http('checkout/cart'); ?>" method="post" enctype="multipart/form-data" id="clearcart"> 
        <input type="hidden" name="clearcart" value="1" />
        <a onclick="$('#clearcart').submit();" id="clearcart_button" class="button"><span><?php echo $this->language->get('text_clear'); ?></span></a>
    </form>
  </div>
  <?php } ?>
In the same file, find this (near the bottom of the file)

Code: Select all

});     
//--></script>
Right above it, insert:

Code: Select all

    $('#clearcart_button').replaceWith('<a onclick="" id="clearcart_button" class="button">' + $('#clearcart_button').html() + '</a>'); 
    
    $('#clearcart_button').click(function () {
        $.ajax({
            type: 'post',
            url: 'index.php?route=module/cart/clear',
            dataType: 'html',
            data: $('#clearcart :input'),
            success: function (html) {
                $('#module_cart .middle').html(html);
            },
        });            
    });
Edit: catalog/language/english/module/cart.php
Find

Code: Select all

$_['text_empty']    = '0 items';
Below it, insert:

Code: Select all

$_['text_clear']    = 'Clear';

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by KGal » Sun Jan 24, 2010 6:20 pm

Hi! dbstr

That is excellent! thanks very much for sharing, is that for 1.4 please?

New member

Posts

Joined
Sun Jan 03, 2010 1:28 pm
Location - Australia

Post by dbstr » Sun Jan 24, 2010 6:35 pm

Yeah, it works with 1.4.0 :)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by KGal » Sun Jan 24, 2010 7:06 pm

Ok! great thanks

New member

Posts

Joined
Sun Jan 03, 2010 1:28 pm
Location - Australia

Post by goldndelicious » Mon Jan 25, 2010 6:22 am

Thats fantastic thank you.

Just one question. How do i know if ajax is enabled? i don't really know much about ajax

personalised car signs
personalised bedroom door signs
personalised gifts for kids


New member

Posts

Joined
Sun Oct 04, 2009 8:22 am

Post by nzjollyroger » Tue Jan 26, 2010 2:15 pm

can this work with 1.3.2?

New member

Posts

Joined
Mon Nov 16, 2009 5:26 am

Post by Miguelito » Fri Feb 05, 2010 6:07 am

How could this mod be updated so it wouldn't show the 'Clear' button if there's no items in the cart?

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by dbstr » Fri Feb 05, 2010 6:32 am

What I posted was just a veeeeeery quick and easy way of doing it, not a real mod as such... But I'll see about making it work properly, I'm probably gonna use it myself, someday... ;-)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by dbstr » Fri Feb 05, 2010 7:18 pm

Alright, new version.. Undo all the changes from the previous post, and try this:

Edit: catalog/view/theme/yourtemplate/template/module/cart.tpl
Find (line ~19):

Code: Select all

<div style="text-align: right;"><?php echo $text_subtotal; ?>&nbsp;<?php echo $subtotal; ?></div> 
Below, insert:

Code: Select all

<a onclick="clearCart();" class="button"><span><?php echo $this->language->get('text_clear'); ?></span></a>
--------------------------------------------------------------------------------------------------------------------------------
Find (at the bottom of the file, before <?php } ?> ):

Code: Select all

});     
//--></script>
Below, insert:

Code: Select all

<script type="text/javascript"><!--
function clearCart() {
    $.ajax({
        type: 'post',
        url: 'index.php?route=module/cart/clear',
        dataType: 'html',
        data: '&clearcart=true',
        success: function (html) {
            $('#module_cart .middle').html(html);
        },
    });            
}
//--></script>
--------------------------------------------------------------------------------------------------------------------------------
Edit: catalog/controller/module/cart.php
Find (line ~88):

Code: Select all

$output .= '<div style="text-align: right;">' . $this->language->get('text_subtotal') . '&nbsp;' .  $this->currency->format($this->cart->getTotal()) . '</div>'; 
Below, insert:

Code: Select all

$output .= '<a onclick="clearCart();" class="button"><span>' . $this->language->get('text_clear') . '</span></a>';
--------------------------------------------------------------------------------------------------------------------------------
Find (at the bottom of the file):

Code: Select all

}
?>
Above, insert:

Code: Select all

    public function clear() {
        $this->language->load('module/cart'); 
        
        if ($this->request->server['REQUEST_METHOD'] == 'POST') {
            if (isset($this->request->post['clearcart'])) { 
                $this->cart->clear();
                
                $output = '<div style="text-align: center;">' . $this->language->get('text_empty')  . '</div>';
        
                $this->response->setOutput($output, $this->config->get('config_compression'));
            }
        }
    } 
--------------------------------------------------------------------------------------------------------------------------------
Edit: catalog/language/english/module/cart.php
Find

Code: Select all

$_['text_empty']    = '0 items';
Below it, insert:

Code: Select all

$_['text_clear']    = 'Clear';

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by Miguelito » Sat Feb 06, 2010 5:40 am

Tested in 1.4.0 and it's working great! Thank you :)

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."


Active Member

Posts

Joined
Sun Jan 10, 2010 10:11 pm

Post by DannyMacD » Sun Feb 07, 2010 12:10 am

i have done the above but got this error on shop:

Parse error: syntax error, unexpected T_PUBLIC in /home/disifin/public_html/shop/catalog/controller/module/cart.php on line 134

help please :)

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by dbstr » Sun Feb 07, 2010 1:12 am

could your paste your cart.php?

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by DannyMacD » Sun Feb 07, 2010 1:36 am

never mind me being special...

works a treat!!

thank you!

Active Member

Posts

Joined
Fri Jun 26, 2009 6:39 am

Post by The Alchemist » Sun Feb 07, 2010 4:37 am

Nice Mod

User avatar
Active Member

Posts

Joined
Sun Nov 22, 2009 11:04 am

Post by RJonesUSC » Thu Mar 17, 2011 4:59 am

Anyone have this working on the latest release? I can't seem to get it working on 1.4.9.3.

New member

Posts

Joined
Tue Feb 15, 2011 4:03 am

Post by alexgg » Thu Oct 04, 2012 2:53 am

Hi dbstr and others,

Thanks for the nice adjustment.
What I was wondering, would it be possible with only the adjustment in cart.php as described by dbstr above, to just have the clearcart done by adding a parameter to the URL? So e.g. by requesting this:

/cart/index.php?route=checkout/cart&clearcart

??

This would be really really cool, cause I couldn't find another way of Opencart doing this.
Thanks for anyone having a suggestion.
Alex

P.S. I tried using the query above, but it didn't work...maybe I have to append it in someway?

Newbie

Posts

Joined
Tue Nov 01, 2011 7:25 pm

Post by MinoS » Tue Nov 11, 2014 7:05 am

You may be interested in my Clear Cart Button extension http://www.opencart.com/index.php?route ... n_id=16587

Also I provide free support :)

Newbie

Posts

Joined
Tue Mar 25, 2014 11:28 pm
Who is online

Users browsing this forum: No registered users and 12 guests