1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\Econda\Business; |
9
|
|
|
|
10
|
|
|
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderDependencyContainer; |
11
|
|
|
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactory; |
12
|
|
|
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactoryWorker; |
13
|
|
|
use Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface; |
14
|
|
|
use Spryker\Zed\Kernel\Business\AbstractBusinessFactory; |
15
|
|
|
use Spryker\Zed\ProductCategory\Persistence\ProductCategoryQueryContainerInterface; |
16
|
|
|
use Spryker\Zed\ProductImage\Persistence\ProductImageQueryContainerInterface; |
17
|
|
|
use SprykerEco\Zed\Econda\Business\Collector\DatabaseCollectorInterface; |
18
|
|
|
use SprykerEco\Zed\Econda\Business\Collector\File\EcondaCategoryCollector; |
19
|
|
|
use SprykerEco\Zed\Econda\Business\Collector\File\EcondaProductCollector; |
20
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\ExporterInterface; |
21
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\FileExporter; |
22
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Runner; |
23
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\RunnerInterface; |
24
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\Adapter\AdapterInterface; |
25
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\Adapter\CsvAdapter; |
26
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriter; |
27
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriterInterface; |
28
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\CsvNameGenerator; |
29
|
|
|
use SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\NameGeneratorInterface; |
30
|
|
|
use SprykerEco\Zed\Econda\Business\Helper\ProgressBarHelper; |
31
|
|
|
use SprykerEco\Zed\Econda\Business\Helper\ProgressBarHelperInterface; |
32
|
|
|
use SprykerEco\Zed\Econda\Business\Manager\CollectorManager; |
33
|
|
|
use SprykerEco\Zed\Econda\Business\Manager\CollectorManagerInterface; |
34
|
|
|
use SprykerEco\Zed\Econda\Business\Reader\File\CsvFileReader; |
35
|
|
|
use SprykerEco\Zed\Econda\Business\Reader\File\FileReaderInterface; |
36
|
|
|
use SprykerEco\Zed\Econda\Dependency\Facade\EcondaToLocaleFacadeInterface; |
37
|
|
|
use SprykerEco\Zed\Econda\Dependency\Facade\EcondaToPriceProductFacadeInterface; |
38
|
|
|
use SprykerEco\Zed\Econda\Dependency\Facade\EcondaToPropelFacadeBridge; |
39
|
|
|
use SprykerEco\Zed\Econda\EcondaDependencyProvider; |
40
|
|
|
use SprykerEco\Zed\Econda\Persistence\Econda\AbstractEcondaPdoQuery; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @method \SprykerEco\Zed\Econda\EcondaConfig getConfig() |
44
|
|
|
* @method \SprykerEco\Zed\Econda\Persistence\EcondaQueryContainerInterface getQueryContainer() |
45
|
|
|
*/ |
46
|
|
|
class EcondaBusinessFactory extends AbstractBusinessFactory |
47
|
|
|
{ |
48
|
|
|
protected const CATEGORY_NODE_ECONDA_QUERY = 'CategoryNodeEcondaQuery'; |
49
|
|
|
protected const CRITERIA_BUILDER_FACTORY_WORKER = 'CriteriaBuilderFactoryWorker'; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Reader\File\FileReaderInterface |
53
|
|
|
*/ |
54
|
|
|
public function createEcondaCsvFileReader(): FileReaderInterface |
55
|
|
|
{ |
56
|
|
|
$nameGenerator = $this->createCsvNameGenerator(); |
57
|
|
|
|
58
|
|
|
return new CsvFileReader($this->getConfig(), $nameGenerator); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Exporter\RunnerInterface |
63
|
|
|
*/ |
64
|
|
|
public function createRunner(): RunnerInterface |
65
|
|
|
{ |
66
|
|
|
return new Runner( |
67
|
|
|
$this->getLocaleFacade(), |
68
|
|
|
$this->createFileExporter() |
69
|
|
|
); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Manager\CollectorManagerInterface |
74
|
|
|
*/ |
75
|
|
|
public function createCategoryCollectorManager(): CollectorManagerInterface |
76
|
|
|
{ |
77
|
|
|
return new CollectorManager( |
78
|
|
|
$this->createCriteriaBuilder(), |
79
|
|
|
$this->getQueryContainer(), |
80
|
|
|
$this->createProgressBarHelper(), |
81
|
|
|
$this->createEcondaCategoryCollector() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Manager\CollectorManagerInterface |
87
|
|
|
*/ |
88
|
|
|
public function createProductCollectorManager(): CollectorManagerInterface |
89
|
|
|
{ |
90
|
|
|
return new CollectorManager( |
91
|
|
|
$this->createCriteriaBuilder(), |
92
|
|
|
$this->getQueryContainer(), |
93
|
|
|
$this->createProgressBarHelper(), |
94
|
|
|
$this->createEcondaProductCollector() |
95
|
|
|
); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\FileWriterInterface |
100
|
|
|
*/ |
101
|
|
|
protected function createFileWriter(): FileWriterInterface |
102
|
|
|
{ |
103
|
|
|
$csvFileWriterAdapter = $this->createCsvFileWriterAdapter(); |
104
|
|
|
|
105
|
|
|
return new FileWriter($csvFileWriterAdapter); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Helper\ProgressBarHelperInterface |
110
|
|
|
*/ |
111
|
|
|
protected function createProgressBarHelper(): ProgressBarHelperInterface |
112
|
|
|
{ |
113
|
|
|
return new ProgressBarHelper(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\NameGenerator\NameGeneratorInterface |
118
|
|
|
*/ |
119
|
|
|
protected function createCsvNameGenerator(): NameGeneratorInterface |
120
|
|
|
{ |
121
|
|
|
return new CsvNameGenerator(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Collector\DatabaseCollectorInterface |
126
|
|
|
*/ |
127
|
|
|
public function createEcondaCategoryCollector(): DatabaseCollectorInterface |
128
|
|
|
{ |
129
|
|
|
return new EcondaCategoryCollector( |
130
|
|
|
$this->createCriteriaBuilder(), |
131
|
|
|
$this->createEcondaPdoQuery(static::CATEGORY_NODE_ECONDA_QUERY) |
132
|
|
|
); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Collector\DatabaseCollectorInterface |
137
|
|
|
*/ |
138
|
|
|
public function createEcondaProductCollector(): DatabaseCollectorInterface |
139
|
|
|
{ |
140
|
|
|
return new EcondaProductCollector( |
141
|
|
|
$this->createCriteriaBuilder(), |
142
|
|
|
$this->createEcondaPdoQuery('ProductConcreteEcondaQuery'), |
143
|
|
|
$this->getProductCategoryQueryContainer(), |
144
|
|
|
$this->getProductImageQueryContainer(), |
145
|
|
|
$this->getPriceProductFacade(), |
146
|
|
|
$this->getConfig() |
147
|
|
|
); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Exporter\ExporterInterface |
152
|
|
|
*/ |
153
|
|
|
protected function createFileExporter(): ExporterInterface |
154
|
|
|
{ |
155
|
|
|
return new FileExporter( |
156
|
|
|
$this->createFileWriter(), |
157
|
|
|
$this->createCsvNameGenerator(), |
158
|
|
|
$this->getConfig()->getFileExportPath(), |
159
|
|
|
$this->getCollectorFileExporterPlugins() |
160
|
|
|
); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* @return \SprykerEco\Zed\Econda\Dependency\Plugin\ExporterPluginInterface[] |
165
|
|
|
*/ |
166
|
|
|
protected function getCollectorFileExporterPlugins(): array |
167
|
|
|
{ |
168
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::FILE_PLUGINS); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* @return \SprykerEco\Zed\Econda\Dependency\Facade\EcondaToLocaleFacadeInterface |
173
|
|
|
*/ |
174
|
|
|
protected function getLocaleFacade(): EcondaToLocaleFacadeInterface |
175
|
|
|
{ |
176
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_LOCALE); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @return \SprykerEco\Zed\Econda\Business\Exporter\Writer\File\Adapter\AdapterInterface |
181
|
|
|
*/ |
182
|
|
|
protected function createCsvFileWriterAdapter(): AdapterInterface |
183
|
|
|
{ |
184
|
|
|
return new CsvAdapter( |
185
|
|
|
$this->getConfig()->getFileExportPath(), |
186
|
|
|
$this->getConfig()->getCsvDelimiter() |
187
|
|
|
); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* @return \Spryker\Zed\ProductImage\Persistence\ProductImageQueryContainerInterface |
192
|
|
|
*/ |
193
|
|
|
protected function getProductImageQueryContainer(): ProductImageQueryContainerInterface |
194
|
|
|
{ |
195
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::QUERY_CONTAINER_PRODUCT_IMAGE); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $econdaPdoQueryName |
200
|
|
|
* |
201
|
|
|
* @return \SprykerEco\Zed\Econda\Persistence\Econda\AbstractEcondaPdoQuery |
202
|
|
|
*/ |
203
|
|
|
protected function createEcondaPdoQuery($econdaPdoQueryName): AbstractEcondaPdoQuery |
204
|
|
|
{ |
205
|
|
|
$econdaPdoQuery = $this->getConfig()->getEcondaPdoQueryClassName( |
206
|
|
|
$this->getPropelFacade()->getCurrentDatabaseEngineName(), |
207
|
|
|
$econdaPdoQueryName |
208
|
|
|
); |
209
|
|
|
|
210
|
|
|
return new $econdaPdoQuery(); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @return \SprykerEco\Zed\Econda\Dependency\Facade\EcondaToPropelFacadeBridge |
215
|
|
|
*/ |
216
|
|
|
protected function getPropelFacade(): EcondaToPropelFacadeBridge |
217
|
|
|
{ |
218
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_PROPEL); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return \SprykerEco\Zed\Econda\Dependency\Facade\EcondaToPriceProductFacadeInterface |
223
|
|
|
*/ |
224
|
|
|
protected function getPriceProductFacade(): EcondaToPriceProductFacadeInterface |
225
|
|
|
{ |
226
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::FACADE_PRICE_PRODUCT); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface |
231
|
|
|
*/ |
232
|
|
|
protected function createCriteriaBuilder(): CriteriaBuilderInterface |
233
|
|
|
{ |
234
|
|
|
$factory = new CriteriaBuilderFactory( |
235
|
|
|
$this->createCriteriaBuilderContainer() |
236
|
|
|
); |
237
|
|
|
|
238
|
|
|
$factory->registerWorkerCallback(static::CRITERIA_BUILDER_FACTORY_WORKER, function () use ($factory) { |
239
|
|
|
return $factory->buildWorker(CriteriaBuilderFactoryWorker::class); |
240
|
|
|
}); |
241
|
|
|
|
242
|
|
|
/** @var \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderFactoryWorker $factoryWorker */ |
243
|
|
|
$factoryWorker = $factory->getWorkerByName(static::CRITERIA_BUILDER_FACTORY_WORKER); |
244
|
|
|
/** @var \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderInterface $criteriaBuilder */ |
245
|
|
|
$criteriaBuilder = $factoryWorker->buildCriteriaBuilder(); |
246
|
|
|
|
247
|
|
|
return $criteriaBuilder; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* @return \Spryker\Shared\SqlCriteriaBuilder\CriteriaBuilder\CriteriaBuilderDependencyContainer |
252
|
|
|
*/ |
253
|
|
|
protected function createCriteriaBuilderContainer(): CriteriaBuilderDependencyContainer |
254
|
|
|
{ |
255
|
|
|
return new CriteriaBuilderDependencyContainer(); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @return \Spryker\Zed\ProductCategory\Persistence\ProductCategoryQueryContainerInterface |
260
|
|
|
*/ |
261
|
|
|
protected function getProductCategoryQueryContainer(): ProductCategoryQueryContainerInterface |
262
|
|
|
{ |
263
|
|
|
return $this->getProvidedDependency(EcondaDependencyProvider::QUERY_CONTAINER_PRODUCT_CATEGORY); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
|