2017 © Pedro Peláez
 

library cart

Simple shopping cart system

image

gabrieljmj/cart

Simple shopping cart system

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Gabrieljmj\Cart

Total Downloads Latest Unstable Version License Build Status Scrutinizer Code Quality, (*1)

Simple shopping cart system., (*2)

Usage

Adding product to cart

Use the method \Gabrieljmj\Cart\Cart::add(ProductInterface $product) to add a product. If previously the same product was added, will be add one more to cart., (*3)

use Gabrieljmj\Cart\Product\Product;
use Gabrieljmj\Cart\Cart;

$product = new Product(1, 'TV', 499.90, ['tv', 'led']);
$cart = new Cart();
$cart->add($product);

Removing product of a cart

Using \Gabrieljmj\Cart\Cart::remove($product[, $amount = 0]) you can remove products of a cart. If $amount be 0, all products of that products will be removed. The argument $product can be an instance of \Gabrieljmj\Cart\Product\ProductInterface or product id., (*4)

$cart->remove(1);

Clearing the cart

To this use the method \Gabrieljmj\Cart\Cart::clear., (*5)

$cart->clear();

Verifying if the cart has a product

The $product argument can be the product id or an instance of \Gabrieljmj\Cart\Product\ProductInterface. The return will be boolean., (*6)

$cart->has($product);

Counting how many products has in the cart

The method \Gabrieljmj\Cart\Cart::count() will return how many items has in the cart., (*7)

$cart->count();

Counting how many products of a type has in the cart

Use the method \Gabrieljmj\Cart\Cart::getTotalOfAProduct($product) and like others, $product can be an instance of \Gabrieljmj\Cart\Product\ProductInterface or product id., (*8)

$cart->getTotalOfAProduct($product);

Counting how many types of products has in the cart

And this method (\Gabrieljmj\Cart\Cart::countUniqueItems()) counts how many types of products has in the cart., (*9)

$cart->countUniqueItems();

Calculating total price of the cart

The method \Gabrieljmj\Cart\Cart::getTotalPrice() returns how much costs the cart., (*10)

$cart->getTotalPrice();

Iterating with all products

Each product will return an instance of \Gabrieljmj\Cart\Product\ProductInterface:, (*11)

$iterator = $cart->getIterator();

while ($iterator->valid()) {
    $curr = $iterator->current();
    echo '<li><b>Product:</b>' . $curr->getProduct()->getName() . ' / <b>Total:</b> ' . $cart->getTotalOfAProduct($curr) . '</li>';
    $iterator->next();
}

Storaging

The instance of the cart usually is save on a session or a cookie., (*12)

$_SESSION['cart'] = $cart;
//or
setcookie('cart', $cart);

The Versions

01/01 2015

dev-master

9999999-dev

Simple shopping cart system

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

cart shopping