PHP Classes

Shopping Cart: Manipulate the item of a shopping cart using AJAX

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog (2)    
Ratings Unique User Downloads Download Rankings
StarStarStar 50%Total: 9,208 All time: 165 This week: 560Down
Version License PHP version Categories
session_cart 5The PHP License5.0E-Commerce, AJAX
Description 

Author

This class can be used to manipulate the items of a shopping cart using AJAX to avoid making the user leave the current page.

The class can generate HTML and Javascript to show the list of items in the shopping cart.

The list has form submit buttons to trigger the execution of AJAX requests that can add or remove items from the shopping cart.

The list of shopping cart items is stored in a session variable.

The actions of adding and removing items are also tracked by storing the action details in a MySQL database table.

Picture of Ashraf Gheith
  Performance   Level  
Name: Ashraf Gheith <contact>
Classes: 9 packages by
Country: Bosnia and Herzegovina Bosnia and Herzegovina
Age: 41
All time rank: 131 in Bosnia and Herzegovina Bosnia and Herzegovina
Week rank: 416 Down1 in Bosnia and Herzegovina Bosnia and Herzegovina Equal
Innovation award
Innovation award
Nominee: 1x

Recommendations

Recommendation for a PHP class to shopping cart installer
Install shopping cart Web site

Design shopping cart with PHP and MySQL
How to design PHP shopping cart

What is the best PHP shopping cart for take away class?
Shopping cart to process orders for a restaurant

Store and show shopping cart items
I have an existing website that I want to add a shopping cart.

Example

<?php
    session_start
();
    require_once(
"config.php");
    require_once(
"cart.php");
?>
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Example of AJAX Cart</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="description" content="" />
        <meta name="keywords" content="" />
        <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
        <script type="text/javascript" src="main.js"></script>
    </head>
    <body leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">
        <h1>Products list</h1>
        <?php
            $cart
= new cart();
           
$products = $cart->getProducts();
       
?>
<table cellpadding="5" cellspacing="0" border="0">
            <tr>
                <td align="left" width="200"><b>Product</b></td>
                <td align="left" width="300" colspan="2"><b>Price</b></td>
            </tr>
            <?php
               
foreach($products as $product){
           
?>
<tr>
                    <td align="left"><?php print $product->product; ?></td>
                    <td align="left">$<?php print $product->price; ?></td>
                    <td align="center"><span style="cursor:pointer;" class="addToCart" data-id="<?php print $product->id; ?>">add to cart</span></td>
                </tr>
            <?php
               
}
           
?>
</table>
        <br /><a href="show-cart.php" title="go to cart">Go to cart</a>
    </body>
</html>


Screenshots  
  • cart.jpg
  Files folder image Files  
File Role Description
Plain text file cart.php Class The Main Class
Plain text file cart.sql Data SQL file
Plain text file config.php Conf. Configuration file
Plain text file ajax.php Example AJAX file
Plain text file index.php Example Index file
Plain text file show-cart.php Example Show cart elements
Plain text file main.js Data JS script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:9,208
This week:0
All time:165
This week:560Down
User Ratings User Comments (1)
 All time
Utility:76%StarStarStarStar
Consistency:71%StarStarStarStar
Documentation:-
Examples:57%StarStarStar
Tests:-
Videos:-
Overall:50%StarStarStar
Rank:2564
 
Thank you, Good Job Good luck Ayoub Bekkey
10 years ago (Ayoub Bekkey)
52%StarStarStar