ygoncharova / terminal
Requires
- php: >=7.3
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-09-19 03:32:43 UTC
README
Set prices for products, scan products and get calculated total price
##Requirements The Terminal library has the following requirements:
PHP 7.3+ PHPUnit ^6.5
Installation
$ git clone git@github.com:yhoncharova/TerminalLib.git $ composer update
Terminal
Create an instance:
$terminal = new Terminal();
Set prices for products:
$code = 'AZ'; $quantity = 1; $price = 2.00; $terminal->setPricing($code, $quantity, $price);
Scan products:
$terminal->scanCode('AZ');
Get calculated total price for scanned products:
$terminal->getTotal();
Price
Price for unit volume of products. To create Price object, pass quantity as integer and price as float.
$price = new Price(2, 17.25);
##Product
Each item of the basket is encapsulated as an instance of Product
.
The Product
class contains the current state of the each item in the basket.
To create a new Product
, pass the product's code
, quantity
. Quantity will be set automatically to 1, if no value passed into constructor.
$code = '1'; $quantity = 2; $product = new Product($code, $quantity);
To increase quantity
, use increaseQuantity
method.
$product->increaseQuantity(); // increment `quantity` $product->increaseQuantity(3); // increase `quantity` by 2 items
The code
should not be changed once the Product
is created and so there is no setter method for the property on the object.
##Pricier Collection of Product codes which are linked to collection of their Price objects. To fill Pricier with product prices:
$pricier = new Pricier(); $pricier->add($code, $quantity, $price); $pricier->add($code, $quantity, $price);
To get price of particular product:
$pricier->getPrice($product);
##Basket The Basket object manages the adding of products into basket.
To create a new Basket
instance:
$basket = new Basket();
The Basket
will create a new Collection
instance in constructor to encapsulate manage the Product instances in basket.
Get the count of the products:
$basket->count();
Get a product from the basket via it's code
:
$product = $basket->get('AZ');
To add a product to the basket, pass the code
to add
method. If product with the code
already exists in the basket, then quantity
will be incremented.
$code = 'AZ'; $basket->add($code);
Thanks for using :)