|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Sylius\Bundle\ProductBundle\DependencyInjection; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Bundle\ProductBundle\Controller\VariantController; |
|
15
|
|
|
use Sylius\Bundle\ProductBundle\Form\Type\VariantType; |
|
16
|
|
|
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension; |
|
17
|
|
|
use Sylius\Component\Product\Factory\ProductVariantFactory; |
|
18
|
|
|
use Sylius\Component\Product\Model\Attribute; |
|
19
|
|
|
use Sylius\Component\Product\Model\AttributeInterface; |
|
20
|
|
|
use Sylius\Component\Product\Model\AttributeTranslation; |
|
21
|
|
|
use Sylius\Component\Product\Model\AttributeTranslationInterface; |
|
22
|
|
|
use Sylius\Component\Product\Model\AttributeValue; |
|
23
|
|
|
use Sylius\Component\Product\Model\AttributeValueInterface; |
|
24
|
|
|
use Sylius\Component\Product\Model\Option; |
|
25
|
|
|
use Sylius\Component\Product\Model\OptionInterface; |
|
26
|
|
|
use Sylius\Component\Product\Model\OptionTranslation; |
|
27
|
|
|
use Sylius\Component\Product\Model\OptionTranslationInterface; |
|
28
|
|
|
use Sylius\Component\Product\Model\OptionValue; |
|
29
|
|
|
use Sylius\Component\Product\Model\OptionValueInterface; |
|
30
|
|
|
use Sylius\Component\Product\Model\OptionValueTranslation; |
|
31
|
|
|
use Sylius\Component\Product\Model\OptionValueTranslationInterface; |
|
32
|
|
|
use Sylius\Component\Product\Model\Variant; |
|
33
|
|
|
use Sylius\Component\Product\Model\VariantInterface; |
|
34
|
|
|
use Sylius\Component\Resource\Factory; |
|
35
|
|
|
use Symfony\Component\Config\FileLocator; |
|
36
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
37
|
|
|
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface; |
|
38
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Product catalog extension. |
|
42
|
|
|
* |
|
43
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
|
44
|
|
|
*/ |
|
45
|
|
|
class SyliusProductExtension extends AbstractResourceExtension implements PrependExtensionInterface |
|
46
|
|
|
{ |
|
47
|
|
|
/** |
|
48
|
|
|
* {@inheritdoc} |
|
49
|
|
|
*/ |
|
50
|
|
|
public function load(array $config, ContainerBuilder $container) |
|
51
|
|
|
{ |
|
52
|
|
|
$config = $this->processConfiguration(new Configuration(), $config); |
|
53
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
|
54
|
|
|
|
|
55
|
|
|
$this->registerResources('sylius', $config['driver'], $config['resources'], $container); |
|
56
|
|
|
|
|
57
|
|
|
$configFiles = [ |
|
58
|
|
|
'services.xml', |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
foreach ($configFiles as $configFile) { |
|
62
|
|
|
$loader->load($configFile); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* {@inheritdoc} |
|
68
|
|
|
*/ |
|
69
|
|
|
public function prepend(ContainerBuilder $container) |
|
70
|
|
|
{ |
|
71
|
|
|
$config = $this->processConfiguration(new Configuration(), $container->getExtensionConfig($this->getAlias())); |
|
72
|
|
|
|
|
73
|
|
|
$this->prependAttribute($container, $config); |
|
74
|
|
|
$this->prependVariation($container, $config); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* @param ContainerBuilder $container |
|
79
|
|
|
* @param array $config |
|
80
|
|
|
*/ |
|
81
|
|
|
private function prependAttribute(ContainerBuilder $container, array $config) |
|
82
|
|
|
{ |
|
83
|
|
|
if (!$container->hasExtension('sylius_attribute')) { |
|
84
|
|
|
return; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
$container->prependExtensionConfig('sylius_attribute', [ |
|
88
|
|
|
'resources' => [ |
|
89
|
|
|
'product' => [ |
|
90
|
|
|
'subject' => $config['resources']['product']['classes']['model'], |
|
91
|
|
|
'attribute' => [ |
|
92
|
|
|
'classes' => [ |
|
93
|
|
|
'model' => Attribute::class, |
|
94
|
|
|
'interface' => AttributeInterface::class, |
|
95
|
|
|
], |
|
96
|
|
|
'translation' => [ |
|
97
|
|
|
'classes' => [ |
|
98
|
|
|
'model' => AttributeTranslation::class, |
|
99
|
|
|
'interface' => AttributeTranslationInterface::class, |
|
100
|
|
|
], |
|
101
|
|
|
], |
|
102
|
|
|
], |
|
103
|
|
|
'attribute_value' => [ |
|
104
|
|
|
'classes' => [ |
|
105
|
|
|
'model' => AttributeValue::class, |
|
106
|
|
|
'interface' => AttributeValueInterface::class, |
|
107
|
|
|
], |
|
108
|
|
|
], |
|
109
|
|
|
], |
|
110
|
|
|
], ] |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param ContainerBuilder $container |
|
116
|
|
|
* @param array $config |
|
117
|
|
|
*/ |
|
118
|
|
|
private function prependVariation(ContainerBuilder $container, array $config) |
|
119
|
|
|
{ |
|
120
|
|
|
if (!$container->hasExtension('sylius_variation')) { |
|
121
|
|
|
return; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
$container->prependExtensionConfig('sylius_variation', [ |
|
125
|
|
|
'resources' => [ |
|
126
|
|
|
'product' => [ |
|
127
|
|
|
'variable' => $config['resources']['product']['classes']['model'], |
|
128
|
|
|
'variant' => [ |
|
129
|
|
|
'classes' => [ |
|
130
|
|
|
'model' => Variant::class, |
|
131
|
|
|
'interface' => VariantInterface::class, |
|
132
|
|
|
'controller' => VariantController::class, |
|
133
|
|
|
'factory' => ProductVariantFactory::class, |
|
134
|
|
|
'form' => [ |
|
135
|
|
|
'default' => VariantType::class, |
|
136
|
|
|
], |
|
137
|
|
|
], |
|
138
|
|
|
], |
|
139
|
|
|
'option' => [ |
|
140
|
|
|
'classes' => [ |
|
141
|
|
|
'model' => Option::class, |
|
142
|
|
|
'interface' => OptionInterface::class, |
|
143
|
|
|
], |
|
144
|
|
|
'translation' => [ |
|
145
|
|
|
'classes' => [ |
|
146
|
|
|
'model' => OptionTranslation::class, |
|
147
|
|
|
'interface' => OptionTranslationInterface::class, |
|
148
|
|
|
], |
|
149
|
|
|
], |
|
150
|
|
|
], |
|
151
|
|
|
'option_value' => [ |
|
152
|
|
|
'classes' => [ |
|
153
|
|
|
'model' => OptionValue::class, |
|
154
|
|
|
'interface' => OptionValueInterface::class, |
|
155
|
|
|
], |
|
156
|
|
|
'translation' => [ |
|
157
|
|
|
'classes' => [ |
|
158
|
|
|
'model' => OptionValueTranslation::class, |
|
159
|
|
|
'interface' => OptionValueTranslationInterface::class, |
|
160
|
|
|
], |
|
161
|
|
|
], |
|
162
|
|
|
], |
|
163
|
|
|
], |
|
164
|
|
|
], |
|
165
|
|
|
]); |
|
166
|
|
|
} |
|
167
|
|
|
} |
|
168
|
|
|
|