atakajlo / shopping-cart
Framework independent cart component for your site
1.2.3
2018-06-22 12:58 UTC
Requires
- php: ^7.1
Requires (Dev)
- phpunit/phpunit: ^7.1
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Framework independent cart extension. Use in project whatever you want!
Installation
The preferred way to install this extension is through composer.
Either run
$ composer require atakajlo/shopping-cart
or add
"atakajlo/shopping-cart": "^1.2"
to the require section of your composer.json.
Usage
- Configure cart extension
use atakajlo\cart\cost\calculator\SimpleCalculator; use atakajlo\cart\Cart; use atakajlo\cart\item\CartItem; use atakajlo\cart\storage\SessionStorage; use atakajlo\cart\sort\IdComparator; $cart = new Cart( new SessionStorage(), new SimpleCalculator(), new IdComparator() //optional );
- Add items
$cartItem = new CartItem(1, 100, 1); $cart->add($cartItem);
- Update item quantity
$cart->changeQuantityById($cartItem->getId(), 5);
- Get all items
$items = $cart->getItems();
- Get cart total cost
$totalCost = $cart->getCost()->getTotal();
Tests
$ ./vendor/bin/phpunit
License
This project is released under the terms of the MIT license.
Copyright (c) 2018, Dmytry Fedorenko