I am currently trying to empty the whole cart in mangento 1.9 while clicking an item. The code is in the list.phtml from my template.
<form action="<?php echo $this->getUrl('checkout/cart/updatePost') ?>" method="POST" name="emptyTheCart">
<?php echo $this->getBlockHtml('formkey'); ?>
<button type="submit" name="update_cart_action" value="empty_cart" style="display:none" title="<?php echo $this->__('Empty Cart'); ?>" id="empty_cart_button"></button>
</form>
$('.item').click(function() {
var dataExecURL = "<?php echo $this->getUrl('checkout/cart/updatePost') ?>";
var datafiles=$("#emptyTheCart").serialize();
$.ajax({
type : 'POST',
data : datafiles,
url : dataExecURL
});
});
when i click on an item, it should empty my cart. Can someone please help? I do not have any clues why this is not working at all.
Add id="#emptyTheCart"
to the form, since you are using $("#emptyTheCart").serialize()
but the form doesn't seem to have any id?
Other than that, your code looks correct.
I have managed to make several modifications on the request, and now I have succeded.
$('.item').click(function() {
$(this).find('input:radio')[0].checked = true;
var formurl = $(this).find('input:radio').val();
var datafile=$("#product_addtocart_form").serialize();
var dataExecURL = "<?php echo $this->getUrl('checkout/cart/updatePost') ?>";
var datafiles=$("#emptyTheCart").serialize();
datafiles = datafiles + "&update_cart_action=empty_cart";
$.ajax({
type : 'POST',
data : datafiles,
url : dataExecURL,
success: function()
{
$.ajax({
type : 'POST',
data : datafile,
url : formurl
});
}
});
// console.log(datafile);
});
also I have added the form mentioned earlier at the bottom of the document.
Thank you for your help :)