2017 © Pedro Peláez
 

library shopping-cart

Shopping cart

image

ksdev/shopping-cart

Shopping cart

  • Sunday, August 23, 2015
  • by ksdev
  • Repository
  • 2 Watchers
  • 2 Stars
  • 89 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Shopping Cart

Latest Version on Packagist ![Software License][ico-license] Build Status ![Coverage Status][ico-scrutinizer] Quality Score, (*1)

Original source: http://www.peachpit.com/articles/article.aspx?p=1962481 by Larry Ullman. See the article for description and compare source code for changes., (*2)

Install

Via Composer, (*3)

``` bash $ composer require ksdev/shopping-cart, (*4)


## Usage ``` php use Ksdev\ShoppingCart\Cart; use Ksdev\ShoppingCart\Currency; use Ksdev\ShoppingCart\Item; $cart = new Cart(new Currency('PLN')); $tax = '23.00'; // Tax is optional $item1 = new Item('SKU1', 'Item 1', '100.00', $tax); $item2 = new Item('SKU2', 'Item 2', '200.00', $tax); $item3 = new Item('SKU3', 'Item 3', '300.00', $tax); $cart->addItem($item1); $cart->addItem($item2); $cart->addItem($item3); if (!$cart->isEmpty()) { foreach ($cart as $arr) { $item = $arr['item']; var_dump($item->getSku()); // E.g. string(4) "SKU1" var_dump($item->getName()); // E.g. string(6) "Item 1" var_dump($item->getPrice()); // E.g. string(6) "100.00" var_dump($item->getTax()); // E.g. string(5) "23.00" var_dump($arr['qty']); // E.g. int(1) } } var_dump($cart->total()); // string(6) "600.00" var_dump($cart->getCurrency()->getCode()); // string(3) "PLN" $item4 = new Item('SKU1', 'Item 1', '100.00', $tax); // Same as $item1 $cart->addItem($item4); var_dump($cart->total()); // string(6) "700.00" var_dump($cart->count()); // int(4); also: count($cart) var_dump($cart->countUnique()); // int(3) $cart->updateItem($item2, 3); // 3 is the new quantity var_dump($cart->count()); // int(6) var_dump($cart->countUnique()); // int(3) $cart->updateItem($item2, 0); // Removes the item from the cart var_dump($cart->count()); // int(3) var_dump($cart->countUnique()); // int(2) $cart->deleteItem($item1); // Removes the item from the cart var_dump($cart->count()); // int(1) var_dump($cart->countUnique()); // int(1) var_dump($cart->getItem('SKU3')); // Get item by Stock Keeping Unit /* array(2) { 'item' => class Ksdev\ShoppingCart\Item#270 (3) { protected $sku => string(4) "SKU3" protected $name => string(6) "Item 3" protected $price => string(6) "300.00" protected $tax => string(5) "23.00" } 'qty' => int(1) } */

Testing

bash $ composer test, (*5)

Credits

  • Larry Ullman

License

The MIT License (MIT). Please see License File for more information., (*6)

The Versions

23/08 2015

dev-master

9999999-dev https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev

05/08 2015

0.2.6

0.2.6.0 https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev

05/08 2015

0.2.5

0.2.5.0 https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev

02/08 2015

0.2.0

0.2.0.0 https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev

01/08 2015

0.1.1

0.1.1.0 https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev

01/08 2015

0.1.0

0.1.0.0 https://github.com/ksdev-pl/shopping-cart

Shopping cart

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

The Development Requires

by Larry Ullman

cart shopping-cart ksdev