-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditor-version.php
More file actions
84 lines (75 loc) · 1.39 KB
/
editor-version.php
File metadata and controls
84 lines (75 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
**
* Interfaces
*
*/
interface CartInterface {
/**
* Add Product
* If item is in cart, increment quantity
* If quantity is not 1, set absolute quantity value, instead of incrementing
* If product is less than one, remove product from cart
*
*/
function addProduct($id, $quantity = 1);
function removeProduct($id);
/**
* Get Total Price
* price * quantity for all items
*/
function getTotalPrice();
/**
* Get Total Items
* item * quantity
*/
function getTotalItems();
/**
* Output table of all items, prices, quantity in cart, etc
*/
function printCart();
}
/**
* Products Database Example
*/
$products = [
[
'id' => 1,
'title' => 'Valheim',
'price' => 19.99,
],
[
'id' => 2,
'title' => 'Loop Hero',
'price' => 12.74,
],
[
'id' => 3,
'title' => 'Rust',
'price' => 39.99,
],
[
'id' => 4,
'title' => 'Hades',
'price' => 24.99,
],
];
/*
* Query Example database by id
*/
function getProductById($id){
// return product
// throw error if not found
}
/*
* Implement Cart methods
*/
// class Cart implements CartInterface {
// }
/**
* App Code Here
*/
// init cart
// add various items to cart
// remove item or two from cart
// update item quantity
// print cart