Framework independent cart extension. Use in project whatever you want!
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
.
- 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();
$ ./vendor/bin/phpunit
This project is released under the terms of the MIT license.
Copyright (c) 2018, Dmytry Fedorenko