|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Loaders\EavAttributeOptionValueLoader |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Loaders; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
|
24
|
|
|
use TechDivision\Import\Services\ImportProcessorInterface; |
|
25
|
|
|
use TechDivision\Import\Configuration\SubjectConfigurationInterface; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Loader for available option values. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
View Code Duplication |
class EavAttributeOptionValueLoader implements LoaderInterface |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* The attribute option values. |
|
41
|
|
|
* |
|
42
|
|
|
* @var array |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $eavAttributeOptionValues = array(); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Construct that initializes the iterator with the import processor instance. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \TechDivision\Import\Services\ImportProcessorInterface $importProcessor The import processor instance |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __construct(ImportProcessorInterface $importProcessor) |
|
52
|
|
|
{ |
|
53
|
|
|
|
|
54
|
|
|
// load the entity types |
|
55
|
|
|
$entityTypes = $importProcessor->getEavEntityTypes(); |
|
56
|
|
|
|
|
57
|
|
|
// prepare the array with the attribute sets |
|
58
|
|
|
foreach ($entityTypes as $entityType) { |
|
59
|
|
|
// prepare the array with the attribute sets |
|
60
|
|
|
foreach ($importProcessor->getEavAttributeOptionValuesByEntityTypeIdAndStoreId($entityType[MemberNames::ENTITY_TYPE_ID], 0) as $eavAttributeOptionValue) { |
|
61
|
|
|
$this->eavAttributeOptionValues[$entityType[MemberNames::ENTITY_TYPE_CODE]][$eavAttributeOptionValue[MemberNames::ATTRIBUTE_CODE]][] = $eavAttributeOptionValue[MemberNames::VALUE]; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Loads and returns data the custom validation data. |
|
68
|
|
|
* |
|
69
|
|
|
* @param \TechDivision\Import\Configuration\ParamsConfigurationInterface $configuration The configuration instance to load the validations from |
|
70
|
|
|
* |
|
71
|
|
|
* @return \ArrayAccess The array with the data |
|
72
|
|
|
*/ |
|
73
|
|
|
public function load(SubjectConfigurationInterface $configuration = null) |
|
74
|
|
|
{ |
|
75
|
|
|
|
|
76
|
|
|
// load the entity type code from the passed subject configuration |
|
77
|
|
|
$entityTypeCode = $configuration->getExecutionContext()->getEntityTypeCode(); |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
// return the available attribute option values for the entity type |
|
80
|
|
|
if (isset($this->eavAttributeOptionValues[$entityTypeCode])) { |
|
81
|
|
|
return $this->eavAttributeOptionValues[$entityTypeCode]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
// return an empty array otherwise |
|
85
|
|
|
return array(); |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Return's the import processor instance. |
|
90
|
|
|
* |
|
91
|
|
|
* @return \TechDivision\Import\Services\ImportProcessorInterface The processor instance |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getImportProcessor() |
|
94
|
|
|
{ |
|
95
|
|
|
return $this->importProcessor; |
|
|
|
|
|
|
96
|
|
|
} |
|
97
|
|
|
} |
|
98
|
|
|
|
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.