Jump to content

Ajax problem when adding product to cart


pipedragon72

Recommended Posts

When I add a new product to the cart it doesn't automatically show up in the cart and I have to refresh the page for it to work so I'm guessing something's gone wrong with the ajax-cart.js file?

In my product-list.tpl I've changed the code because I wanted to add a quantity box to each item. I found this post on the forum and have added the necessary code but something isn't working ...
http://www.prestashop.com/forums/viewthread/28136/

The amended code I have in my ajax-cart.js file is:

//override every button in the page in relation to the cart
   overrideButtonsInThePage : function(){
       //for every 'add' buttons...
       $('.ajax_add_to_cart_button').unbind('click').click(function(){
           var idProduct =  $(this).attr('rel').replace('ajax_id_product_', '');
           ajaxCart.add(idProduct, null, false, this, $('#quantity_wanted_'+idProduct).val());
           return false;
       });
       //for product page 'add' button...
       $('body#product p#add_to_cart input').unbind('click').click(function(){
           ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null);
           return false;
       });



The amended code in my product-list.tpl is:

{if ($product.allow_oosp OR $product.quantity > 0) && $product.customizable != 2}
{l s='Quantity :'}<input type="text" name="ajax_qty_to_add_to_cart[{$product.id_product|intval}]" id="quantity_wanted_{$product.id_product|intval}" class="text" value="{if isset($quantityBackup)}{$quantityBackup|intval}{else}1{/if}" size="2" maxlength="3" /><a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$base_dir}cart.php?add&id;_product={$product.id_product|intval}&token;={$static_token}">{l s='Add to cart'}{else} 
{l s='Add to cart'}{/if}



Can anyone see why it's not working???

Link to comment
Share on other sites

It seems there is a common problem.

replace text at line 29 in modules/blockcart/blockcart.tpl

    <!-- block summary -->

       {*if $cart_qties > 0}{$cart_qties}{/if*}
{$cart_qties}
{l s='products' mod='blockcart'}
{l s='product' mod='blockcart'}
       {*if $cart_qties > 0}{if $priceDisplay == 1}{convertPrice price=$cart->getOrderTotal(false)}{else}{convertPrice price=$cart->getOrderTotal(true)}{/if}{/if*}
{if $priceDisplay == 1}{convertPrice price=$cart->getOrderTotal(false)}{else}{convertPrice price=$cart->getOrderTotal(true)}{/if}
       {if $cart_qties == 0}{if $cart_qties == 0}{l s='(empty)' mod='blockcart'}{/if}{/if}

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...