Sunday, January 27, 2013

how to remove ajax cart from opencart

I was working with opencart. And I was facing problem with removing ajax enabled shopping cart feature from opencart. Prior to 1.5, Opencart provides an option on the admin panel to turn off the ajax cart feature. But this option is no longer exists.
To remove this feature, we need to add some code on the common.js file. There is a function addToCart(). We have added a custom function RedirectToCart().
function RedirectToCart(){
   window.location='index.php?route=checkout/cart';
}

Hence, our addToCart() function becomes like this:
function addToCart(product_id, quantity) {
 quantity = typeof(quantity) != 'undefined' ? quantity : 1;

 $.ajax({
  url: 'index.php?route=checkout/cart/add',
  type: 'post',
  data: 'product_id=' + product_id + '&quantity=' + quantity,
  dataType: 'json',
  success: function(json) {
   $('.success, .warning, .attention, .information, .error').remove();
   
   if (json['redirect']) {
    location = json['redirect'];
   }
   
   if (json['success']) {
    $('#notification').html('');
    
    $('.success').fadeIn('slow');
    
    $('#cart-total').html(json['total']);
    
    $('html, body').animate({ scrollTop: 0 }, 'slow'); 
   }
                        RedirectToCart();
  }
 });
}


See the book OpenCart 1.4 Template Design Cookbook.
See the book Joomla Mobile Development Beginners Guide

No comments: