@@ 45-64 (lines=20) @@ | ||
42 | * @param array $item |
|
43 | * @return bool |
|
44 | */ |
|
45 | public function add(array $item) : bool |
|
46 | { |
|
47 | // validation structure |
|
48 | if ($this->validate($item, ['id', 'user_id']) === false) { |
|
49 | return false; |
|
50 | } |
|
51 | ||
52 | if ($this->existUser((int)$item['user_id'])) { |
|
53 | if ($this->existItem($item)) { |
|
54 | call_user_func([$this, 'incrementItem'], $item); |
|
55 | } else { |
|
56 | call_user_func([$this, 'addItem'], $item); |
|
57 | } |
|
58 | } else { |
|
59 | $item['count'] = 1; |
|
60 | $this->addRow((int)$item['user_id'], inJson([$item])); |
|
61 | } |
|
62 | ||
63 | return true; |
|
64 | } |
|
65 | ||
66 | /** |
|
67 | * Remove item from cart |
@@ 45-63 (lines=19) @@ | ||
42 | * @param array $item |
|
43 | * @return mixed |
|
44 | */ |
|
45 | public function add(array $item): bool |
|
46 | { |
|
47 | if ($this->validate($item, ['id', 'user_id']) === false) { |
|
48 | return false; |
|
49 | } |
|
50 | ||
51 | if ($this->existUser((int)$item['user_id'])) { |
|
52 | if ($this->existItem((int)$item['id'], (int)$item['user_id'])) { |
|
53 | call_user_func([$this, 'incrementItem'], $item); |
|
54 | } else { |
|
55 | call_user_func([$this, 'addItem'], $item); |
|
56 | } |
|
57 | } else { |
|
58 | $item['count'] = 1; |
|
59 | $this->addRow($item); |
|
60 | } |
|
61 | ||
62 | return true; |
|
63 | } |
|
64 | ||
65 | /** |
|
66 | * Remove item from cart |