|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) shopware AG <[email protected]> |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace ShopwarePlugins\Connect\Subscribers; |
|
9
|
|
|
|
|
10
|
|
|
use Enlight\Event\SubscriberInterface; |
|
11
|
|
|
use Shopware\Components\Model\ModelManager; |
|
12
|
|
|
use Shopware\Connect\Gateway\PDO; |
|
13
|
|
|
use Shopware\CustomModels\Connect\Attribute; |
|
14
|
|
|
use Shopware\CustomModels\Connect\PaymentRepository; |
|
15
|
|
|
use Shopware\CustomModels\Connect\ProductToRemoteCategory; |
|
16
|
|
|
use Shopware\CustomModels\Connect\RemoteCategory; |
|
17
|
|
|
use ShopwarePlugins\Connect\Components\Api\Request\RestApiRequest; |
|
18
|
|
|
use ShopwarePlugins\Connect\Components\CategoryExtractor; |
|
19
|
|
|
use ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver; |
|
20
|
|
|
use ShopwarePlugins\Connect\Components\Config; |
|
21
|
|
|
use ShopwarePlugins\Connect\Components\CategoryResolver\DefaultCategoryResolver; |
|
22
|
|
|
use ShopwarePlugins\Connect\Components\ConfigFactory; |
|
23
|
|
|
use ShopwarePlugins\Connect\Components\ConnectExport; |
|
24
|
|
|
use ShopwarePlugins\Connect\Components\ConnectFactory; |
|
25
|
|
|
use ShopwarePlugins\Connect\Components\ErrorHandler; |
|
26
|
|
|
use ShopwarePlugins\Connect\Components\FrontendQuery\FrontendQuery; |
|
27
|
|
|
use ShopwarePlugins\Connect\Components\ImportService; |
|
28
|
|
|
use ShopwarePlugins\Connect\Components\ProductStream\ProductSearch; |
|
29
|
|
|
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamRepository; |
|
30
|
|
|
use ShopwarePlugins\Connect\Components\ProductStream\ProductStreamService; |
|
31
|
|
|
use Shopware\CustomModels\Connect\ProductStreamAttributeRepository; |
|
32
|
|
|
use ShopwarePlugins\Connect\Components\RandomStringGenerator; |
|
33
|
|
|
use ShopwarePlugins\Connect\Components\Validator\ProductAttributesValidator\ProductsAttributesValidator; |
|
34
|
|
|
use ShopwarePlugins\Connect\Services\ExportAssignmentService; |
|
35
|
|
|
use ShopwarePlugins\Connect\Services\MenuService; |
|
36
|
|
|
use ShopwarePlugins\Connect\Services\PaymentService; |
|
37
|
|
|
use Shopware\Components\DependencyInjection\Container; |
|
38
|
|
|
use Shopware\Models\Category\Category as CategoryModel; |
|
39
|
|
|
use Shopware\Models\Article\Article as ArticleModel; |
|
40
|
|
|
use Shopware\CustomModels\Connect\Attribute as ConnectAttribute; |
|
41
|
|
|
use Enlight_Components_Db_Adapter_Pdo_Mysql; |
|
42
|
|
|
use Shopware\CustomModels\Connect\ProductStreamAttribute; |
|
43
|
|
|
use ShopwarePlugins\Connect\Services\RemoteShopService; |
|
44
|
|
|
use Shopware\Connect\SDK; |
|
45
|
|
|
|
|
46
|
|
|
class ServiceContainer implements SubscriberInterface |
|
47
|
|
|
{ |
|
48
|
|
|
/** |
|
49
|
|
|
* @var ModelManager |
|
50
|
|
|
*/ |
|
51
|
|
|
private $manager; |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @var Enlight_Components_Db_Adapter_Pdo_Mysql |
|
55
|
|
|
*/ |
|
56
|
|
|
private $db; |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @var Container |
|
60
|
|
|
*/ |
|
61
|
|
|
private $container; |
|
62
|
|
|
|
|
63
|
|
|
/** @var Config */ |
|
64
|
|
|
private $config; |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @var SDK |
|
68
|
|
|
*/ |
|
69
|
|
|
private $sdk; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* ServiceContainer constructor. |
|
73
|
|
|
* @param ModelManager $manager |
|
74
|
|
|
* @param Enlight_Components_Db_Adapter_Pdo_Mysql $db |
|
75
|
|
|
* @param Container $container |
|
76
|
|
|
* @param Config $config |
|
77
|
|
|
*/ |
|
78
|
|
|
public function __construct( |
|
79
|
|
|
ModelManager $manager, |
|
80
|
|
|
Enlight_Components_Db_Adapter_Pdo_Mysql $db, |
|
81
|
|
|
Container $container, |
|
82
|
|
|
Config $config, |
|
83
|
|
|
SDK $sdk |
|
84
|
|
|
) { |
|
85
|
|
|
$this->manager = $manager; |
|
86
|
|
|
$this->db = $db; |
|
87
|
|
|
$this->container = $container; |
|
88
|
|
|
$this->config = $config; |
|
89
|
|
|
$this->sdk = $sdk; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritdoc} |
|
94
|
|
|
*/ |
|
95
|
|
|
public static function getSubscribedEvents() |
|
96
|
|
|
{ |
|
97
|
|
|
return [ |
|
98
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.product_stream_service' => 'onProductStreamService', |
|
99
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.product_search' => 'onProductSearch', |
|
100
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.payment_service' => 'onPaymentService', |
|
101
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.menu_service' => 'onMenuService', |
|
102
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.frontend_query' => 'onCreateFrontendQuery', |
|
103
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.rest_api_request' => 'onRestApiRequest', |
|
104
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.import_service' => 'onImportService', |
|
105
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.auto_category_reverter' => 'onAutoCategoryReverter', |
|
106
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.auto_category_resolver' => 'onAutoCategoryResolver', |
|
107
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.default_category_resolver' => 'onDefaultCategoryResolver', |
|
108
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.export_assignment_service' => 'onExportAssignmentService', |
|
109
|
|
|
'Enlight_Bootstrap_InitResource_swagconnect.remote_shop_service' => 'onRemoteShopService' |
|
110
|
|
|
]; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* @return ProductStreamService |
|
115
|
|
|
*/ |
|
116
|
|
|
public function onProductStreamService() |
|
117
|
|
|
{ |
|
118
|
|
|
/** @var ProductStreamAttributeRepository $streamAttrRepository */ |
|
119
|
|
|
$streamAttrRepository = $this->manager->getRepository(ProductStreamAttribute::class); |
|
120
|
|
|
|
|
121
|
|
|
return new ProductStreamService( |
|
122
|
|
|
new ProductStreamRepository($this->manager, $this->container->get('shopware_product_stream.repository')), |
|
123
|
|
|
$streamAttrRepository, |
|
124
|
|
|
$this->config |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* @return ProductSearch |
|
130
|
|
|
*/ |
|
131
|
|
|
public function onProductSearch() |
|
132
|
|
|
{ |
|
133
|
|
|
return new ProductSearch( |
|
134
|
|
|
$this->container->get('shopware_product_stream.repository'), |
|
135
|
|
|
$this->config, |
|
136
|
|
|
$this->container->get('shopware_search.product_search'), |
|
137
|
|
|
$this->container->get('shopware_storefront.context_service') |
|
138
|
|
|
); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return MenuService |
|
143
|
|
|
*/ |
|
144
|
|
|
public function onMenuService() |
|
145
|
|
|
{ |
|
146
|
|
|
return new MenuService( |
|
147
|
|
|
$this->container->get('shopware_plugininstaller.plugin_manager'), |
|
148
|
|
|
$this->manager |
|
149
|
|
|
); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* @return PaymentService |
|
154
|
|
|
*/ |
|
155
|
|
|
public function onPaymentService() |
|
156
|
|
|
{ |
|
157
|
|
|
return new PaymentService( |
|
158
|
|
|
$this->manager->getRepository('Shopware\Models\Payment\Payment'), |
|
159
|
|
|
new PaymentRepository($this->manager) |
|
160
|
|
|
); |
|
161
|
|
|
} |
|
162
|
|
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @return FrontendQuery |
|
165
|
|
|
*/ |
|
166
|
|
|
public function onCreateFrontendQuery() |
|
167
|
|
|
{ |
|
168
|
|
|
return new FrontendQuery($this->manager); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* @return RestApiRequest |
|
173
|
|
|
*/ |
|
174
|
|
|
public function onRestApiRequest() |
|
175
|
|
|
{ |
|
176
|
|
|
return new RestApiRequest($this->config); |
|
177
|
|
|
} |
|
178
|
|
|
|
|
179
|
|
|
/** |
|
180
|
|
|
* @return \ShopwarePlugins\Connect\Components\ImportService |
|
181
|
|
|
*/ |
|
182
|
|
|
public function onImportService() |
|
183
|
|
|
{ |
|
184
|
|
|
return new ImportService( |
|
185
|
|
|
$this->manager, |
|
186
|
|
|
$this->container->get('multi_edit.product'), |
|
187
|
|
|
$this->manager->getRepository(CategoryModel::class), |
|
188
|
|
|
$this->manager->getRepository(ArticleModel::class), |
|
189
|
|
|
$this->manager->getRepository(RemoteCategory::class), |
|
190
|
|
|
$this->manager->getRepository(ProductToRemoteCategory::class), |
|
191
|
|
|
$this->container->get('swagconnect.auto_category_resolver'), |
|
192
|
|
|
new CategoryExtractor( |
|
193
|
|
|
$this->manager->getRepository(ConnectAttribute::class), |
|
194
|
|
|
$this->container->get('swagconnect.auto_category_resolver'), |
|
195
|
|
|
new PDO($this->db->getConnection()), |
|
196
|
|
|
new RandomStringGenerator(), |
|
197
|
|
|
$this->db |
|
198
|
|
|
), |
|
199
|
|
|
$this->container->get('CategoryDenormalization'), |
|
200
|
|
|
$this->container->get('shopware_attribute.data_persister') |
|
201
|
|
|
); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return \ShopwarePlugins\Connect\Components\AutoCategoryReverter |
|
206
|
|
|
*/ |
|
207
|
|
|
public function onAutoCategoryReverter() |
|
208
|
|
|
{ |
|
209
|
|
|
return new \ShopwarePlugins\Connect\Components\AutoCategoryReverter( |
|
210
|
|
|
$this->container->get('swagconnect.import_service') |
|
211
|
|
|
); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
/** |
|
215
|
|
|
* @return \ShopwarePlugins\Connect\Components\CategoryResolver\AutoCategoryResolver |
|
216
|
|
|
*/ |
|
217
|
|
View Code Duplication |
public function onAutoCategoryResolver() |
|
|
|
|
|
|
218
|
|
|
{ |
|
219
|
|
|
return new AutoCategoryResolver( |
|
220
|
|
|
$this->manager, |
|
221
|
|
|
$this->manager->getRepository(CategoryModel::class), |
|
222
|
|
|
$this->manager->getRepository(RemoteCategory::class), |
|
223
|
|
|
$this->config, |
|
224
|
|
|
$this->container->get('CategoryDenormalization'), |
|
225
|
|
|
$this->manager->getRepository(ProductToRemoteCategory::class) |
|
226
|
|
|
); |
|
227
|
|
|
} |
|
228
|
|
|
|
|
229
|
|
|
/** |
|
230
|
|
|
* @return ExportAssignmentService |
|
231
|
|
|
*/ |
|
232
|
|
|
public function onExportAssignmentService() |
|
233
|
|
|
{ |
|
234
|
|
|
$connectFactory = new ConnectFactory(); |
|
235
|
|
|
|
|
236
|
|
|
return new ExportAssignmentService( |
|
237
|
|
|
$this->manager->getRepository(Attribute::class), |
|
238
|
|
|
new ConnectExport( |
|
239
|
|
|
$connectFactory->getHelper(), |
|
240
|
|
|
$connectFactory->getSDK(), |
|
241
|
|
|
$this->manager, |
|
242
|
|
|
new ProductsAttributesValidator(), |
|
243
|
|
|
ConfigFactory::getConfigInstance(), |
|
244
|
|
|
new ErrorHandler(), |
|
245
|
|
|
$this->container->get('events') |
|
246
|
|
|
) |
|
247
|
|
|
); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
/** |
|
251
|
|
|
* @return \ShopwarePlugins\Connect\Components\CategoryResolver\DefaultCategoryResolver |
|
252
|
|
|
*/ |
|
253
|
|
View Code Duplication |
public function onDefaultCategoryResolver() |
|
|
|
|
|
|
254
|
|
|
{ |
|
255
|
|
|
return new DefaultCategoryResolver( |
|
256
|
|
|
$this->manager, |
|
257
|
|
|
$this->manager->getRepository(RemoteCategory::class), |
|
258
|
|
|
$this->manager->getRepository(ProductToRemoteCategory::class), |
|
259
|
|
|
$this->manager->getRepository(CategoryModel::class), |
|
260
|
|
|
$this->container->get('CategoryDenormalization') |
|
261
|
|
|
); |
|
262
|
|
|
} |
|
263
|
|
|
|
|
264
|
|
|
/** |
|
265
|
|
|
* @return RemoteShopService |
|
266
|
|
|
*/ |
|
267
|
|
|
public function onRemoteShopService() |
|
268
|
|
|
{ |
|
269
|
|
|
return new RemoteShopService( |
|
270
|
|
|
$this->sdk |
|
271
|
|
|
); |
|
272
|
|
|
} |
|
273
|
|
|
} |
|
274
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.