|
Grove-Cart Version 1.0 Documentation
Requirements:
Grove Cart requires PHP, MySQL,
ezSQL, and PHP session
support. Constructor:
Grove Cart is a PHP class that needs to
be initialized before it can be used. It's constructor takes in a
set of arguements and looks like this:
function cart(
$products_table, $product_id, $price_field, $name_field )
| $products_table: |
The table that contains the list of products, their IDs,
prices, and names. |
| $product_id: |
The field (column name) in the products table that contains
the unique identifier for each product, such as the product ID
or unique product name. |
| $price_field: |
The field (column name) in the products table that contains
the price information. |
| $name_field: |
The field (column name) in the products table that contains
the name and / or description of the product. |
Example Usage:
include_once( "lib/ez_sql.php" );
include_once( "lib/HG_cart.php" );
// A new cart for retail pointing to the retailPrice field
$retail_cart = new cart( "master_products", "record_number",
"retail_price", "name" );
Add to Cart:
A function that will take in the
product ID and quantity of the item you wish to put in the cart. If
that product ID is already in the cart, Grove Cart will update that
item's quantity.
$retail_cart->add( "448", 1 );
$retail_cart->add( "345", 2 );
Update Cart:
A function that will update the
quantity for the specified product_id. Note: if the quantity is less
than one, this function will not do anything (please us the
delete_from_cart function to delete an item).
$retail_cart->update_cart( "448", 5 );
$retail_cart->update_cart( "345", 1 );
Delete From Cart:
A function that will delete an item
from the cart.
$retail_cart->delete_from_cart( "448");
Get Cart Items:
A function that will return a
multi-dimensional array of the items in the cart along with their
price, names, and quantity.
$items = $retail_cart->get_items();
foreach ( $items as $item )
{
echo "<br>\n Product ID: " . $item["product_id"] . "<br>\n";
echo "<br>\n Price: " . $item["price"] . "<br>\n";
echo "<br>\n Name: " . $item["name"] . "<br>\n";
echo "<br>\n Quantity: " . $item["quantity"] . "<br>\n";
}
Get Number of Items:
A function that will return the number
of items in the cart. Note: this function does not make a database
call, and as such, should be the preferred method of quickly getting
the number of items.
echo "<br>\n Number of Items: ";
echo $retail_cart->get_num_items();
Get Cart Total:
A function that will return the total
price of all items and their quantity in the cart. Note: this
function does not make a database call, and as such, should be the
preferred method of quickly getting the total of the cart.
echo "<br>\n Cart Total: ";
echo $retail_cart->get_cart_total();
Delete Cart:
A function that delete an entire cart
and all of its contents from the database. Note: this is NOT a
desctructor as your cart instance will still exist, it will just be
empty.
$retail_cart->delete_cart();
|