ygoncharova / terminal
本软件包最新版本(dev-master)没有提供许可信息。
dev-master
2020-06-16 09:32 UTC
Requires
- php: >=7.3
Requires (Dev)
- phpunit/phpunit: ^6.5
This package is not auto-updated.
Last update: 2024-10-03 03:38:51 UTC
README
设置产品价格,扫描产品并获得计算总价
##需求 Terminal 库有以下需求
PHP 7.3+ PHPUnit ^6.5
安装
$ git clone git@github.com:yhoncharova/TerminalLib.git $ composer update
Terminal
创建实例
$terminal = new Terminal();
设置产品价格
$code = 'AZ'; $quantity = 1; $price = 2.00; $terminal->setPricing($code, $quantity, $price);
扫描产品
$terminal->scanCode('AZ');
获取扫描产品的计算总价
$terminal->getTotal();
价格
产品单位体积的价格。创建 Price 对象时,将数量作为整数,价格作为浮点数传递。
$price = new Price(2, 17.25);
##产品 购物篮中的每一项都被封装为 Product
实例。
Product
类包含购物篮中每一项的当前状态。
要创建新的 Product
,请传递产品的 code
和 quantity
。如果没有传递构造函数中的值,则数量将自动设置为 1。
$code = '1'; $quantity = 2; $product = new Product($code, $quantity);
要增加 quantity
,请使用 increaseQuantity
方法。
$product->increaseQuantity(); // increment `quantity` $product->increaseQuantity(3); // increase `quantity` by 2 items
一旦创建了 Product
,其 code
就不应改变,因此对象上没有设置该属性的 setter 方法。
##Pricier 产品代码的集合与它们的价格对象的集合相关联。要填充 Pricier 中的产品价格
$pricier = new Pricier(); $pricier->add($code, $quantity, $price); $pricier->add($code, $quantity, $price);
获取特定产品的价格
$pricier->getPrice($product);
##购物篮 购物篮对象管理将产品添加到购物篮中。
创建新的 Basket
实例
$basket = new Basket();
Basket
将在构造函数中创建一个新的 Collection
实例,以封装并管理购物篮中的产品实例。
获取产品数量
$basket->count();
通过其 code
从购物篮中获取产品
$product = $basket->get('AZ');
要将产品添加到购物篮中,请将 code
传递给 add
方法。如果购物篮中已存在具有相同 code
的产品,则 quantity
将增加。
$code = 'AZ'; $basket->add($code);
感谢使用 :)