/shopping-cart

Framework independent cart extension. Use in project whatever you want!

Primary LanguagePHPMIT LicenseMIT

Shopping cart

Framework independent cart extension. Use in project whatever you want!

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

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

  1. 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
);
  1. Add items
$cartItem = new CartItem(1, 100, 1);
$cart->add($cartItem);
  1. Update item quantity
$cart->changeQuantityById($cartItem->getId(), 5);
  1. Get all items
$items = $cart->getItems();
  1. 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