1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This software may be modified and distributed under the terms |
7
|
|
|
* of the MIT license. See the LICENSE file for details. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace FAPI\Sylius\Model\Cart; |
11
|
|
|
|
12
|
|
|
use FAPI\Sylius\Model\CreatableFromArray; |
13
|
|
|
use FAPI\Sylius\Model\Customer\Customer; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @author Kasim Taskin <[email protected]> |
17
|
|
|
*/ |
18
|
|
|
final class Cart implements CreatableFromArray |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var int |
22
|
|
|
*/ |
23
|
|
|
private $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Customer |
27
|
|
|
*/ |
28
|
|
|
private $customer; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
private $currencyCode; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var string |
37
|
|
|
*/ |
38
|
|
|
private $localeCode; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $checkoutState; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var CartItem[] |
47
|
|
|
*/ |
48
|
|
|
private $items; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* CartCreated constructor. |
52
|
|
|
*/ |
53
|
|
|
private function __construct( |
54
|
|
|
int $id, |
55
|
|
|
Customer $customer, |
56
|
|
|
string $currencyCode, |
57
|
|
|
string $localeCode, |
58
|
|
|
string $checkoutState, |
59
|
|
|
array $items |
60
|
|
|
) { |
61
|
|
|
$this->id = $id; |
62
|
|
|
$this->customer = $customer; |
63
|
|
|
$this->currencyCode = $currencyCode; |
64
|
|
|
$this->localeCode = $localeCode; |
65
|
|
|
$this->checkoutState = $checkoutState; |
66
|
|
|
$this->items = $items; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @return Cart |
71
|
|
|
*/ |
72
|
|
|
public static function createFromArray(array $data): self |
73
|
|
|
{ |
74
|
|
|
$id = -1; |
75
|
|
|
if (isset($data['id'])) { |
76
|
|
|
$id = $data['id']; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
$customer = Customer::createFromArray([]); |
80
|
|
|
if (isset($data['customer'])) { |
81
|
|
|
$customer = Customer::createFromArray($data['customer']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
$currencyCode = ''; |
85
|
|
|
if (isset($data['currencyCode'])) { |
86
|
|
|
$currencyCode = $data['currencyCode']; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$localeCode = ''; |
90
|
|
|
if (isset($data['localeCode'])) { |
91
|
|
|
$localeCode = $data['localeCode']; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
$checkoutState = ''; |
95
|
|
|
if (isset($data['checkoutState'])) { |
96
|
|
|
$checkoutState = $data['checkoutState']; |
97
|
|
|
} |
98
|
|
|
/** @var CartItem[] $items */ |
99
|
|
|
$items = []; |
100
|
|
|
if (isset($data['items'])) { |
101
|
|
|
foreach ($data['items'] as $item) { |
102
|
|
|
$items[] = CartItem::createFromArray($item); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return new self($id, $customer, $currencyCode, $localeCode, $checkoutState, $items); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function getId(): int |
110
|
|
|
{ |
111
|
|
|
return $this->id; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function getCustomer(): Customer |
115
|
|
|
{ |
116
|
|
|
return $this->customer; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function getCurrencyCode(): string |
120
|
|
|
{ |
121
|
|
|
return $this->currencyCode; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function getLocaleCode(): string |
125
|
|
|
{ |
126
|
|
|
return $this->localeCode; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function getCheckoutState(): string |
130
|
|
|
{ |
131
|
|
|
return $this->checkoutState; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @return CartItem[] |
136
|
|
|
*/ |
137
|
|
|
public function getItems(): array |
138
|
|
|
{ |
139
|
|
|
return $this->items; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|