|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Waredesk\Models; |
|
4
|
|
|
|
|
5
|
|
|
use DateTime; |
|
6
|
|
|
use Waredesk\Collections\Products\Variants; |
|
7
|
|
|
use JsonSerializable; |
|
8
|
|
|
use Waredesk\Image; |
|
9
|
|
|
|
|
10
|
|
|
class Product implements JsonSerializable |
|
11
|
|
|
{ |
|
12
|
|
|
private $id; |
|
13
|
|
|
private $images; |
|
14
|
|
|
private $variants; |
|
15
|
|
|
private $name; |
|
16
|
|
|
private $description; |
|
17
|
|
|
private $notes; |
|
18
|
|
|
private $creation_datetime; |
|
19
|
|
|
private $modification_datetime; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var Image |
|
23
|
|
|
*/ |
|
24
|
|
|
private $pendingImage; |
|
25
|
|
|
|
|
26
|
2 |
|
public function __construct() |
|
27
|
|
|
{ |
|
28
|
2 |
|
$this->variants = new Variants(); |
|
29
|
2 |
|
} |
|
30
|
|
|
|
|
31
|
1 |
|
public function getId(): ?int |
|
32
|
|
|
{ |
|
33
|
1 |
|
return $this->id; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
2 |
|
public function setId(int $id = null) |
|
37
|
|
|
{ |
|
38
|
2 |
|
$this->id = $id; |
|
39
|
2 |
|
} |
|
40
|
|
|
|
|
41
|
1 |
|
public function getImages(): ?array |
|
42
|
|
|
{ |
|
43
|
1 |
|
return $this->images; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
2 |
|
public function setImages(array $images = null) |
|
47
|
|
|
{ |
|
48
|
2 |
|
$this->pendingImage = null; |
|
49
|
2 |
|
$this->images = $images; |
|
50
|
2 |
|
} |
|
51
|
|
|
|
|
52
|
1 |
|
public function setImage(Image $image = null) |
|
53
|
|
|
{ |
|
54
|
1 |
|
$this->pendingImage = $image; |
|
55
|
1 |
|
} |
|
56
|
|
|
|
|
57
|
2 |
|
public function getVariants(): ?Variants |
|
58
|
|
|
{ |
|
59
|
2 |
|
return $this->variants; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
public function setVariants(Variants $variants) |
|
63
|
|
|
{ |
|
64
|
2 |
|
$this->variants = $variants; |
|
65
|
2 |
|
} |
|
66
|
|
|
|
|
67
|
2 |
|
public function getName(): ?string |
|
68
|
|
|
{ |
|
69
|
2 |
|
return $this->name; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
2 |
|
public function setName(string $name = null) |
|
73
|
|
|
{ |
|
74
|
2 |
|
$this->name = $name; |
|
75
|
2 |
|
} |
|
76
|
|
|
|
|
77
|
2 |
|
public function getDescription(): ?string |
|
78
|
|
|
{ |
|
79
|
2 |
|
return $this->description; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
2 |
|
public function setDescription(string $description = null) |
|
83
|
|
|
{ |
|
84
|
2 |
|
$this->description = $description; |
|
85
|
2 |
|
} |
|
86
|
|
|
|
|
87
|
2 |
|
public function getNotes(): ?string |
|
88
|
|
|
{ |
|
89
|
2 |
|
return $this->notes; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
2 |
|
public function setNotes(string $notes = null) |
|
93
|
|
|
{ |
|
94
|
2 |
|
$this->notes = $notes; |
|
95
|
2 |
|
} |
|
96
|
|
|
|
|
97
|
|
|
public function getCreationDatetime(): ?DateTime |
|
98
|
|
|
{ |
|
99
|
|
|
return $this->creation_datetime; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
2 |
|
public function setCreationDatetime(DateTime $creation_datetime = null) |
|
103
|
|
|
{ |
|
104
|
2 |
|
$this->creation_datetime = $creation_datetime; |
|
105
|
2 |
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function getModificationDatetime(): ?DateTime |
|
108
|
|
|
{ |
|
109
|
|
|
return $this->modification_datetime; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
2 |
|
public function setModificationDatetime(DateTime $modification_datetime = null) |
|
113
|
|
|
{ |
|
114
|
2 |
|
$this->modification_datetime = $modification_datetime; |
|
115
|
2 |
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
public function jsonSerialize() |
|
118
|
|
|
{ |
|
119
|
|
|
$returnValue = [ |
|
120
|
2 |
|
'variants' => $this->getVariants()->jsonSerialize(), |
|
121
|
2 |
|
'name' => $this->getName(), |
|
|
|
|
|
|
122
|
2 |
|
'description' => $this->getDescription(), |
|
123
|
2 |
|
'notes' => $this->getNotes(), |
|
124
|
|
|
]; |
|
125
|
2 |
|
if ($this->pendingImage) { |
|
126
|
1 |
|
$returnValue['image'] = $this->pendingImage->toBase64(); |
|
127
|
|
|
} |
|
128
|
2 |
|
return $returnValue; |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|