Wednesday, 9 September 2015

Update cart items count through ajax opencart


Update cart items count through ajax opencart

Kindly follow the below steps.

Go to catalog\view\theme\your_theme\template\common\header.tpl and put the below code where you want to display the items-count

<span class="cart-qty cart-total" id="item-count"><?php echo $this->cart->countProducts(); ?></span>

Now Go to catalog\view\javascript\common.js and find the addToCart function

Put below line

$('#item-count').html(json['item-count']); before this line $('#cart-total').html(json['total']);


Now Go to catalog\controller\checkout\cart.php and find the below code

$json['total'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));

After this code put this line

$json['item-count'] = $this->cart->countProducts();

Now Go to catalog\view\theme\your_theme\template\product\product.tpl and and find the below line

$('#cart-total').html(json['total']); and put below line just before it.

$('#item-count').html(json['item-count']);

Thats it enjoy chandresh rana coding... :)

1 comment:

Anonymous said...

Thanks for the auspicious writeup. It in fact was once a
enjoyment account it. Look advanced to more
introduced agreeable from you! By the way, how can we be in contact?


Feel free to visit my webpage :: ford fiesta classic