1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainFoundation\Entity; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\VariantInterface; |
8
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\VariantTrait; |
9
|
|
|
use Loevgaard\DandomainFoundation; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @ORM\Entity() |
13
|
|
|
* @ORM\Table(name="loevgaard_dandomain_variants") |
14
|
|
|
*/ |
15
|
|
|
class Variant implements VariantInterface |
16
|
|
|
{ |
17
|
|
|
use VariantTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var int |
21
|
|
|
* |
22
|
|
|
* @ORM\Id |
23
|
|
|
* @ORM\GeneratedValue |
24
|
|
|
* @ORM\Column(type="integer") |
25
|
|
|
**/ |
26
|
|
|
protected $id; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @var int |
30
|
|
|
* |
31
|
|
|
* @ORM\Column(type="integer", unique=true) |
32
|
|
|
*/ |
33
|
|
|
protected $externalId; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var int|null |
37
|
|
|
* |
38
|
|
|
* @ORM\Column(nullable=true, type="integer") |
39
|
|
|
*/ |
40
|
|
|
protected $sortOrder; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var string|null |
44
|
|
|
* |
45
|
|
|
* @ORM\Column(nullable=true, type="string") |
46
|
|
|
*/ |
47
|
|
|
protected $text; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var Product[]|ArrayCollection |
51
|
|
|
* |
52
|
|
|
* @ORM\ManyToMany(mappedBy="disabledVariants", targetEntity="Product") |
53
|
|
|
*/ |
54
|
|
|
protected $disabledProducts; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var Product[]|ArrayCollection |
58
|
|
|
* |
59
|
|
|
* @ORM\ManyToMany(mappedBy="variants", targetEntity="Product") |
60
|
|
|
*/ |
61
|
|
|
protected $products; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var VariantGroup[]|ArrayCollection |
65
|
|
|
* |
66
|
|
|
* @ORM\ManyToMany(mappedBy="variants", targetEntity="VariantGroup") |
67
|
|
|
*/ |
68
|
|
|
protected $variantGroups; |
69
|
|
|
|
70
|
|
|
public function __construct() |
71
|
|
|
{ |
72
|
|
|
$this->disabledProducts = new ArrayCollection(); |
73
|
|
|
$this->products = new ArrayCollection(); |
74
|
|
|
$this->variantGroups = new ArrayCollection(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Populates a variant based on the response from the Dandomain API |
79
|
|
|
* |
80
|
|
|
* See the properties here: |
81
|
|
|
* http://4221117.shop53.dandomain.dk/admin/webapi/endpoints/v1_0/ProductDataService/help/operations/GetDataProduct |
82
|
|
|
* |
83
|
|
|
* @param \stdClass|array $data |
84
|
|
|
*/ |
85
|
|
|
public function populateFromApiResponse($data) |
86
|
|
|
{ |
87
|
|
|
$data = DandomainFoundation\objectToArray($data); |
88
|
|
|
|
89
|
|
|
$this |
90
|
|
|
->setExternalId($data['id']) |
91
|
|
|
->setSortOrder($data['sortOrder']) |
92
|
|
|
->setText($data['text']) |
93
|
|
|
; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @return int |
98
|
|
|
*/ |
99
|
|
|
public function getId(): int |
100
|
|
|
{ |
101
|
|
|
return (int)$this->id; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param int $id |
106
|
|
|
* @return Variant |
107
|
|
|
*/ |
108
|
|
|
public function setId(int $id) |
109
|
|
|
{ |
110
|
|
|
$this->id = $id; |
111
|
|
|
return $this; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @return int |
116
|
|
|
*/ |
117
|
|
|
public function getExternalId(): int |
118
|
|
|
{ |
119
|
|
|
return (int)$this->externalId; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param int $externalId |
124
|
|
|
* @return Variant |
125
|
|
|
*/ |
126
|
|
|
public function setExternalId(int $externalId) |
127
|
|
|
{ |
128
|
|
|
$this->externalId = $externalId; |
129
|
|
|
return $this; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @return int|null |
134
|
|
|
*/ |
135
|
|
|
public function getSortOrder() |
136
|
|
|
{ |
137
|
|
|
return $this->sortOrder; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param int|null $sortOrder |
142
|
|
|
* @return Variant |
143
|
|
|
*/ |
144
|
|
|
public function setSortOrder($sortOrder) |
145
|
|
|
{ |
146
|
|
|
$this->sortOrder = $sortOrder; |
147
|
|
|
return $this; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return null|string |
152
|
|
|
*/ |
153
|
|
|
public function getText() |
154
|
|
|
{ |
155
|
|
|
return $this->text; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @param null|string $text |
160
|
|
|
* @return Variant |
161
|
|
|
*/ |
162
|
|
|
public function setText($text) |
163
|
|
|
{ |
164
|
|
|
$this->text = $text; |
165
|
|
|
return $this; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @return ArrayCollection|Product[] |
170
|
|
|
*/ |
171
|
|
|
public function getDisabledProducts() |
172
|
|
|
{ |
173
|
|
|
return $this->disabledProducts; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* @param ArrayCollection|Product[] $disabledProducts |
178
|
|
|
* @return Variant |
179
|
|
|
*/ |
180
|
|
|
public function setDisabledProducts($disabledProducts) |
181
|
|
|
{ |
182
|
|
|
$this->disabledProducts = $disabledProducts; |
183
|
|
|
return $this; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @return ArrayCollection|Product[] |
188
|
|
|
*/ |
189
|
|
|
public function getProducts() |
190
|
|
|
{ |
191
|
|
|
return $this->products; |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
/** |
195
|
|
|
* @param ArrayCollection|Product[] $products |
196
|
|
|
* @return Variant |
197
|
|
|
*/ |
198
|
|
|
public function setProducts($products) |
199
|
|
|
{ |
200
|
|
|
$this->products = $products; |
201
|
|
|
return $this; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @return ArrayCollection|VariantGroup[] |
206
|
|
|
*/ |
207
|
|
|
public function getVariantGroups() |
208
|
|
|
{ |
209
|
|
|
return $this->variantGroups; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* @param ArrayCollection|VariantGroup[] $variantGroups |
214
|
|
|
* @return Variant |
215
|
|
|
*/ |
216
|
|
|
public function setVariantGroups($variantGroups) |
217
|
|
|
{ |
218
|
|
|
$this->variantGroups = $variantGroups; |
219
|
|
|
return $this; |
220
|
|
|
} |
221
|
|
|
} |
222
|
|
|
|