Samir Karmacharya Samir Karmacharya - 6 months ago 192
jQuery Question

How to refresh the page and remove delete product, when click on delete btton in dropdown cart on heder in opencart


I try to refresh the page along with removal of cart delete data when
click on delete button on drop down cart on header in opencart. i
found the location on cart.tpl but i could not found the location of
function when click on that button ie.


onclick="cart.remove('<?php echo $product['key']; ?>');



and i try to refresh the page using jquery


<script type="text/javascript">
jQuery(document).ready(function(){
$('.dropdown-menu .text-center .btn-xs').click(function(){
location.reload();
});

});
</script>



it refresh the page but dosent delete the cart prouct. any one knew
about this

Answer

Open the file catalog/view/javascript/common.js. Go to line 200.

Change this

'remove': function(key) {
        $.ajax({
            url: 'index.php?route=checkout/cart/remove',
            type: 'post',
            data: 'key=' + key,
            dataType: 'json',
            beforeSend: function() {
                $('#cart > button').button('loading');
            },
            complete: function() {
                $('#cart > button').button('reset');
            },          
            success: function(json) {
                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
                }, 100);

                if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
                    location = 'index.php?route=checkout/cart';
                } else {
                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                }
            }

TO THIS

'remove': function(key) {
        $.ajax({
            url: 'index.php?route=checkout/cart/remove',
            type: 'post',
            data: 'key=' + key,
            dataType: 'json',
            beforeSend: function() {
                $('#cart > button').button('loading');
            },
            complete: function() {
                $('#cart > button').button('reset');
            },          
            success: function(json) {
                // Need to set timeout otherwise it wont update the total
                setTimeout(function () {
                    $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
                }, 100);

                if (getURLVar('route') == 'checkout/cart' || getURLVar('route') == 'checkout/checkout') {
                    location = 'index.php?route=checkout/cart';
                } else {
                    $('#cart > ul').load('index.php?route=common/cart/info ul li');
                }
                location.reload();
            }
Comments