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\Sylius\Transformer\SyliusProduct; |
14
|
|
|
|
15
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\Details; |
16
|
|
|
use Sylius\Component\Core\Model\ProductInterface; |
17
|
|
|
|
18
|
|
|
final class ProductDetailsTransformer implements ProductDetailsTransformerInterface |
19
|
|
|
{ |
20
|
|
|
public function transform(ProductInterface $product): Details |
21
|
|
|
{ |
22
|
|
|
$productVariantsCount = $product->getVariants()->count(); |
23
|
|
|
|
24
|
|
|
return new Details( |
25
|
|
|
$product->getId(), |
26
|
|
|
null, |
27
|
|
|
null, |
28
|
|
|
$productVariantsCount > 1 ? 'configurable' : 'simple', |
29
|
|
|
$productVariantsCount === 1 ? $product->getVariants()->first()->getCode() : $product->getCode(), |
30
|
|
|
$product->getSlug(), |
31
|
|
|
$product->getName(), |
32
|
|
|
null, |
33
|
|
|
null, |
34
|
|
|
$product->getCreatedAt(), |
35
|
|
|
$product->getUpdatedAt(), |
36
|
|
|
$product->getImages()->first() ? $product->getImages()->first()->getPath() : null, |
37
|
|
|
($product->getVariants()->first()->getOnHand() - $product->getVariants()->first()->getOnHold()) > 0, |
38
|
|
|
null, |
39
|
|
|
$product->getVariants()->first()->getTaxCategory() !== null ? $product->getVariants()->first()->getTaxCategory()->getId() : null, |
40
|
|
|
$product->getVariants()->first()->getTaxCategory() !== null ? $product->getVariants()->first()->getTaxCategory()->getName() : null, |
41
|
|
|
$product->getDescription(), |
42
|
|
|
$product->getShortDescription(), |
43
|
|
|
1,//hasOptions |
44
|
|
|
1,//requiredOptions |
45
|
|
|
[],//productLinks |
46
|
|
|
[],//colorOptions, |
47
|
|
|
[],//sizeOptions |
48
|
|
|
$productVariantsCount === 1 ? $product->getVariants()->first()->getCode() : $product->getCode() |
49
|
|
|
); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|