I am using OC 2.3.0.2 with Journal 2.9.2 i want to show the total number of product in header cart and it to be update when some one add or remove the product from cart.
My header.php is look like this
Code: Select all
$data['text_shopping_cart'] = $this->language->get('text_shopping_cart');
Code: Select all
<?php
// Text
$_['text_items'] = '%s item(s) - %s';
$_['text_empty'] = 'Your shopping cart is empty!';
$_['text_cart'] = 'View Cart';
$_['text_checkout'] = 'Checkout';
$_['text_recurring'] = 'Payment Profile';
Code: Select all
function getURLVar(key){var value=[];var query=String(document.location).split('?');if(query[1]){var part=query[1].split('&');for(i=0;i<part.length;i++){var data=part[i].split('=');if(data[0]&&data[1]){value[data[0]]=data[1];}}if(value[key]){return value[key];}else{return'';}}}$(document).ready(function(){$('.text-danger').each(function(){var element=$(this).parent().parent();if(element.hasClass('form-group')){element.addClass('has-error');}});$('#form-currency .currency-select').on('click',function(e){e.preventDefault();$('#form-currency input[name=\'code\']').val($(this).attr('name'));$('#form-currency').submit();});$('#form-language .language-select').on('click',function(e){e.preventDefault();$('#form-language input[name=\'code\']').val($(this).attr('name'));$('#form-language').submit();});$('#search input[name=\'search\']').parent().find('button').on('click',function(){var url=$('base').attr('href')+'index.php?route=product/search';var value=$('header #search input[name=\'search\']').val();if(value){url+='&search='+encodeURIComponent(value);}location=url;});$('#search input[name=\'search\']').on('keydown',function(e){if(e.keyCode==13){$('header #search input[name=\'search\']').parent().find('button').trigger('click');}});$('#menu .dropdown-menu').each(function(){var menu=$('#menu').offset();var dropdown=$(this).parent().offset();var i=(dropdown.left+$(this).outerWidth())-(menu.left+$('#menu').outerWidth());if(i>0){$(this).css('margin-left','-'+(i+10)+'px');}});$('#list-view').click(function(){$('#content .product-grid > .clearfix').remove();$('#content .row > .product-grid').attr('class','product-layout product-list col-xs-12');$('#grid-view').removeClass('active');$('#list-view').addClass('active');localStorage.setItem('display','list');});$('#grid-view').click(function(){var cols=$('#column-right, #column-left').length;if(cols==2){$('#content .product-list').attr('class','product-layout product-grid col-lg-6 col-md-6 col-sm-12 col-xs-12');}else if(cols==1){$('#content .product-list').attr('class','product-layout product-grid col-lg-4 col-md-4 col-sm-6 col-xs-12');}else{$('#content .product-list').attr('class','product-layout product-grid col-lg-3 col-md-3 col-sm-6 col-xs-12');}$('#list-view').removeClass('active');$('#grid-view').addClass('active');localStorage.setItem('display','grid');});if(localStorage.getItem('display')=='list'){$('#list-view').trigger('click');$('#list-view').addClass('active');}else{$('#grid-view').trigger('click');$('#grid-view').addClass('active');}$(document).on('keydown','#collapse-checkout-option input[name=\'email\'], #collapse-checkout-option input[name=\'password\']',function(e){if(e.keyCode==13){$('#collapse-checkout-option #button-login').trigger('click');}});$('[data-toggle=\'tooltip\']').tooltip({container:'body'});$(document).ajaxStop(function(){$('[data-toggle=\'tooltip\']').tooltip({container:'body'});});});var cart={'add':function(product_id,quantity){$.ajax({url:'index.php?route=checkout/cart/add',type:'post',data:'product_id='+product_id+'&quantity='+(typeof(quantity)!='undefined'?quantity:1),dataType:'json',beforeSend:function(){$('#cart > button').button('loading');},complete:function(){$('#cart > button').button('reset');},success:function(json){$('.alert, .text-danger').remove();if(json['redirect']){location=json['redirect'];}if(json['success']){$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> '+json['success']+' <button type="button" class="close" data-dismiss="alert">×</button></div>');setTimeout(function(){$('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> '+json['total']+'</span>');},100);$('html, body').animate({scrollTop:0},'slow');$('#cart > ul').load('index.php?route=common/cart/info ul li');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'update':function(key,quantity){$.ajax({url:'index.php?route=checkout/cart/edit',type:'post',data:'key='+key+'&quantity='+(typeof(quantity)!='undefined'?quantity:1),dataType:'json',beforeSend:function(){$('#cart > button').button('loading');},complete:function(){$('#cart > button').button('reset');},success:function(json){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');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});},'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){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');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});}}
var voucher={'add':function(){},'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){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');}},error:function(xhr,ajaxOptions,thrownError){alert(thrownError+"\r\n"+xhr.statusText+"\r\n"+xhr.responseText);}});}}