How to Auto-Update Cart After Changing Product Quantity in ECSHOP

1. Back up and modify the flow.dwt file in the template directory:

(1) Add a piece of JS between the <head> tags to replace the update button for form submission:
<script type="text/javascript">
function formSubmit()
{
document.getElementById("formCart").submit();
}
</script>
Copy code
(2) Between the <body> tags, find code like this:
<!– {if $goods.goods_id gt 0 && $goods.is_gift eq 0 && $goods.parent_id eq 0} 普通商品可修改数量 –>
<input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" value="{$goods.goods_number}" size="4" class="inputBg" style="text-align:center " onkeydown="showdiv(this)"/>
Copy code
Change it to trigger an event when the object loses focus: onblur="formSubmit()" , for example:
<!– {if $goods.goods_id gt 0 && $goods.is_gift eq 0 && $goods.parent_id eq 0} 普通商品可修改数量 –>
<input type="text" name="goods_number[{$goods.rec_id}]" id="goods_number_{$goods.rec_id}" value="{$goods.goods_number}" size="4" class="inputBg" style="text-align:center " onblur="formSubmit()"/>
Copy code
(3) Then find the following code:

<input name="submit" type="submit" class="bnt_blue_1" value="{$lang.update_cart}" />
Copy code
Deleting this code removes the “Update Cart” button. If you want to keep the button, you must change the name="submit" attribute to something else, otherwise you will get a “submit is not a function” error in Firebug. The reason is that if there is an element with name="submit" inside the <form>, it will conflict with the submit() method when using document.getElementById("formCart").submit() to submit the form.

2. Back up and modify the flow.php file in the root directory:
Find this code:
elseif ($_REQUEST['step'] == 'update_cart')
Copy code
Comment out the entire line: show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php');,
and add this line above it: ecs_header("Location: flow.php/n");
This enables automatic redirect back to the details page after updating the cart, like so:
elseif ($_REQUEST['step'] == 'update_cart')
{
/*—————————————————— */
//– 更新购物车
/*—————————————————— */

if (isset($_POST['goods_number']) && is_array($_POST['goods_number']))
{
flow_update_cart($_POST['goods_number']);
}
ecs_header("Location: flow.php/n");
// show_message($_LANG['update_cart_notice'], $_LANG['back_to_cart'], 'flow.php');
exit;
}
Copy code
And that’s it, you’re all done.

Leave a Comment

Your email address will not be published.