Benefit-PHP-Shopping-Cart-Class
Benefit PHP Shopping Cart Class (Simple Lightweight)
Table of Contents
Initialization
Get All
Get Item
Get Item Child
Get Total Sum
Get Item Sum
Total Item Count
Check Item
Check Item Child
Check Item Child Value
clear
Remove
Remove Child
Remove Child Value
Insert
Field
Update
Increment
Decrement
Put
Initialization
First you import the benefit.php file in your project
include('benefit.php');
Defining a new class
You can use the following code as an example
/* BCC = Benefit Cart Class */
$bcc = new benefit;
Get All
getAll() command pulls all products added to cart
print_r($bcc->getAll());
/* **OR** */
foreach($bcc->getAll() as $key => $value){
/*
* $key = ProductID, hash, crc32
* $value = array in quantity, amount, cf (custom fields -size, color and type or gender (male, female, child))
* Usage: $value["quantity"], $value["price"], $value["color"] (array)
*/
}
Get Item
Bring the specified product from the basket
$bcc->fetch($item);
Get Item Child
Fetch the sub-features of the specified product from the basket
$bcc->fChild($item, $key)
Get Total Sum
Returns the total basket amount
/*
* Field (Ex): price
*/
$bcc->tPrice($field);
Get Item Sum
Returns the amount of the child product in the cart:
/*
* Ex.: $item => 7ca36866, price
*/
$bcc->tiPrice($item, $field)
Total Item Count
Returns the amount of products in the basket
$bcc->tItems();
Check Item
Checks if the product in the basket is available:
$bcc->check($item);
Check Item Child
Checks if the product in the basket has a child key
/*
* 7ca36866 in color, size or type
*/
$bcc->cChild($item, $key);
Check Item Child Value
Checks whether there is a feature or variation in the child element of the product in the basket
$bcc->cChildValue($item, $key, $value);
Clear
Clear cart
$bcc->clear();
Remove
Removes the specified product from the cart
$bcc->remove($item);
Remove Child
Removes the child element of the specified product
$bcc->rChild($item, $key);
Remove Child Value
Removes the value of the child element of the specified product
$bcc->rChildValue($item, $key, $value);
Insert
Adds the product to the basket
/*
* The default quantity is 1
* Specify variation with field before using insert function
*/
$bcc->insert($item, $quantity);
Field
Variation for the product to be added can be identified
/*
* $cf is array()
* Ex:
* $data = ["color" = ["red", "green", "blue"], "size" = ["s", "m", "l", "xl"]]
*/
$bcc->field($item, $cf);
Update
Updates the key value specified in the product
$bcc->update($item, $key, $value);
Increment
Increases the amount of the specified key
$bcc->inc($item);
Decrement
Decreases the amount of the specified key
$bcc->dec($item);
Put
Records the finished operations
/*
* You usually don't need to use this command
*/
$bcc->put();