/** * Get normalized default value for attribute * @param AbstractAttribute $attribute * @param string $defaultLocale * @param array $magentoAttributes * @param array $magentoAttributesOptions * @param MappingCollection $attributeMapping * * @return string */ protected function getNormalizedDefaultValue(AbstractAttribute $attribute, $defaultLocale, array $magentoAttributes, array $magentoAttributesOptions, MappingCollection $attributeMapping) { $attributeCode = strtolower($attributeMapping->getTarget($attribute->getCode())); $context = ['identifier' => null, 'scopeCode' => null, 'localeCode' => $defaultLocale, 'onlyLocalized' => false, 'magentoAttributes' => [$attributeCode => ['scope' => !$attribute->isLocalizable() ? ProductValueNormalizer::GLOBAL_SCOPE : '']], 'magentoAttributesOptions' => $magentoAttributesOptions, 'attributeCodeMapping' => $attributeMapping, 'currencyCode' => '']; if ($attribute->getDefaultValue() instanceof ProductValueInterface) { return reset($this->productValueNormalizer->normalize($attribute->getDefaultValue(), 'MagentoArray', $context)); } elseif ($attribute->getDefaultValue() instanceof AttributeOption) { $productValue = $this->productValueManager->createProductValueForDefaultOption($attribute); $normalizedOption = $this->productValueNormalizer->normalize($productValue, 'MagentoArray', $context); return null != $normalizedOption ? reset($normalizedOption) : null; } else { return null !== $attribute->getDefaultValue() ? (string) $attribute->getDefaultValue() : ''; } }
/** * Get values array for a given product * * @param ProductInterface $product The given product * @param array $magentoAttributes Attribute list from Magento * @param array $magentoAttributesOptions Attribute options list from Magento * @param string $localeCode The locale to apply * @param string $scopeCode The akeneo scope * @param MappingCollection $categoryMapping Root category mapping * @param MappingCollection $attributeCodeMapping Attribute mapping * @param boolean $onlyLocalized If true, only get translatable attributes * * @return array Computed data */ public function getValues(ProductInterface $product, $magentoAttributes, $magentoAttributesOptions, $localeCode, $scopeCode, MappingCollection $categoryMapping, MappingCollection $attributeCodeMapping, $onlyLocalized) { $normalizedValues = []; $context = ['identifier' => $product->getIdentifier(), 'scopeCode' => $scopeCode, 'localeCode' => $localeCode, 'onlyLocalized' => $onlyLocalized, 'magentoAttributes' => $magentoAttributes, 'magentoAttributesOptions' => $magentoAttributesOptions, 'attributeCodeMapping' => $attributeCodeMapping, 'currencyCode' => $this->currencyCode]; foreach ($product->getValues() as $value) { $normalizedValue = $this->productValueNormalizer->normalize($value, 'MagentoArray', $context); if ($normalizedValue !== null) { $normalizedValues = array_merge($normalizedValues, $normalizedValue); } } $normalizedValues = array_merge($normalizedValues, $this->getCustomValue($product, $attributeCodeMapping, ['categoryMapping' => $categoryMapping, 'scopeCode' => $scopeCode])); ksort($normalizedValues); return $normalizedValues; }