Shopping Cart Edit in php using AJAX

42

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.

HTML Cart Edit

The product list code is same as the example we have seen in last tutorial Responsive PHP Shopping Cart. So we can see cart edit page.

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,

Edit Cart Session and Total Price using PHP

This code shows the PHP logic to change cart session and the total price based on the newly changed cart item quantity.

 

Leave A Reply

Your email address will not be published.