|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file has been created by developers from BitBag. |
|
5
|
|
|
* Feel free to contact us once you face any issues or want to start |
|
6
|
|
|
* another great project. |
|
7
|
|
|
* You can find more information about us on https://bitbag.io and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusVueStorefrontPlugin\Document\Product; |
|
14
|
|
|
|
|
15
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Helper\DateHelper; |
|
16
|
|
|
|
|
17
|
|
|
class Details |
|
18
|
|
|
{ |
|
19
|
|
|
private const ENTITY_ID = 'id'; |
|
20
|
|
|
|
|
21
|
|
|
private const ENTITY_TYPE_ID = 'entity_type_id'; |
|
22
|
|
|
|
|
23
|
|
|
private const SKU = 'sku'; |
|
24
|
|
|
|
|
25
|
|
|
private const NAME = 'name'; |
|
26
|
|
|
|
|
27
|
|
|
private const ATTRIBUTE_SET_ID = 'attribute_set_id'; |
|
28
|
|
|
|
|
29
|
|
|
private const STATUS = 'status'; |
|
30
|
|
|
|
|
31
|
|
|
private const VISIBILITY = 'visibility'; |
|
32
|
|
|
|
|
33
|
|
|
private const TYPE = 'type_id'; |
|
34
|
|
|
|
|
35
|
|
|
private const CREATED_AT = 'created_at'; |
|
36
|
|
|
|
|
37
|
|
|
private const UPDATED_AT = 'updated_at'; |
|
38
|
|
|
|
|
39
|
|
|
private const EXTENSION_ATTRIBUTES = 'extension_attributes'; |
|
40
|
|
|
|
|
41
|
|
|
private const PRODUCT_LINKS = 'product_links'; |
|
42
|
|
|
|
|
43
|
|
|
private const TIER_PRICES = 'tier_prices'; |
|
44
|
|
|
|
|
45
|
|
|
private const CUSTOM_ATTRIBUTES = 'custom_attributes'; |
|
46
|
|
|
|
|
47
|
|
|
private const DESCRIPTION = 'description'; |
|
48
|
|
|
|
|
49
|
|
|
private const IMAGE = 'image'; |
|
50
|
|
|
|
|
51
|
|
|
private const SMALL_IMAGE = 'small_image'; |
|
52
|
|
|
|
|
53
|
|
|
private const THUMBNAIL = 'thumbnail'; |
|
54
|
|
|
|
|
55
|
|
|
private const REQUIRED_OPTIONS = 'required_options'; |
|
56
|
|
|
|
|
57
|
|
|
private const HAS_OPTIONS = 'has_options'; |
|
58
|
|
|
|
|
59
|
|
|
private const URL_KEY = 'url_key'; |
|
60
|
|
|
|
|
61
|
|
|
private const TAX_CLASS_ID = 'tax_class_id'; |
|
62
|
|
|
|
|
63
|
|
|
private const ERIN_RECOMMENDS = 'erin_recommends'; |
|
64
|
|
|
|
|
65
|
|
|
private const NEW = 'new'; |
|
66
|
|
|
|
|
67
|
|
|
private const SALE = 'sale'; |
|
68
|
|
|
|
|
69
|
|
|
private const CHILDREN_DATA = 'children_data'; |
|
70
|
|
|
|
|
71
|
|
|
// TODO DEMO APP ONLY |
|
72
|
|
|
private const SLUG = 'slug'; |
|
73
|
|
|
|
|
74
|
|
|
private const PARENT_SKU = 'parentSku'; |
|
75
|
|
|
|
|
76
|
|
|
private const IS_CONFIGURED = 'is_configured'; |
|
77
|
|
|
|
|
78
|
|
|
// TODO PROPERTIES BELOW APPEAR ONLY IN CORESHOP VS BRIDGE |
|
79
|
|
|
|
|
80
|
|
|
private const AVAILABILITY = 'availability'; |
|
81
|
|
|
|
|
82
|
|
|
private const TEXT_STATUS = 'option_text_status'; |
|
83
|
|
|
|
|
84
|
|
|
private const TAX_CLASS_NAME = 'option_text_tax_class_id'; |
|
85
|
|
|
|
|
86
|
|
|
private const SHORT_DESCRIPTION = 'short_description'; |
|
87
|
|
|
|
|
88
|
|
|
private const COLOR_OPTIONS = 'color_options'; |
|
89
|
|
|
|
|
90
|
|
|
private const SIZE_OPTIONS = 'size_options'; |
|
91
|
|
|
|
|
92
|
|
|
// INTEGRATION BOILERPLATE |
|
93
|
|
|
private const META_TITLE = 'meta_title'; |
|
94
|
|
|
|
|
95
|
|
|
private const META_DESCRIPTION = 'meta_description'; |
|
96
|
|
|
|
|
97
|
|
|
private const GIFT_MESSAGE_AVAILABLE = 'gift_message_available'; |
|
98
|
|
|
|
|
99
|
|
|
private const SPECIAL_FROM_DATE = 'special_from_date'; |
|
100
|
|
|
|
|
101
|
|
|
private const SPECIAL_TO_DATE = 'special_to_date'; |
|
102
|
|
|
|
|
103
|
|
|
private const TYPE_SIMPLE = 'simple'; |
|
104
|
|
|
|
|
105
|
|
|
private const TYPE_CONFIGURABLE = 'configurable'; |
|
106
|
|
|
|
|
107
|
|
|
/** https://docs.magento.com/m2/ce/user_guide/system/data-attributes-product.html */ |
|
108
|
|
|
private const TYPES_IN_MAGENTO2 = [self::TYPE_SIMPLE, self::TYPE_CONFIGURABLE, 'grouped', 'virtual', 'bundle']; |
|
109
|
|
|
|
|
110
|
|
|
private const DEFAULT_ENTITY_TYPE_ID = 4; |
|
111
|
|
|
|
|
112
|
|
|
private const DEFAULT_ATTRIBUTE_SET_ID = 11; |
|
113
|
|
|
|
|
114
|
|
|
private const DEFAULT_STATUS = 1; |
|
115
|
|
|
|
|
116
|
|
|
private const DEFAULT_VISIBILITY = 4; |
|
117
|
|
|
|
|
118
|
|
|
private const DEFAULT_TYPE = self::TYPE_SIMPLE; |
|
119
|
|
|
|
|
120
|
|
|
private const DEFAULT_CATEGORY_ID = 2; |
|
121
|
|
|
|
|
122
|
|
|
private const DEFAULT_AVAILABILITY = '1'; |
|
123
|
|
|
|
|
124
|
|
|
private const DEFAULT_OPTION_STATUS = 'Enabled'; |
|
125
|
|
|
|
|
126
|
|
|
private const DEFAULT_TAX_CLASS_ID = 2; |
|
127
|
|
|
|
|
128
|
|
|
private const DEFAULT_TAX_CLASS_NAME = 'Taxable Goods'; |
|
129
|
|
|
|
|
130
|
|
|
private const DEFAULT_CATEGORY = 'Default category'; |
|
131
|
|
|
|
|
132
|
|
|
private const DEFAULT_MEDIA_TYPE = 'image'; |
|
133
|
|
|
|
|
134
|
|
|
// NODEAPP MAPPING COMPARISON |
|
135
|
|
|
private const URL_PATH = 'url_path'; |
|
136
|
|
|
|
|
137
|
|
|
/** @var string */ |
|
138
|
|
|
private $urlPath; |
|
139
|
|
|
|
|
140
|
|
|
// END OF NODEAPP COMPARISON |
|
141
|
|
|
|
|
142
|
|
|
/** @var int */ |
|
143
|
|
|
private $entityId; |
|
144
|
|
|
|
|
145
|
|
|
/** @var int */ |
|
146
|
|
|
private $entityTypeId; |
|
147
|
|
|
|
|
148
|
|
|
/** @var int */ |
|
149
|
|
|
private $attributeSetId; |
|
150
|
|
|
|
|
151
|
|
|
/** @var string */ |
|
152
|
|
|
private $type; |
|
153
|
|
|
|
|
154
|
|
|
/** @var string */ |
|
155
|
|
|
private $sku; |
|
156
|
|
|
|
|
157
|
|
|
/** @var string */ |
|
158
|
|
|
private $urlKey; |
|
159
|
|
|
|
|
160
|
|
|
/** @var string */ |
|
161
|
|
|
private $name; |
|
162
|
|
|
|
|
163
|
|
|
/** @var int */ |
|
164
|
|
|
private $status; |
|
165
|
|
|
|
|
166
|
|
|
/** @var int */ |
|
167
|
|
|
private $visibility; |
|
168
|
|
|
|
|
169
|
|
|
/** @var \DateTimeInterface */ |
|
170
|
|
|
private $createdAt; |
|
171
|
|
|
|
|
172
|
|
|
/** @var \DateTimeInterface */ |
|
173
|
|
|
private $updatedAt; |
|
174
|
|
|
|
|
175
|
|
|
/** @var string */ |
|
176
|
|
|
private $image; |
|
177
|
|
|
|
|
178
|
|
|
/** @var bool */ |
|
179
|
|
|
private $availability; |
|
180
|
|
|
|
|
181
|
|
|
/** @var string */ |
|
182
|
|
|
private $textStatus; |
|
183
|
|
|
|
|
184
|
|
|
/** @var int */ |
|
185
|
|
|
private $taxClassId; |
|
186
|
|
|
|
|
187
|
|
|
/** @var string */ |
|
188
|
|
|
private $taxClassName; |
|
189
|
|
|
|
|
190
|
|
|
/** @var string */ |
|
191
|
|
|
private $description; |
|
192
|
|
|
|
|
193
|
|
|
/** @var string */ |
|
194
|
|
|
private $shortDescription; |
|
195
|
|
|
|
|
196
|
|
|
/** @var int */ |
|
197
|
|
|
private $hasOptions; |
|
198
|
|
|
|
|
199
|
|
|
/** @var int */ |
|
200
|
|
|
private $requiredOptions; |
|
201
|
|
|
|
|
202
|
|
|
/** @var array */ |
|
203
|
|
|
private $productLinks; |
|
204
|
|
|
|
|
205
|
|
|
/** @var array */ |
|
206
|
|
|
private $colorOptions; |
|
207
|
|
|
|
|
208
|
|
|
/** @var array */ |
|
209
|
|
|
private $sizeOptions; |
|
210
|
|
|
|
|
211
|
|
|
// TODO OPTIONAL STUFF FROM VARIOUS PLACES |
|
212
|
|
|
|
|
213
|
|
|
/** @var array */ |
|
214
|
|
|
private $extensionAttributes = []; |
|
215
|
|
|
|
|
216
|
|
|
/** @var array */ |
|
217
|
|
|
private $tierPrices = []; |
|
218
|
|
|
|
|
219
|
|
|
/** @var array|null */ |
|
220
|
|
|
private $customAttributes; |
|
221
|
|
|
|
|
222
|
|
|
/** @var string */ |
|
223
|
|
|
private $smallImage = '/a/b/small.jpg'; |
|
224
|
|
|
|
|
225
|
|
|
/** @var string */ |
|
226
|
|
|
private $thumbnail = '/a/b/small.jpg'; |
|
227
|
|
|
|
|
228
|
|
|
/** @var bool */ |
|
229
|
|
|
private $erinRecommends = true; |
|
230
|
|
|
|
|
231
|
|
|
/** @var bool */ |
|
232
|
|
|
private $new = true; |
|
233
|
|
|
|
|
234
|
|
|
/** @var bool */ |
|
235
|
|
|
private $sale = true; |
|
236
|
|
|
|
|
237
|
|
|
/** @var array */ |
|
238
|
|
|
private $childrenData = []; |
|
239
|
|
|
|
|
240
|
|
|
/** @var string */ |
|
241
|
|
|
private $slug; |
|
242
|
|
|
|
|
243
|
|
|
/** @var string */ |
|
244
|
|
|
private $parentSku; |
|
245
|
|
|
|
|
246
|
|
|
/** @var bool */ |
|
247
|
|
|
private $isConfigured = true; |
|
248
|
|
|
|
|
249
|
|
|
// TODO INTEGRATION BOILERPLATE ONLY |
|
250
|
|
|
|
|
251
|
|
|
/** @var string|null */ |
|
252
|
|
|
private $metaTitle; |
|
253
|
|
|
|
|
254
|
|
|
/** @var string|null */ |
|
255
|
|
|
private $metaDescription; |
|
256
|
|
|
|
|
257
|
|
|
/** @var bool|null */ |
|
258
|
|
|
private $giftMessageAvailable; |
|
259
|
|
|
|
|
260
|
|
|
/** @var \DateTime|null */ |
|
261
|
|
|
private $specialFromDate; |
|
262
|
|
|
|
|
263
|
|
|
/** @var \DateTime|null */ |
|
264
|
|
|
private $specialToDate; |
|
265
|
|
|
|
|
266
|
|
|
public function __construct( |
|
267
|
|
|
int $entityId, |
|
268
|
|
|
?int $entityTypeId, |
|
269
|
|
|
?int $attributeSetId, |
|
270
|
|
|
?string $type, |
|
271
|
|
|
?string $sku, |
|
272
|
|
|
string $urlKey, |
|
273
|
|
|
string $name, |
|
274
|
|
|
?int $status, |
|
275
|
|
|
?int $visibility, |
|
276
|
|
|
\DateTimeInterface $createdAt, |
|
277
|
|
|
\DateTimeInterface $updatedAt, |
|
278
|
|
|
?string $image, |
|
279
|
|
|
bool $availability, |
|
280
|
|
|
?string $textStatus, |
|
281
|
|
|
?int $taxClassId, |
|
282
|
|
|
?string $taxClassName, |
|
283
|
|
|
?string $description, |
|
284
|
|
|
?string $shortDescription, |
|
285
|
|
|
int $hasOptions, |
|
286
|
|
|
int $requiredOptions, |
|
287
|
|
|
array $productLinks, |
|
288
|
|
|
array $colorOptions, |
|
289
|
|
|
array $sizeOptions, |
|
290
|
|
|
string $parentSku |
|
291
|
|
|
) { |
|
292
|
|
|
$this->entityId = $entityId; |
|
293
|
|
|
$this->entityTypeId = $entityTypeId ?? self::DEFAULT_ENTITY_TYPE_ID; |
|
294
|
|
|
$this->attributeSetId = $attributeSetId ?? self::DEFAULT_ATTRIBUTE_SET_ID; |
|
295
|
|
|
$this->type = $type ?? self::TYPE_SIMPLE; |
|
296
|
|
|
$this->sku = $sku; |
|
297
|
|
|
$this->urlKey = $urlKey; |
|
298
|
|
|
$this->name = $name; |
|
299
|
|
|
$this->status = $status ?? self::DEFAULT_STATUS; |
|
300
|
|
|
$this->visibility = $visibility ?? self::DEFAULT_VISIBILITY; |
|
301
|
|
|
$this->createdAt = $createdAt; |
|
302
|
|
|
$this->updatedAt = $updatedAt; |
|
303
|
|
|
$this->image = $image; |
|
304
|
|
|
$this->availability = $availability; |
|
305
|
|
|
$this->textStatus = $textStatus ?? self::DEFAULT_OPTION_STATUS; |
|
306
|
|
|
$this->taxClassId = $taxClassId ?? self::DEFAULT_TAX_CLASS_ID; |
|
307
|
|
|
$this->taxClassName = $taxClassName ?? self::DEFAULT_TAX_CLASS_NAME; |
|
308
|
|
|
$this->description = $description; |
|
309
|
|
|
$this->shortDescription = $shortDescription; |
|
310
|
|
|
$this->hasOptions = $hasOptions; |
|
311
|
|
|
$this->requiredOptions = $requiredOptions; |
|
312
|
|
|
$this->productLinks = $productLinks; |
|
313
|
|
|
$this->colorOptions = $colorOptions; |
|
314
|
|
|
$this->sizeOptions = $sizeOptions; |
|
315
|
|
|
$this->urlPath = $urlKey; |
|
316
|
|
|
$this->slug = $urlKey; |
|
317
|
|
|
$this->parentSku = $parentSku; |
|
318
|
|
|
} |
|
319
|
|
|
|
|
320
|
|
|
public function toArray(): array |
|
321
|
|
|
{ |
|
322
|
|
|
return [ |
|
323
|
|
|
self::ENTITY_ID => $this->entityId, |
|
324
|
|
|
self::ENTITY_TYPE_ID => $this->entityTypeId, |
|
325
|
|
|
self::ATTRIBUTE_SET_ID => $this->attributeSetId, |
|
326
|
|
|
self::TYPE => $this->type, |
|
327
|
|
|
self::SKU => $this->sku, |
|
328
|
|
|
self::URL_KEY => $this->urlKey, |
|
329
|
|
|
self::NAME => $this->name, |
|
330
|
|
|
self::STATUS => $this->status, |
|
331
|
|
|
self::VISIBILITY => $this->visibility, |
|
332
|
|
|
self::CREATED_AT => $this->createdAt->format(DateHelper::DATE_FORMAT), |
|
333
|
|
|
self::UPDATED_AT => $this->updatedAt->format(DateHelper::DATE_FORMAT), |
|
334
|
|
|
self::IMAGE => $this->image, |
|
335
|
|
|
self::AVAILABILITY => (string) $this->availability, |
|
336
|
|
|
self::TEXT_STATUS => $this->textStatus, |
|
337
|
|
|
self::TAX_CLASS_ID => (string) $this->taxClassId, |
|
338
|
|
|
self::TAX_CLASS_NAME => $this->taxClassName, |
|
339
|
|
|
self::DESCRIPTION => $this->description, |
|
340
|
|
|
self::SHORT_DESCRIPTION => $this->shortDescription, |
|
341
|
|
|
self::HAS_OPTIONS => $this->hasOptions, |
|
342
|
|
|
self::REQUIRED_OPTIONS => $this->requiredOptions, |
|
343
|
|
|
self::PRODUCT_LINKS => $this->productLinks, |
|
344
|
|
|
self::COLOR_OPTIONS => $this->colorOptions, |
|
345
|
|
|
self::SIZE_OPTIONS => $this->sizeOptions, |
|
346
|
|
|
self::EXTENSION_ATTRIBUTES => $this->extensionAttributes, |
|
347
|
|
|
self::TIER_PRICES => $this->tierPrices, |
|
348
|
|
|
self::CUSTOM_ATTRIBUTES => $this->customAttributes, |
|
349
|
|
|
self::SMALL_IMAGE => $this->smallImage, |
|
350
|
|
|
self::THUMBNAIL => $this->thumbnail, |
|
351
|
|
|
self::ERIN_RECOMMENDS => (string) (int) $this->erinRecommends, |
|
352
|
|
|
self::NEW => (string) (int) $this->new, |
|
353
|
|
|
self::SALE => (string) (int) $this->sale, |
|
354
|
|
|
self::CHILDREN_DATA => $this->childrenData, |
|
355
|
|
|
self::SLUG => $this->slug, |
|
356
|
|
|
self::PARENT_SKU => $this->parentSku, |
|
357
|
|
|
self::IS_CONFIGURED => $this->isConfigured, |
|
358
|
|
|
self::META_TITLE => $this->metaTitle, |
|
359
|
|
|
self::META_DESCRIPTION => $this->metaDescription, |
|
360
|
|
|
self::GIFT_MESSAGE_AVAILABLE => (int) $this->giftMessageAvailable, |
|
361
|
|
|
self::SPECIAL_FROM_DATE => $this->specialFromDate, |
|
362
|
|
|
self::SPECIAL_TO_DATE => $this->specialToDate, |
|
363
|
|
|
self::URL_PATH => $this->urlPath, |
|
364
|
|
|
]; |
|
365
|
|
|
} |
|
366
|
|
|
|
|
367
|
|
|
public function isConfigurableProduct(): bool |
|
368
|
|
|
{ |
|
369
|
|
|
return $this->type === self::TYPE_CONFIGURABLE; |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
|