Post by opencart-templates » Fri Jun 17, 2011 9:18 pm

I have had a few emails already about the latest Opencart release without the add to cart animating the product. So here is how to manually add it back.

Assuming you are using the cart module, otherwise you will need to change #module_cart to #cart

DEMO: http://demo.opencart-templates.co.uk/de ... od_classic

- EDIT: /catalog/view/theme/default/template/product/product.tpl
- FIND:

Code: Select all

$('html, body').animate({ scrollTop: 0 }, 'slow'); 
- ADD ABOVE:

Code: Select all

animateProduct( $("#image") , $("#module_cart") );  
- Edit: /catalog/view/javascript/common.js
- ADD inside the $(document).read

Code: Select all

 /* AddToCart */
   $('.addToCart').click(function() {
	  var tis = $(this);
	  $.ajax({
		 url: 'index.php?route=checkout/cart/update',
		 type: 'post',
		 data: 'product_id=' + tis.attr("data-id"),
		 dataType: 'json',
		 content: this,
		 success: $.proxy(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']);
			   $('#module_cart .cart-module').html(json['output']);
			   
			   animateProduct(tis.parents().eq(2).find(".image img") , $("#module_cart"));
			   
			   $('html, body').animate({ scrollTop: 0 }, 'slow');
			}   
		 }, this)
	  });
	  
   });
- ADD to bottom:

Code: Select all

function animateProduct(image,cart){

   image.before('<img src="' + image.attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

   var cart_offset  = cart.offset();

   params = {
	  top : cart_offset.top + 'px',
	  left : cart_offset.left + 'px',
	  opacity : 0.0,
	  width : cart.width(), 
	  height : cart.height()
   };

   $('#temp').animate(params, 'slow', false, function () {
	  $('#temp').remove();
   });
}
I moved majority of the code to the common.js in the hope that this will be updated less than the product.tpl

- Seen as we are now using a function and not inline JS to animate the image, we can reuse this throughout the website. So I though why not show you how this could work with HTML5 data attribute and eventually this might be updated in the core.

- EDIT: /catalog/view/theme/default/template/product/category.tpl
- FIND:

Code: Select all

<div class="cart"><a onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button"><span><?php echo $button_cart; ?></span></a></div>
- REPLACE WITH:

Code: Select all

<div class="cart"><a data-id="<?php echo $product['product_id']; ?>" class="button addToCart"><span><?php echo $button_cart; ?></span></a></div>
Last edited by opencart-templates on Fri Sep 02, 2011 10:58 pm, edited 6 times in total.

Advanced Professional Email Template
Customers Pre-Sale. Inc abandoned cart email
Order Follow-Up Email. Inc request review
Email Validation with ZeroBounce


User avatar
Active Member

Posts

Joined
Mon May 16, 2011 7:24 pm
Location - UK

Post by rph » Fri Sep 02, 2011 10:58 pm

Cool. Will have to try this out.

-Ryan


rph
Expert Member

Posts

Joined
Fri Jan 08, 2010 5:05 am
Location - Lincoln, Nebraska

Post by anti91 » Sun Sep 04, 2011 10:30 am

Perfect..

New member

Posts

Joined
Tue Aug 30, 2011 8:27 am

Post by vickiowa » Tue Sep 27, 2011 7:50 am

I tried this but it didn't work for me.

I'm using OC 1.5.1.1 and Shoppica Theme 1.0.8 (www.shoppica dotnet)

Any ideas or advice would be welcome. Thanks much.
Vick

Newbie

Posts

Joined
Tue Sep 27, 2011 6:16 am

Post by crookedview » Wed Sep 28, 2011 11:24 am

Looks great - will try this out!

Newbie

Posts

Joined
Fri Sep 02, 2011 8:13 am

Post by trance » Mon Dec 26, 2011 12:22 am

You've got an error in the instructions you wrote

Code: Select all

function animateProduct(image,cart){

   image.before('<img src="' + image.attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;" />');

   var cart_offset  = cart.offset();

   params = {
     top : cart_offset.top + 'px',
     left : cart_offset.left + 'px',
     opacity : 0.0,
     width : cart.width(), 
     height : cart.height()
   };

   $('#temp').animate(params, 'slow', false, function () {
     $('#temp').remove();
   });
}

should be so

Code: Select all

function animateProduct(image,cart){
	var image_offset  = image.offset();
   $("body").append('<img src="' + image.attr('src') + '" id="temp" style="position: absolute; top:'+image_offset.top+'px; left:'+image_offset.left+'px" />');

   var cart_offset  = cart.offset();
   params = {
	  top : cart_offset.top + 'px',
	  left : cart_offset.left + 'px',
	  opacity : 0.0,
	  width : cart.width(),
	  height : cart.height()
   };
	
  $('#temp').animate(params, 'slow', false, function () {
	  $('#temp').remove();
   });
}


Newbie

Posts

Joined
Wed Sep 28, 2011 12:06 am

Post by opencart-templates » Mon Dec 26, 2011 4:44 am

Yes thanks for spotting this, I upgraded the code so it works from a category page a while ago now and forgot to update this post.

Advanced Professional Email Template
Customers Pre-Sale. Inc abandoned cart email
Order Follow-Up Email. Inc request review
Email Validation with ZeroBounce


User avatar
Active Member

Posts

Joined
Mon May 16, 2011 7:24 pm
Location - UK

Post by har10 » Fri Apr 27, 2012 8:57 am

hallo,
could it be possible instead of product image to animate

we could animate cart button
there i put up a icon that could be animated


thanks in advance

Newbie

Posts

Joined
Sat Feb 25, 2012 3:57 pm
Who is online

Users browsing this forum: No registered users and 7 guests