PHP Classes

Simple Static Basket: Manage shopping baskets stored in sessions

Recommend this page to a friend!
  Info   Example   Demos   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 423 All time: 6,376 This week: 560Up
Version License PHP version Categories
simple-basket 1.0GNU General Publi...5.2PHP 5, E-Commerce
Description 

Author

This class can manage shopping baskets stored in sessions.

It can create and manage the items in a shopping basket using session variables to store the basket data. Currently it can:

- Add a list of items to the basket specifying the items' id, price, name and quantity
- Change items already in the basket
- Get the list of items in the basket
- Get the quantity of items in the basket
- Get the quantity of item types in the basket
- Get the total cost of the items in the basket
- Get the last modification date of the basket
- Remove items from the basket

Picture of Nemeth Zoltan
  Performance   Level  
Name: Nemeth Zoltan is available for providing paid consulting. Contact Nemeth Zoltan .
Classes: 9 packages by
Country: Hungary Hungary
Age: 46
All time rank: 157113 in Hungary Hungary
Week rank: 214 Up3 in Hungary Hungary Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

Example

<pre>
  <?php
 
/**
   * Initialize
   */
 
include_once 'Basket.class.php';

  function
summarylist() {
   
$items = Basket::getItemList();
   
var_export($items);
    print
"<br>Full price: " . Basket::getFullPrice();
    print
"<br>Item quantity: " . Basket::getItemCount();
    print
"<br>Item types: " . Basket::getItemtypeCount();
    print
"<br>Last modify: " . Basket::getLastModify(false). " (".Basket::getLastModify().")";
   
$sleep = mt_rand(1,3);
    print
"<br> >> Wait ".$sleep." seconds for testing.<br>";
   
//sleep($sleep);
 
}

 
Basket::emptyBasket();
 
/**
   * Empty basket
   */
 
print "Simple Static Basket with session storage<br>";
  print
"<br>Basket (empty) [emptyBasket, getItemList]<br>";
 
summarylist();
 
/**
   * Add simple item
   */
 
print "<br><br>Add a simple item [changeItem]<br>";
 
Basket::changeItem('sugar_01', 12.25, 'Sugar, 1kg', 0.75);
 
summarylist();
 
/**
   * Add multiple items
   */
 
print "<br><br>Add multiple items [addItemFromArray]<br>";
 
$add_items = array(
    array(
'id' => 'salt_01', 'quantity' => 4.57, 'name' => 'Salt, 1kg', 'price' => 0.65),
    array(
'id' => 'salt_02', 'quantity' => 3.10, 'name' => 'Salt, 2kg', 'price' => 1.15),
    array(
'id' => 'salt_03', 'quantity' => 2.90, 'name' => 'Salt, 5kg', 'price' => 2.55),
    array(
'id' => 'sugar_02', 'quantity' => 1.34, 'name' => 'Sugar, 2kg', 'price' => 1.40),
    array(
'id' => 'sugar_03', 'quantity' => 13.45, 'name' => 'Sugar, 5kg', 'price' => 3.59),
  );
 
Basket::addItemFromArray($add_items);
 
summarylist();
 
/**
   * Remove salt_03
   */
 
print "<br><br>Remove salt_03 [removeItem]<br>";
 
Basket::removeItem('salt_03');
 
summarylist();
 
/**
   * Change the quantity of salt_02
   */
 
print "<br><br>Change the quantity of salt_02 to 3.45 [changeItem]<br>";
 
Basket::changeItem('salt_02', 3.45, null, 0);
 
summarylist();
 
/**
   * Change the price of salt_02
   */
 
print "<br><br>Change the price of salt_02 to 1.23 [changeItem]<br>";
 
Basket::changeItem('salt_02', 0, null, 1.23);
 
summarylist();
 
/**
   * Change the name of salt_02
   */
 
print "<br><br>Change the name of salt_02 to Sugar, 1.5kg [changeItem]<br>";
 
Basket::changeItem('salt_02', 0, 'Sugar, 1.5kg', 0);
 
summarylist();
 
?>
</pre>


  Files folder image Files (2)  
File Role Description
Plain text file Basket.class.php Class Simple static basket
Accessible without login Plain text file test.php Example test file for the class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:423
This week:0
All time:6,376
This week:560Up