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; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\Category; |
16
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ConfigurableChildren; |
17
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ConfigurableOptions; |
18
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\Details; |
19
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\MediaGallery; |
20
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\Price; |
21
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ProductLinks; |
22
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\Stock; |
23
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\StockItem; |
24
|
|
|
|
25
|
|
|
class Product implements ProductInterface |
26
|
|
|
{ |
27
|
|
|
/** @var int */ |
28
|
|
|
private $documentId; |
29
|
|
|
|
30
|
|
|
/** @var Details */ |
31
|
|
|
private $details; |
32
|
|
|
|
33
|
|
|
/** @var Stock */ |
34
|
|
|
private $stock; |
35
|
|
|
|
36
|
|
|
/** @var Category */ |
37
|
|
|
private $category; |
38
|
|
|
|
39
|
|
|
/** @var MediaGallery */ |
40
|
|
|
private $mediaGallery; |
41
|
|
|
|
42
|
|
|
/** @var ConfigurableChildren */ |
43
|
|
|
private $configurableChildren; |
44
|
|
|
|
45
|
|
|
/** @var ConfigurableOptions */ |
46
|
|
|
private $configurableOptions; |
47
|
|
|
|
48
|
|
|
/** @var ProductLinks */ |
49
|
|
|
private $productLinks; |
50
|
|
|
|
51
|
|
|
/** @var Price */ |
52
|
|
|
private $price; |
53
|
|
|
|
54
|
|
|
/** @var StockItem */ |
55
|
|
|
private $stockItem; |
56
|
|
|
|
57
|
|
|
public function __construct( |
58
|
|
|
int $documentId, |
59
|
|
|
Details $details, |
60
|
|
|
Stock $stock, |
61
|
|
|
Category $category, |
62
|
|
|
MediaGallery $mediaGallery, |
63
|
|
|
?ConfigurableChildren $configurableChildren, |
64
|
|
|
?ConfigurableOptions $configurableOptions, |
65
|
|
|
ProductLinks $productLinks, |
66
|
|
|
Price $price, |
67
|
|
|
StockItem $stockItem |
68
|
|
|
) { |
69
|
|
|
$this->documentId = $documentId; |
70
|
|
|
$this->stock = $stock; |
71
|
|
|
$this->category = $category; |
72
|
|
|
$this->mediaGallery = $mediaGallery; |
73
|
|
|
$this->details = $details; |
74
|
|
|
$this->configurableChildren = $configurableChildren; |
75
|
|
|
$this->configurableOptions = $configurableOptions; |
76
|
|
|
$this->productLinks = $productLinks; |
77
|
|
|
$this->price = $price; |
78
|
|
|
$this->stockItem = $stockItem; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function getDocumentId(): int |
82
|
|
|
{ |
83
|
|
|
return $this->documentId; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function toElasticArray(): array |
87
|
|
|
{ |
88
|
|
|
return \array_merge( |
89
|
|
|
[ |
90
|
|
|
self::STOCK => $this->stock, |
91
|
|
|
self::STOCK_ITEM => $this->stockItem, |
92
|
|
|
], |
93
|
|
|
$this->details->toArray(), |
94
|
|
|
$this->category->toArray(), |
95
|
|
|
$this->mediaGallery->toArray(), |
96
|
|
|
$this->details->isConfigurableProduct() ? $this->configurableChildren->toArray() : [], |
97
|
|
|
$this->details->isConfigurableProduct() ? $this->configurableOptions->toArray() : [], |
98
|
|
|
$this->productLinks->toArray(), |
99
|
|
|
$this->price->toArray() |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|