Post by chokoret » Wed Jul 20, 2011 7:21 am

I am trying to remove the mini cart on the header,
and want to put item count number next to "shopping cart" link in the header (under the search box)

so it'd be like



shopping cart (0) | wishlist (0)

I opened controller/common/header.php and modified
['text_cart'] part as

sprintf($this->language->get('text_cart'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0));


This does work for counting items in the cart, but it doesn't let the header automatically update the count when I click the add to cart button. I need to refresh the page to see the updated number.

I want it to be automatically updated like wishlist count..

Can I get help with it please? ???

User avatar
New member

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by grgr » Thu Jul 21, 2011 2:47 am

I think you need to add id="cart_total" to the link.

-
Image Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by chokoret » Thu Jul 21, 2011 4:14 am

@grgr i tried it but it automatically changes whole text to like "2 items - $1405.00" ...hmmmmmm....
seeems like it needs to be worked with common.js too..

User avatar
New member

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by hbuchel » Tue Aug 02, 2011 11:16 pm

I had the same issue, after changing the text_items in english/common/header.php, it would still default back to displaying the old text and the price amount. I discovered that also changing text_items in english/checkout/cart.php to the same solved the problem. I'm not super sure why it uses different language files for that.

New member

Posts

Joined
Mon Aug 30, 2010 9:41 pm

Post by wend » Thu Aug 04, 2011 2:07 am

header.tpl
<a id="mini_cart" href="<?php echo $cart; ?>"><?php echo $text_cart; ?></a>
<!--Add id "mini_cart" to "Shopping Cart", So we can easily change the content by jQuery script -->

Code: Select all

  <div class="links"><a href="<?php echo $home; ?>"><?php echo $text_home; ?></a><a href="<?php echo $wishlist; ?>" id="wishlist_total"><?php echo $text_wishlist; ?></a><a href="<?php echo $account; ?>"><?php echo $text_account; ?></a>
<a id="mini_cart" href="<?php echo $cart; ?>"><?php echo $text_cart; ?></a>
<!--Add id "mini_cart" to "Shopping Cart", So we can easily change the content by jQuery script -->
<a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a></div>
Modify common.js
addCart function:

Code: Select all

function addToCart(product_id) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'product_id=' + product_id,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information, .error').remove();
			
			if (json['redirect']) {
				location = json['redirect'];
			}
			
			if (json['error']) {
				if (json['error']['warning']) {
					$('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				}
			}	 
						
			if (json['success']) {
				$('#notification').html('<div class="attention" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
				
				$('.attention').fadeIn('slow');
				
				$('#cart_total').html(json['total']);
[b]//ADD CODE DEGINNING-----------------------------------
				//Show goods Number after "Shopping Cart" nav, like this  Shopping Cart (num)
				var itemNumLength = json['total'].indexOf('item(s)')-1; 
//Get the beginning of string "item(s)", then get the length of goods num.			
				var itemNum = json['total'].substr( 0 , itemNumLength );	
//get the goods num in the cart
				//var miniCartContent = $('#mini_cart').html();
				$('#mini_cart').html('Shopping Cart ('+itemNum+')');
//END-------------------------------------- Only support one language.[/b]				$('html, body').animate({ scrollTop: 0 }, 'slow'); 
			}	
		}
	});
}
removeCart function:

Code: Select all

function removeCart(key) {
	$.ajax({
		url: 'index.php?route=checkout/cart/update',
		type: 'post',
		data: 'remove=' + key,
		dataType: 'json',
		success: function(json) {
			$('.success, .warning, .attention, .information').remove();
			
			if (json['output']) {
				$('#cart_total').html(json['total']);
[b]//ADD CODE DEGINNING-----------------------------------
				//Show goods Number after "Shopping Cart" nav, like this  Shopping Cart (num)
				var itemNumLength = json['total'].indexOf('item(s)')-1; 
//Get the beginning of string "item(s)", then get the length of goods num.			
				var itemNum = json['total'].substr( 0 , itemNumLength );	
//get the goods num in the cart
				//var miniCartContent = $('#mini_cart').html();
				$('#mini_cart').html('Shopping Cart ('+itemNum+')');
//END-------------------------------------- Only support one language.[/b]				$('#cart .content').html(json['output']);
			}			
		}
	});
}
Now we can see Shopping Cart(nnn) under the search area. And any time we update cart, the num changes.
But when there is no change for cart, for example: first enter the home page, or reenter the page, it will display "shopping Cart" without num of items.

I will keep working on it.

Write less, Do more. Learning jQuery, Javascript, PHP, CSS


User avatar
Newbie

Posts

Joined
Sat Jul 30, 2011 8:56 am
Location - Shenzhen-China

Post by wend » Thu Aug 04, 2011 2:36 am

Modify "catalog\controller\common\header.php"

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

Modify "catalog\language\english\common\header.php"

//$_['text_cart'] = 'Shopping Cart';
$_['text_cart'] = 'Shopping Cart (%s)';


:laugh: DONE!!!

Write less, Do more. Learning jQuery, Javascript, PHP, CSS


User avatar
Newbie

Posts

Joined
Sat Jul 30, 2011 8:56 am
Location - Shenzhen-China

Post by wend » Thu Aug 04, 2011 2:38 am

After these changes, whenever refresh the page, it will always display right num.

Enjoy it. :crazy:

Write less, Do more. Learning jQuery, Javascript, PHP, CSS


User avatar
Newbie

Posts

Joined
Sat Jul 30, 2011 8:56 am
Location - Shenzhen-China

Post by chokoret » Thu Aug 04, 2011 2:58 am

Wonderful! i havn't try your trick yet, but sure it would do good! i couldn't even think of touching a letter from js file cuz it's so comprehensive for me..thanks!!
i'm opening up files now ;D

User avatar
New member

Posts

Joined
Thu Jun 09, 2011 1:26 am
Location - Los Angeles, CA

Post by wend » Thu Aug 04, 2011 3:09 am

It is just jQuery, easier than javascript. In fact it is javascript too. But it is easy to learn, and write less do a lot for you.
jQuery is poision, and I want to do almost everything with jQuery. :laugh:

Write less, Do more. Learning jQuery, Javascript, PHP, CSS


User avatar
Newbie

Posts

Joined
Sat Jul 30, 2011 8:56 am
Location - Shenzhen-China

Post by wbunny » Fri Dec 21, 2012 12:25 am

I tried to do this in 1.5.2.1, but it doesn't work. Does anyone have a solution for this? Thanks for your help!

User avatar
Newbie

Posts

Joined
Wed May 11, 2011 9:52 pm

Post by Daz1847 » Tue May 28, 2013 9:00 pm

Any idea on how to get this to work on OC v1.5.3.1

Really need this.

Thanks

Unlimited Everything Hosting + Anytime Money Back Guarantee
Only£1.95pm - Limited Time Offer
- http://shortlink.info/?cda56b00


User avatar
Newbie

Posts

Joined
Fri Apr 01, 2011 10:33 pm
Who is online

Users browsing this forum: Amazon [Bot] and 94 guests