@@ 201-220 (lines=20) @@ | ||
198 | * |
|
199 | * @return string The packed value |
|
200 | */ |
|
201 | protected function pack($attributeCode, $value) |
|
202 | { |
|
203 | ||
204 | // load the attibute with the passed code |
|
205 | $attribute = $this->loadAttributeByAttributeCode($attributeCode); |
|
206 | ||
207 | // pack the value according to the attribute's frontend input type |
|
208 | switch ($attribute[MemberNames::FRONTEND_INPUT]) { |
|
209 | case FrontendInputTypes::MULTISELECT: |
|
210 | return implode($this->getMultipleValueDelimiter(), $value); |
|
211 | break; |
|
212 | ||
213 | case FrontendInputTypes::BOOLEAN: |
|
214 | return $value === true ? 'true' : 'false'; |
|
215 | break; |
|
216 | ||
217 | default: |
|
218 | return $value; |
|
219 | } |
|
220 | } |
|
221 | ||
222 | /** |
|
223 | * Unpacks the passed value according to the frontend input type of the attribute with the passed code. |
|
@@ 230-250 (lines=21) @@ | ||
227 | * |
|
228 | * @return mixed The unpacked value |
|
229 | */ |
|
230 | protected function unpack($attributeCode, $value) |
|
231 | { |
|
232 | ||
233 | // load the attibute with the passed code |
|
234 | $attribute = $this->loadAttributeByAttributeCode($attributeCode); |
|
235 | ||
236 | // unpack the value according to the attribute's frontend input type |
|
237 | switch ($attribute[MemberNames::FRONTEND_INPUT]) { |
|
238 | ||
239 | case FrontendInputTypes::MULTISELECT: |
|
240 | return explode($this->getMultipleValueDelimiter(), $value); |
|
241 | break; |
|
242 | ||
243 | case FrontendInputTypes::BOOLEAN: |
|
244 | return filter_var($value, FILTER_VALIDATE_BOOLEAN); |
|
245 | break; |
|
246 | ||
247 | default: |
|
248 | return $value; |
|
249 | } |
|
250 | } |
|
251 | ||
252 | /** |
|
253 | * Passes the configuration and initializes the serializer. |