1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Callbacks\AbstractEavAwareCallback |
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\Callbacks; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\MemberNames; |
24
|
|
|
use TechDivision\Import\ConfigurationInterface; |
25
|
|
|
use TechDivision\Import\Services\EavAwareProcessorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* An abstract EAV aware callback implementation. |
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
|
|
|
abstract class AbstractEavAwareCallback extends AbstractCallback |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* The EAV aware processor. |
41
|
|
|
* |
42
|
|
|
* @var \TechDivision\Import\Services\EavAwareProcessorInterface |
43
|
|
|
*/ |
44
|
|
|
protected $eavAwareProcessor; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* The configuration instance. |
48
|
|
|
* |
49
|
|
|
* @var \TechDivision\Import\ConfigurationInterface |
50
|
|
|
*/ |
51
|
|
|
protected $configuration; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Initialize the callback with the passed processor instance. |
55
|
|
|
* |
56
|
|
|
* @param \TechDivision\Import\ConfigurationInterface $configuration The configuration instance |
57
|
|
|
* @param \TechDivision\Import\Services\EavAwareProcessorInterface $eavAwareProcessor The processor instance |
58
|
|
|
*/ |
59
|
|
|
public function __construct(ConfigurationInterface $configuration, EavAwareProcessorInterface $eavAwareProcessor) |
60
|
|
|
{ |
61
|
|
|
$this->configuration = $configuration; |
62
|
|
|
$this->eavAwareProcessor = $eavAwareProcessor; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Return's the EAV aware processor instance. |
67
|
|
|
* |
68
|
|
|
* @return \TechDivision\Import\Services\EavAwareProcessorInterface The processor instance |
69
|
|
|
*/ |
70
|
|
|
protected function getEavAwareProcessor() |
71
|
|
|
{ |
72
|
|
|
return $this->eavAwareProcessor; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Returns the configuration instance. |
77
|
|
|
* |
78
|
|
|
* @return \TechDivision\Import\ConfigurationInterface The configuration instance |
79
|
|
|
*/ |
80
|
|
|
protected function getConfiguration() |
81
|
|
|
{ |
82
|
|
|
return $this->configuration; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Returns the configured entity type code. |
87
|
|
|
* |
88
|
|
|
* @return string The entity type code from the configuration |
89
|
|
|
*/ |
90
|
|
|
protected function getEntityTypeCode() |
91
|
|
|
{ |
92
|
|
|
return $this->getConfiguration()->getEntityTypeCode(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Returns the entity type ID for the configured entity type code. |
97
|
|
|
* |
98
|
|
|
* @return integer The entity type ID of the configured entity type |
99
|
|
|
*/ |
100
|
|
|
protected function getEntityTypeId() |
101
|
|
|
{ |
102
|
|
|
|
103
|
|
|
// load the entity type for the configured entity type code |
104
|
|
|
$entityType = $this->getEavAwareProcessor()->loadEavEntityTypeByEntityTypeCode($this->getEntityTypeCode()); |
105
|
|
|
|
106
|
|
|
// return the entity type ID |
107
|
|
|
return $entityType[MemberNames::ENTITY_TYPE_ID]; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Load's and return's the EAV attribute option value with the passed entity type ID, code, store ID and value. |
112
|
|
|
* |
113
|
|
|
* @param string $entityTypeId The entity type ID of the EAV attribute to load the option value for |
114
|
|
|
* @param string $attributeCode The code of the EAV attribute option to load |
115
|
|
|
* @param integer $storeId The store ID of the attribute option to load |
116
|
|
|
* @param string $value The value of the attribute option to load |
117
|
|
|
* |
118
|
|
|
* @return array The EAV attribute option value |
119
|
|
|
*/ |
120
|
|
|
protected function loadAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value) |
121
|
|
|
{ |
122
|
|
|
return $this->getEavAwareProcessor()->loadAttributeOptionValueByEntityTypeIdAndAttributeCodeAndStoreIdAndValue($entityTypeId, $attributeCode, $storeId, $value); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|