gabrielcabola/simple-shopping-cart

Simple Shopping Cart in PHP

dev-master 2018-12-07 21:12 UTC

This package is auto-updated.

Last update: 2024-09-09 02:41:15 UTC


README

alt text

Simple-shopping-cart

A simple shopping cart class in PHP 5.4.x

How to use

Load Class

//composer autoload (ignore if do you already have)
require '../vendor/autoload.php';
//load the class
use SSCart\Cart;
//Initialize
$cart = new Cart([array $options]);

Options

Add

// Add a product
$cart->add([object $product]);

Change quantity

More (up)

// Increase Item Quantity
$cart->upQuantity(id,amount);

//or use only to increase one
$cart->upQuantity(id);

Less (down)

// Decrease Item Quantity
$cart->downQuantity(id,amount);

//or use only to decrease one
$cart->downQuantity(id);

Remove item

// Decrease Item Quantity
$cart->remove(id);

List all Itens

// List
$cart->items();

Total of products

// Get a integer number of distinct products in cart
$cart->productsTotal();

Total of itens

// Get a integer number  of itens total in cart
$cart->itemsTotal();

Total Amount of Cart

// Show total cost of cart
$cart->sumTotal()

Clear Cart

// Cleat entire Cart
$cart->clearCart

Helpers

Using helpers

//Price sub class
use SSCart/Price;

//Format price and decimals
Price::format($number);

//Return Class currency ($ default)
Price::currency();

Return a formated price.

Example

Run a simple app to demonstate how Cart works!

/example/index.php