Update Cart Total After Adding A Product To Cart

Hello,

I created a custom theme for my CS-Cart store but now when adding a product to cart the cart total price and number of product that appears in the header does not update unless the page is refreshed. I would like to have the cart information refreshed automatically when a user adds a new product to their cart.

Here is my cart_content.tpl code:

{assign var="dropdown_id" value=$block.snapping_id}
{assign var="r_url" value=$config.current_url|escape:url}
{hook name="checkout:cart_content"}
{__("total")}: {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{if $smarty.session.cart.amount}{$smarty.session.cart.amount}{else}0{/if}

{/hook}

and here is the link I use as my 'add to cart' button:


All help is much appreciated.

Try to replace

{__("total")}: {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{if $smarty.session.cart.amount}{$smarty.session.cart.amount}{else}0{/if}

with

{__("total")}: {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{if $smarty.session.cart.amount}{$smarty.session.cart.amount}{else}0{/if}

Thank you, eComLabs. It worked!

I would be interested to know the significance of the missing comment line you added?

Thank you, eComLabs. It worked!

I would be interested to know the significance of the missing comment line you added?

You are welcome! If the div which should be updated does not contain this comment, it will be ignored by the system. Comment and closed div tag should be placed on one line

It's because cs-cart renders the whole page on the server side and then JS in the browser breaks this into the desired "result_id's". It then replaces the HTML for those result_id's with the newly updated code. It's a strange way to do ajax requests and is unique (as far as I've seen) to cs-cart. For some reason, they don't feel they can trust their html parsing to find a closing tag for a result_id.

You are welcome! If the div which should be updated does not contain this comment, it will be ignored by the system. Comment and closed div tag should be placed on one line

It's because cs-cart renders the whole page on the server side and then JS in the browser breaks this into the desired "result_id's". It then replaces the HTML for those result_id's with the newly updated code. It's a strange way to do ajax requests and is unique (as far as I've seen) to cs-cart. For some reason, they don't feel they can trust their html parsing to find a closing tag for a result_id.

Very interesting! Thank you both.

Try to replace

{__("total")}: {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{if $smarty.session.cart.amount}{$smarty.session.cart.amount}{else}0{/if}

with

{__("total")}: {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{if $smarty.session.cart.amount}{$smarty.session.cart.amount}{else}0{/if}

We have the same issue the quantity function doesn work when customer change on the cart page

But i try your solution and it doesnt work

we have like this our : cart_content.tpl

{assign var="dropdown_id" value=$block.snapping_id}
{assign var="r_url" value=$config.current_url|escape:url}
{hook name="checkout:cart_content"}
{hook name="checkout:dropdown_title"}
{if $smarty.session.cart.amount}
{$smarty.session.cart.amount} {__("items")} {__("for")} {include file="common/price.tpl" value=$smarty.session.cart.display_subtotal}
{else}
{__("cart_is_empty")}
{/if}
{/hook}
{hook name="checkout:minicart"}
{if $smarty.session.cart.amount}
    {hook name="index:cart_status"}
    {assign var="_cart_products" value=$smarty.session.cart.products|array_reverse:true}
    {foreach from=$_cart_products key="key" item="product" name="cart_products"}
    {hook name="checkout:minicart_product"}
    {if !$product.extra.parent}
  • {hook name="checkout:minicart_product_info"}
    {if $block.properties.products_links_type == "thumb"}
    {include file="common/image.tpl" image_width="40" image_height="40" images=$product.main_pair no_ids=true}
    {/if}

    {$product.amount} x {include file="common/price.tpl" value=$product.display_price span_id="price_`$key`_`$dropdown_id`" class="none"}

    {if $block.properties.display_delete_icons == "Y"}
    {if (!$runtime.checkout || $force_items_deletion) && !$product.extra.exclude_from_calculate}
    {include file="buttons/button.tpl" but_href="checkout.delete.from_status?cart_id=`$key`&redirect_url=`$r_url`" but_meta="cm-ajax cm-ajax-full-render" but_target_id="cart_status*" but_role="delete" but_name="delete_cart_item"}
    {/if}
    {/if}
    {/hook}
    {/if}
    {/hook}
    {/foreach}
    {/hook}
    {else}
    {__("cart_is_empty")}
    {/if}
    {if $block.properties.display_bottom_buttons == "Y"}
    {if $settings.General.checkout_redirect != "Y"}
    {/if}
    {/if}
    {/hook}
    {/hook}

    Any help?

    Please clarify your issue in more details

    Recalculate button doesnt work, in the past we use a free addon which automatic recalculate, but now it doesnt work either. So we delete the addon and now recalculate manual not work.

    Recalculate button just submits the form. It does nothing with ajax

    Our recalculate button doesnt work.

    When we push it, does not do anything

    Suggest you contact the developer of the addon you deleted and have them ensure that the addon and any core file changes they may have made are completely removed.

    Our recalculate button doesnt work.

    When we push it, does not do anything

    Check the source code and make sure that the button is located inside the form tag