0

I want to add add to cart button without reloading the page.

For this I found this Excellence extension. But I have a problem when I add the product in cart, my minicart from top page is not updating. I found this in the code:

success: function(data){
 jQuery('#ajax_loader').hide();
 //alert(data.status + ": " + data.message);
 if(jQuery('.block-cart')){
 jQuery('.block-cart').replaceWith(data.sidebar);
 }
 if(jQuery('.header .links')){
 jQuery('.header .links').replaceWith(data.toplink);
 }
}

and my HTML output is look like this:

<div class="top-cart-contain">
 <div class="mini-cart">
 <div class="basket dropdown-toggle" data-toggle="dropdown" data-hover="dropdown">
 <a href="http://example.com/checkout/cart/">
 <div class="cart-box">
 <span class="title">
 <i class="glyphicon glyphicon-shopping-cart"></i>
 My Cart:
 <span>1 prekės</span>
 Price:
 <span class="price">13,74 €</span>
 <i class="glyphicon glyphicon-triangle-bottom"></i>
 </span>
 </div>
 </a>
 </div>
 </div>
</div>

Is there any way to make this extension to update my top cart?

asked Sep 15, 2016 at 14:34

1 Answer 1

1

The jQuery does not find your cart block because the class .block-cart is not the right one in your case. I suggest you replace:

if(jQuery('.block-cart')){
 jQuery('.block-cart').replaceWith(data.sidebar);
}

With:

if(jQuery('.mini-cart')){
 jQuery('.mini-cart').replaceWith(data.sidebar);
}
answered Sep 15, 2016 at 14:35
9
  • thank you so much, but if I change this in my top cart is blank now Commented Sep 15, 2016 at 14:37
  • @RobertD check what's the content of data.sidebar ? Commented Sep 15, 2016 at 14:38
  • I talk about minicart from top, that minicart, and in controller of this extension I have this: $toplink = $this->getLayout()->getBlock('top.links')->toHtml(); $sidebar_block = $this->getLayout()->getBlock('cart_sidebar'); Commented Sep 15, 2016 at 14:39
  • @RobertD yeah what do you get in the data response ? Commented Sep 15, 2016 at 14:41
  • what I need to do to see this data response? Commented Sep 15, 2016 at 14:43

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.