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
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.
Edit: catalog/controller/module/cart.php
Find this (at the bottom of the file)
Code: Select all
}
?>
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'));
}
}
}
Find
Code: Select all
<div class="bottom"> </div>
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 } ?>
Code: Select all
});
//--></script>
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);
},
});
});
Find
Code: Select all
$_['text_empty'] = '0 items';
Code: Select all
$_['text_clear'] = 'Clear';
Request Reviews v1.0 released.
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
The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."
Request Reviews v1.0 released.
Edit: catalog/view/theme/yourtemplate/template/module/cart.tpl
Find (line ~19):
Code: Select all
<div style="text-align: right;"><?php echo $text_subtotal; ?> <?php echo $subtotal; ?></div>
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>
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') . ' ' . $this->currency->format($this->cart->getTotal()) . '</div>';
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
}
?>
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';
Code: Select all
$_['text_clear'] = 'Clear';
Request Reviews v1.0 released.

The Finnish OpenCart Forum
"Real programmers don't document. If it was hard to write, it should be hard to understand."
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?
Also I provide free support

Users browsing this forum: No registered users and 4 guests