/**
  * {@inheritdoc}
  */
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     $productValues = [];
     foreach ($data as $attFieldName => $dataValue) {
         $attributeInfos = $this->fieldExtractor->extractColumnInfo($attFieldName);
         if (null !== $attributeInfos) {
             $attribute = $attributeInfos['attribute'];
             unset($attributeInfos['attribute']);
             $valueKey = $attribute->getCode();
             if ($attribute->isLocalizable()) {
                 $valueKey .= '-' . $attributeInfos['locale_code'];
             }
             if ($attribute->isScopable()) {
                 $valueKey .= '-' . $attributeInfos['scope_code'];
             }
             if (isset($productValues[$valueKey])) {
                 $value = $productValues[$valueKey];
             } else {
                 $value = new $this->valueClass();
                 $value->setAttribute($attribute);
                 $value->setLocale($attributeInfos['locale_code']);
                 $value->setScope($attributeInfos['scope_code']);
             }
             $productValues[$valueKey] = $this->valueDenormalizer->denormalize($dataValue, $this->valueClass, 'csv', ['entity' => $value] + $attributeInfos);
         }
     }
     return new ArrayCollection($productValues);
 }
Exemplo n.º 2
0
 /**
  * @param string $column
  * @param string $value
  *
  * @throws \LogicException
  *
  * @return array
  */
 protected function convertValue($column, $value)
 {
     $attributeFieldInfo = $this->attrFieldExtractor->extractColumnInfo($column);
     if (null !== $attributeFieldInfo && isset($attributeFieldInfo['attribute'])) {
         $converter = $this->converterRegistry->getConverter($attributeFieldInfo['attribute']->getAttributeType());
         if (null === $converter) {
             throw new \LogicException(sprintf('No converters found for attribute type "%s"', $attributeFieldInfo['attribute']->getAttributeType()));
         }
         return $converter->convert($attributeFieldInfo, $value);
     }
     throw new \LogicException(sprintf('Unable to convert the given column "%s"', $column));
 }
Exemplo n.º 3
0
 /**
  * @param array $row the item to merge
  *
  * @return array merged $row
  */
 public function merge(array $row)
 {
     $resultRow = [];
     $collectedMetrics = [];
     $collectedPrices = [];
     foreach ($row as $fieldName => $fieldValue) {
         $attributeInfos = $this->fieldExtractor->extractColumnInfo($fieldName);
         if (null !== $attributeInfos) {
             $attribute = $attributeInfos['attribute'];
             if (AttributeTypes::BACKEND_TYPE_METRIC === $attribute->getBackendType()) {
                 $collectedMetrics = $this->collectMetricData($collectedMetrics, $attributeInfos, $fieldValue);
             } elseif (AttributeTypes::BACKEND_TYPE_PRICE === $attribute->getBackendType()) {
                 $collectedPrices = $this->collectPriceData($collectedPrices, $attributeInfos, $fieldValue);
             } else {
                 $resultRow[$fieldName] = $fieldValue;
             }
         } else {
             $resultRow[$fieldName] = $fieldValue;
         }
     }
     $resultRow = $this->mergeMetricData($resultRow, $collectedMetrics);
     $resultRow = $this->mergePriceData($resultRow, $collectedPrices);
     return $resultRow;
 }