1 | <?php |
||
36 | abstract class AbstractEavSubject extends AbstractSubject implements EavSubjectInterface, NumberConverterSubjectInterface |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The trait that provides number converting functionality. |
||
41 | * |
||
42 | * @var \TechDivision\Import\Subjects\NumberConverterTrait |
||
43 | */ |
||
44 | use NumberConverterTrait; |
||
45 | |||
46 | /** |
||
47 | * The available EAV attributes, grouped by their attribute set and the attribute set name as keys. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $attributes = array(); |
||
52 | |||
53 | /** |
||
54 | * The available user defined EAV attributes, grouped by their entity type. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $userDefinedAttributes = array(); |
||
59 | |||
60 | /** |
||
61 | * The attribute set of the entity that has to be created. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $attributeSet = array(); |
||
66 | |||
67 | /** |
||
68 | * The available EAV attribute sets. |
||
69 | * |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $attributeSets = array(); |
||
73 | |||
74 | /** |
||
75 | * The mapping for the supported backend types (for the EAV entity) => persist methods. |
||
76 | * |
||
77 | * @var array |
||
78 | */ |
||
79 | protected $backendTypes = array( |
||
80 | BackendTypeKeys::BACKEND_TYPE_DATETIME => array('persistDatetimeAttribute', 'loadDatetimeAttribute', 'deleteDatetimeAttribute'), |
||
81 | BackendTypeKeys::BACKEND_TYPE_DECIMAL => array('persistDecimalAttribute', 'loadDecimalAttribute', 'deleteDecimalAttribute'), |
||
82 | BackendTypeKeys::BACKEND_TYPE_INT => array('persistIntAttribute', 'loadIntAttribute', 'deleteIntAttribute'), |
||
83 | BackendTypeKeys::BACKEND_TYPE_TEXT => array('persistTextAttribute', 'loadTextAttribute', 'deleteTextAttribute'), |
||
84 | BackendTypeKeys::BACKEND_TYPE_VARCHAR => array('persistVarcharAttribute', 'loadVarcharAttribute', 'deleteVarcharAttribute') |
||
85 | ); |
||
86 | |||
87 | /** |
||
88 | * The default mappings for the user defined attributes, based on the attributes frontend input type. |
||
89 | * |
||
90 | * @var array |
||
91 | */ |
||
92 | protected $defaultFrontendInputCallbackMappings = array(); |
||
93 | |||
94 | /** |
||
95 | * Return's the default callback frontend input mappings for the user defined attributes. |
||
96 | * |
||
97 | * @return array The default frontend input callback mappings |
||
98 | */ |
||
99 | 34 | public function getDefaultFrontendInputCallbackMappings() |
|
100 | { |
||
101 | 34 | return $this->defaultFrontendInputCallbackMappings; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * Intializes the previously loaded global data for exactly one bunch. |
||
106 | * |
||
107 | * @param string $serial The serial of the actual import |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | 34 | public function setUp($serial) |
|
112 | { |
||
113 | |||
114 | // load the status of the actual import |
||
115 | 34 | $status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); |
|
116 | |||
117 | // load the global data, if prepared initially |
||
118 | 34 | if (isset($status[RegistryKeys::GLOBAL_DATA])) { |
|
119 | 34 | $this->attributes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::EAV_ATTRIBUTES]; |
|
120 | 34 | $this->attributeSets = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::ATTRIBUTE_SETS]; |
|
121 | 34 | $this->userDefinedAttributes = $status[RegistryKeys::GLOBAL_DATA][RegistryKeys::EAV_USER_DEFINED_ATTRIBUTES]; |
|
122 | } |
||
123 | |||
124 | // load the default frontend callback mappings from the child instance and merge with the one from the configuration |
||
125 | 34 | $defaultFrontendInputCallbackMappings = $this->getDefaultFrontendInputCallbackMappings(); |
|
126 | |||
127 | // load the available frontend input callbacks from the configuration |
||
128 | 34 | $availableFrontendInputCallbacks = $this->getConfiguration()->getFrontendInputCallbacks(); |
|
129 | |||
130 | // merge the default mappings with the one's found in the configuration |
||
131 | 34 | foreach ($availableFrontendInputCallbacks as $frontendInputCallbackMappings) { |
|
132 | foreach ($frontendInputCallbackMappings as $frontendInput => $frontentInputMappings) { |
||
133 | $defaultFrontendInputCallbackMappings[$frontendInput] = $frontentInputMappings; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | // load the user defined EAV attributes |
||
138 | 34 | $eavUserDefinedAttributes = $this->getEavUserDefinedAttributes(); |
|
139 | |||
140 | // load the user defined attributes and add the callback mappings |
||
141 | 34 | foreach ($eavUserDefinedAttributes as $eavAttribute) { |
|
142 | // load attribute code and frontend input type |
||
143 | 1 | $attributeCode = $eavAttribute[MemberNames::ATTRIBUTE_CODE]; |
|
144 | 1 | $frontendInput = $eavAttribute[MemberNames::FRONTEND_INPUT]; |
|
145 | |||
146 | // query whether or not the array for the mappings has been initialized |
||
147 | 1 | if (!isset($this->callbackMappings[$attributeCode])) { |
|
148 | 1 | $this->callbackMappings[$attributeCode] = array(); |
|
149 | } |
||
150 | |||
151 | // set the appropriate callback mapping for the attributes input type |
||
152 | 1 | if (isset($defaultFrontendInputCallbackMappings[$frontendInput])) { |
|
153 | 1 | foreach ($defaultFrontendInputCallbackMappings[$frontendInput] as $defaultFrontendInputCallbackMapping) { |
|
154 | 1 | $this->callbackMappings[$attributeCode][] = $defaultFrontendInputCallbackMapping; |
|
155 | } |
||
156 | } |
||
157 | } |
||
158 | |||
159 | // prepare the callbacks |
||
160 | 34 | parent::setUp($serial); |
|
161 | 34 | } |
|
162 | |||
163 | /** |
||
164 | * Return's mapping for the supported backend types (for the product entity) => persist methods. |
||
165 | * |
||
166 | * @return array The mapping for the supported backend types |
||
167 | */ |
||
168 | 1 | public function getBackendTypes() |
|
172 | |||
173 | /** |
||
174 | * Set's the attribute set of the product that has to be created. |
||
175 | * |
||
176 | * @param array $attributeSet The attribute set |
||
177 | * |
||
178 | * @return void |
||
179 | */ |
||
180 | 5 | public function setAttributeSet(array $attributeSet) |
|
184 | |||
185 | /** |
||
186 | * Return's the attribute set of the product that has to be created. |
||
187 | * |
||
188 | * @return array The attribute set |
||
189 | */ |
||
190 | 1 | public function getAttributeSet() |
|
194 | |||
195 | /** |
||
196 | * Cast's the passed value based on the backend type information. |
||
197 | * |
||
198 | * @param string $backendType The backend type to cast to |
||
199 | * @param mixed $value The value to be casted |
||
200 | * |
||
201 | * @return mixed The casted value |
||
202 | */ |
||
203 | 21 | public function castValueByBackendType($backendType, $value) |
|
228 | |||
229 | /** |
||
230 | * Return's the attribute set with the passed attribute set name. |
||
231 | * |
||
232 | * @param string $attributeSetName The name of the requested attribute set |
||
233 | * |
||
234 | * @return array The attribute set data |
||
235 | * @throws \Exception Is thrown, if the attribute set or the given entity type with the passed name is not available |
||
236 | */ |
||
237 | 3 | public function getAttributeSetByAttributeSetName($attributeSetName) |
|
265 | |||
266 | /** |
||
267 | * Return's the attributes for the attribute set of the product that has to be created. |
||
268 | * |
||
269 | * @return array The attributes |
||
270 | * @throws \Exception Is thrown, if the attribute set or the given entity type with the passed name is not available |
||
271 | */ |
||
272 | 5 | public function getAttributes() |
|
308 | |||
309 | /** |
||
310 | * Return's an array with the available user defined EAV attributes for the actual entity type. |
||
311 | * |
||
312 | * @return array The array with the user defined EAV attributes |
||
313 | */ |
||
314 | 34 | public function getEavUserDefinedAttributes() |
|
328 | |||
329 | /** |
||
330 | * Return's the EAV attribute with the passed attribute code. |
||
331 | * |
||
332 | * @param string $attributeCode The attribute code |
||
333 | * |
||
334 | * @return array The array with the EAV attribute |
||
335 | * @throws \Exception Is thrown if the attribute with the passed code is not available |
||
336 | */ |
||
337 | 2 | public function getEavAttributeByAttributeCode($attributeCode) |
|
355 | } |
||
356 |