dev-master
9999999-devSimple shopping cart system
MIT
The Requires
- php >=5.4.0
The Development Requires
cart shopping
Wallogit.com
2017 © Pedro Peláez
Simple shopping cart system
Simple shopping cart system., (*2)
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);
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);
To this use the method \Gabrieljmj\Cart\Cart::clear., (*5)
$cart->clear();
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);
The method \Gabrieljmj\Cart\Cart::count() will return how many items has in the cart., (*7)
$cart->count();
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);
And this method (\Gabrieljmj\Cart\Cart::countUniqueItems()) counts how many types of products has in the cart., (*9)
$cart->countUniqueItems();
The method \Gabrieljmj\Cart\Cart::getTotalPrice() returns how much costs the cart., (*10)
$cart->getTotalPrice();
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();
}
The instance of the cart usually is save on a session or a cookie., (*12)
$_SESSION['cart'] = $cart;
//or
setcookie('cart', $cart);
Simple shopping cart system
MIT
cart shopping