AJAX Cart Edit in PHP Shopping Cart

This Shopping cart tutorial is providing cart edit feature by using jQuery AJAX. In a previous tutorial, we have seen simple shopping cart. This edit feature allows changing the existing cart item quantity in session.

In this example, we are showing item quantity in a text box to allow edit. This cart edit function is called via jQuery AJAX on the blur event of the quantity text box.

We are sending an AJAX call with the appropriate product code and quantity to a PHP file. It changes the quantity in cart session and calculates new total as AJAX response.

jQuery AJAX Cart Edit Call

This script will send an AJAX request to PHP code to edit the quantity by sending the product code and new quantity. This AJAX function will be invoked on loosing focus from the quantity input box. Once the quantity is changed the new price will be calculated again and updated in UI on successful cart edit. The script is,