|
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.shop and write us |
|
8
|
|
|
* an email on [email protected]. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
declare(strict_types=1); |
|
12
|
|
|
|
|
13
|
|
|
namespace BitBag\SyliusCmsPlugin\Importer; |
|
14
|
|
|
|
|
15
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
|
16
|
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface; |
|
17
|
|
|
|
|
18
|
|
|
abstract class AbstractImporter implements ImporterInterface |
|
19
|
|
|
{ |
|
20
|
|
|
public function cleanup(): void |
|
21
|
|
|
{ |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
protected function getColumnValue(string $column, array $row) |
|
25
|
|
|
{ |
|
26
|
|
|
if (array_key_exists($column, $row)) { |
|
27
|
|
|
return $row[$column]; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
return null; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function getTranslatableColumnValue(string $column, $locale, array $row) |
|
34
|
|
|
{ |
|
35
|
|
|
$column = str_replace('__locale__', '_' . $locale, $column); |
|
36
|
|
|
|
|
37
|
|
|
if (array_key_exists($column, $row)) { |
|
38
|
|
|
return $row[$column]; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
return null; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function getAvailableLocales(array $translatableColumns, array $columns): array |
|
45
|
|
|
{ |
|
46
|
|
|
$locales = []; |
|
47
|
|
|
|
|
48
|
|
|
foreach ($translatableColumns as $translatableColumn) { |
|
49
|
|
|
$translatableColumn = str_replace('__locale__', '_', $translatableColumn); |
|
50
|
|
|
|
|
51
|
|
|
foreach ($columns as $column) { |
|
52
|
|
|
if (0 === strpos($column, $translatableColumn)) { |
|
53
|
|
|
$locales[] = str_replace($translatableColumn, '', $column); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
return array_unique($locales); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
protected function validateResource(ResourceInterface $resource, ValidatorInterface $validator, array $groups): void |
|
62
|
|
|
{ |
|
63
|
|
|
$validator->validate($resource, null, $groups); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|