1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Plane\Shop package. |
5
|
|
|
* |
6
|
|
|
* (c) Dariusz Korsak <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Plane\Shop\Traits; |
13
|
|
|
|
14
|
|
|
use Plane\Shop\PaymentInterface; |
15
|
|
|
use Plane\Shop\CartItemInterface; |
16
|
|
|
use Plane\Shop\ShippingInterface; |
17
|
|
|
use Plane\Shop\CartItemCollection; |
18
|
|
|
use Plane\Shop\CartDiscountInterface; |
19
|
|
|
|
20
|
|
|
trait CartCommon |
21
|
|
|
{ |
22
|
2 |
|
public function getCurrency(): string |
23
|
|
|
{ |
24
|
2 |
|
return $this->cart->getCurrency(); |
|
|
|
|
25
|
|
|
} |
26
|
|
|
|
27
|
13 |
|
public function setShipping(ShippingInterface $shipping): void |
28
|
|
|
{ |
29
|
13 |
|
$this->cart->setShipping($shipping); |
30
|
13 |
|
} |
31
|
|
|
|
32
|
2 |
|
public function getShipping(): ?ShippingInterface |
33
|
|
|
{ |
34
|
2 |
|
return $this->cart->getShipping(); |
35
|
|
|
} |
36
|
|
|
|
37
|
13 |
|
public function setPayment(PaymentInterface $payment): void |
38
|
|
|
{ |
39
|
13 |
|
$this->cart->setPayment($payment); |
40
|
13 |
|
} |
41
|
|
|
|
42
|
2 |
|
public function getPayment(): ?PaymentInterface |
43
|
|
|
{ |
44
|
2 |
|
return $this->cart->getPayment(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function addDiscount(CartDiscountInterface $discount): void |
48
|
|
|
{ |
49
|
|
|
$this->cart->addDiscount($discount); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
public function getDiscounts(): array |
53
|
|
|
{ |
54
|
1 |
|
return $this->cart->getDiscounts(); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function fill(CartItemCollection $collection): void |
58
|
|
|
{ |
59
|
|
|
$this->cart->fill($collection); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function add(CartItemInterface $item): void |
63
|
|
|
{ |
64
|
|
|
$this->cart->add($item); |
65
|
|
|
} |
66
|
|
|
|
67
|
2 |
|
public function remove(string $itemId): void |
68
|
|
|
{ |
69
|
2 |
|
$this->cart->remove($itemId); |
70
|
1 |
|
} |
71
|
|
|
|
72
|
1 |
|
public function clear(): void |
73
|
|
|
{ |
74
|
1 |
|
$this->cart->clear(); |
75
|
1 |
|
} |
76
|
|
|
|
77
|
1 |
|
public function update(CartItemInterface $item): void |
78
|
|
|
{ |
79
|
1 |
|
$this->cart->update($item); |
80
|
1 |
|
} |
81
|
|
|
|
82
|
2 |
|
public function has(string $itemId): bool |
83
|
|
|
{ |
84
|
2 |
|
return $this->cart->has($itemId); |
85
|
|
|
} |
86
|
|
|
|
87
|
2 |
|
public function get(string $itemId): CartItemInterface |
88
|
|
|
{ |
89
|
2 |
|
return $this->cart->get($itemId); |
90
|
|
|
} |
91
|
|
|
|
92
|
3 |
|
public function items(): array |
93
|
|
|
{ |
94
|
3 |
|
return $this->cart->items(); |
95
|
|
|
} |
96
|
|
|
|
97
|
2 |
|
public function itemsQuantity(): int |
98
|
|
|
{ |
99
|
2 |
|
return $this->cart->itemsQuantity(); |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
public function weight(): string |
103
|
|
|
{ |
104
|
1 |
|
return $this->cart->weight(); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: