|
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\ConfigurableChildren; |
|
16
|
|
|
use BitBag\SyliusVueStorefrontPlugin\Document\Product\ConfigurableChildren\Child; |
|
17
|
|
|
use Doctrine\Common\Collections\Collection; |
|
18
|
|
|
use Sylius\Component\Core\Model\ProductVariantInterface; |
|
19
|
|
|
|
|
20
|
|
|
final class ProductVariantsToConfigurableChildrenTransformer implements ProductVariantsToConfigurableChildrenTransformerInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** @var ProductVariantPricesTransformerInterface */ |
|
23
|
|
|
private $productVariantPricesTransformer; |
|
24
|
|
|
|
|
25
|
|
|
/** @var ProductVariantOptionValuesToCustomAttributesTransformerInterface */ |
|
26
|
|
|
private $productVariantOptionValuesToCustomAttributesTransformer; |
|
27
|
|
|
|
|
28
|
|
|
public function __construct( |
|
29
|
|
|
ProductVariantPricesTransformerInterface $productVariantPricesTransformer, |
|
30
|
|
|
ProductVariantOptionValuesToCustomAttributesTransformerInterface $productVariantOptionValuesToCustomAttributesTransformer |
|
31
|
|
|
) { |
|
32
|
|
|
$this->productVariantPricesTransformer = $productVariantPricesTransformer; |
|
33
|
|
|
$this->productVariantOptionValuesToCustomAttributesTransformer = $productVariantOptionValuesToCustomAttributesTransformer; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** @param Collection|ProductVariantInterface[] $syliusProductVariants */ |
|
37
|
|
|
public function transform(Collection $syliusProductVariants): ConfigurableChildren |
|
38
|
|
|
{ |
|
39
|
|
|
$configurableChildren = []; |
|
40
|
|
|
|
|
41
|
|
|
foreach ($syliusProductVariants as $productVariant) { |
|
42
|
|
|
$configurableChildren[] = new Child( |
|
43
|
|
|
$this->productVariantPricesTransformer->transform($productVariant), |
|
44
|
|
|
$productVariant->getName(), |
|
45
|
|
|
$productVariant->getCode(), |
|
46
|
|
|
$this->productVariantOptionValuesToCustomAttributesTransformer->transform($productVariant) |
|
47
|
|
|
); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
return new ConfigurableChildren($configurableChildren); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|