@@ 13-73 (lines=61) @@ | ||
10 | * |
|
11 | * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer |
|
12 | */ |
|
13 | class PimCatalogBooleanNormalizer implements NormalizerInterface |
|
14 | { |
|
15 | ||
16 | /** |
|
17 | * @param object $attribute |
|
18 | * @param null $format |
|
19 | * @param array $context |
|
20 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
21 | */ |
|
22 | public function normalize($attribute, $format = null, array $context = []) |
|
23 | { |
|
24 | /**@var Attribute $attribute * */ |
|
25 | $normalizedAttribute = [ |
|
26 | 'code' => null, |
|
27 | 'type' => null, |
|
28 | 'required' => null, |
|
29 | 'labels' => null, |
|
30 | 'parameters' => null, |
|
31 | ]; |
|
32 | ||
33 | $availableLocales = []; |
|
34 | $attributeAvailableLocales = $attribute->getAvailableLocales(); |
|
35 | if (!is_null($attributeAvailableLocales)) { |
|
36 | foreach ($attribute->getAvailableLocales() as $availableLocale) { |
|
37 | $availableLocales [] = $availableLocale; |
|
38 | } |
|
39 | } |
|
40 | ||
41 | $normalizedAttribute['required'] = $attribute->isRequired(); |
|
42 | $normalizedAttribute['type'] = $attribute->getAttributeType(); |
|
43 | $normalizedAttribute['code'] = $attribute->getCode(); |
|
44 | $normalizedAttribute['parameters'] = [ |
|
45 | 'scope' => $attribute->isScopable(), |
|
46 | 'localizable' => $attribute->isLocalizable(), |
|
47 | 'available_locales' => $availableLocales, |
|
48 | 'default_value' => null, |
|
49 | ]; |
|
50 | ||
51 | if ($attribute->isLocalizable()) { |
|
52 | foreach ($attribute->getTranslations() as $trans) { |
|
53 | $normalizedAttribute['labels'][$trans->getLocale( |
|
54 | )] = $trans->getLabel(); |
|
55 | } |
|
56 | } else { |
|
57 | $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel( |
|
58 | ); |
|
59 | } |
|
60 | ||
61 | return $normalizedAttribute; |
|
62 | } |
|
63 | ||
64 | /** |
|
65 | * @param mixed $data |
|
66 | * @param null $format |
|
67 | * @return bool |
|
68 | */ |
|
69 | public function supportsNormalization($data, $format = null) |
|
70 | { |
|
71 | return $data instanceof Attribute; |
|
72 | } |
|
73 | } |
|
74 |
@@ 13-73 (lines=61) @@ | ||
10 | * |
|
11 | * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer |
|
12 | */ |
|
13 | class PimCatalogPriceCollectionNormalizer implements NormalizerInterface |
|
14 | { |
|
15 | /** |
|
16 | * @param object $attribute |
|
17 | * @param null $format |
|
18 | * @param array $context |
|
19 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
20 | */ |
|
21 | public function normalize($attribute, $format = null, array $context = []) |
|
22 | { |
|
23 | /**@var Attribute $attribute * */ |
|
24 | $normalizedAttribute = [ |
|
25 | 'code' => null, |
|
26 | 'type' => null, |
|
27 | 'required' => null, |
|
28 | 'labels' => null, |
|
29 | 'parameters' => null, |
|
30 | ]; |
|
31 | $availableLocales = []; |
|
32 | $attributeAvailableLocales = $attribute->getAvailableLocales(); |
|
33 | if (!is_null($attributeAvailableLocales)) { |
|
34 | foreach ($attribute->getAvailableLocales() as $availableLocale) { |
|
35 | $availableLocales [] = $availableLocale; |
|
36 | } |
|
37 | } |
|
38 | ||
39 | $normalizedAttribute['required'] = $attribute->isRequired(); |
|
40 | $normalizedAttribute['type'] = $attribute->getAttributeType(); |
|
41 | $normalizedAttribute['code'] = $attribute->getCode(); |
|
42 | $normalizedAttribute['parameters'] = [ |
|
43 | 'scope' => $attribute->isScopable(), |
|
44 | 'localizable' => $attribute->isLocalizable(), |
|
45 | 'available_locales' => $availableLocales, |
|
46 | ]; |
|
47 | ||
48 | if ($attribute->isLocalizable()) { |
|
49 | foreach ($attribute->getTranslations() as $trans) { |
|
50 | $normalizedAttribute['labels'][$trans->getLocale( |
|
51 | )] = $trans->getLabel(); |
|
52 | } |
|
53 | } else { |
|
54 | $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel( |
|
55 | ); |
|
56 | } |
|
57 | ||
58 | return $normalizedAttribute; |
|
59 | } |
|
60 | ||
61 | /** |
|
62 | * Checks whether the given class is supported for normalization by this normalizer |
|
63 | * |
|
64 | * @param mixed $data Data to normalize. |
|
65 | * @param string $format The format being (de-)serialized from or into. |
|
66 | * |
|
67 | * @return boolean |
|
68 | */ |
|
69 | public function supportsNormalization($data, $format = null) |
|
70 | { |
|
71 | return $data instanceof Attribute; |
|
72 | } |
|
73 | } |
|
74 |
@@ 13-74 (lines=62) @@ | ||
10 | * |
|
11 | * @package Actualys\Bundle\DrupalCommerceConnectorBundle\Normalizer |
|
12 | */ |
|
13 | class PimCatalogSimpleSelectNormalizer implements NormalizerInterface |
|
14 | { |
|
15 | /** |
|
16 | * @param object $attribute |
|
17 | * @param null $format |
|
18 | * @param array $context |
|
19 | * @return array|\Symfony\Component\Serializer\Normalizer\scalar |
|
20 | */ |
|
21 | public function normalize($attribute, $format = null, array $context = []) |
|
22 | { |
|
23 | /**@var Attribute $attribute * */ |
|
24 | $normalizedAttribute = [ |
|
25 | 'code' => null, |
|
26 | 'type' => null, |
|
27 | 'required' => null, |
|
28 | 'labels' => null, |
|
29 | 'parameters' => null, |
|
30 | ]; |
|
31 | $availableLocales = []; |
|
32 | $attributeAvailableLocales = $attribute->getAvailableLocales(); |
|
33 | if (!is_null($attributeAvailableLocales)) { |
|
34 | foreach ($attribute->getAvailableLocales() as $availableLocale) { |
|
35 | $availableLocales [] = $availableLocale; |
|
36 | } |
|
37 | } |
|
38 | ||
39 | $normalizedAttribute['required'] = $attribute->isRequired(); |
|
40 | $normalizedAttribute['type'] = $attribute->getAttributeType(); |
|
41 | $normalizedAttribute['code'] = $attribute->getCode(); |
|
42 | $normalizedAttribute['parameters'] = [ |
|
43 | 'scope' => $attribute->isScopable(), |
|
44 | 'localizable' => $attribute->isLocalizable(), |
|
45 | 'available_locales' => $availableLocales, |
|
46 | 'minimum_input_length' => $attribute->getMinimumInputLength(), |
|
47 | ]; |
|
48 | ||
49 | if ($attribute->isLocalizable()) { |
|
50 | foreach ($attribute->getTranslations() as $trans) { |
|
51 | $normalizedAttribute['labels'][$trans->getLocale( |
|
52 | )] = $trans->getLabel(); |
|
53 | } |
|
54 | } else { |
|
55 | $normalizedAttribute['labels'][LANGUAGE_NONE] = $attribute->getLabel( |
|
56 | ); |
|
57 | } |
|
58 | ||
59 | return $normalizedAttribute; |
|
60 | } |
|
61 | ||
62 | /** |
|
63 | * Checks whether the given class is supported for normalization by this normalizer |
|
64 | * |
|
65 | * @param mixed $data Data to normalize. |
|
66 | * @param string $format The format being (de-)serialized from or into. |
|
67 | * |
|
68 | * @return boolean |
|
69 | */ |
|
70 | public function supportsNormalization($data, $format = null) |
|
71 | { |
|
72 | return $data instanceof Attribute; |
|
73 | } |
|
74 | } |
|
75 |