/** * {@inheritdoc} */ public function convert(array $item, array $options = []) { $standardizedItem = $this->converter->convert($item, $options); $delocalizedItem = $this->delocalizer->convertToDefaultFormats($standardizedItem, $options); $violations = $this->delocalizer->getViolations(); if ($violations->count() > 0) { throw new DataArrayConversionException('An error occurred during the delocalization of the product.', 0, null, $violations); } return $delocalizedItem; }
/** * {@inheritdoc} */ public function normalize($product, $format = null, array $context = []) { $normalizedProduct = $this->productNormalizer->normalize($product, 'json', $context); $normalizedProduct['values'] = $this->localizedConverter->convertToLocalizedFormats($normalizedProduct['values'], $context); $oldestLog = $this->versionManager->getOldestLogEntry($product); $newestLog = $this->versionManager->getNewestLogEntry($product); $created = null !== $oldestLog ? $this->versionNormalizer->normalize($oldestLog, 'internal_api') : null; $updated = null !== $newestLog ? $this->versionNormalizer->normalize($newestLog, 'internal_api') : null; $normalizedProduct['meta'] = ['form' => $this->formProvider->getForm($product), 'id' => $product->getId(), 'created' => $created, 'updated' => $updated, 'model_type' => 'product', 'structure_version' => $this->structureVersionProvider->getStructureVersion()] + $this->getLabels($product) + $this->getAssociationMeta($product); return $normalizedProduct; }
/** * {@inheritdoc} */ public function normalize($group, $format = null, array $context = []) { $normalizedGroup = $this->groupNormalizer->normalize($group, 'json', $context); if (isset($normalizedGroup['values'])) { $normalizedGroup['values'] = $this->localizedConverter->convertToLocalizedFormats($normalizedGroup['values'], $context); } $normalizedGroup['products'] = []; foreach ($group->getProducts() as $product) { $normalizedGroup['products'][] = $product->getId(); } $firstVersion = $this->versionManager->getOldestLogEntry($group); $lastVersion = $this->versionManager->getNewestLogEntry($group); $firstVersion = null !== $firstVersion ? $this->versionNormalizer->normalize($firstVersion, 'internal_api') : null; $lastVersion = null !== $lastVersion ? $this->versionNormalizer->normalize($lastVersion, 'internal_api') : null; $normalizedGroup['meta'] = ['id' => $group->getId(), 'form' => 'pim-variant-group-edit-form', 'structure_version' => $this->structureVersionProvider->getStructureVersion(), 'model_type' => 'variant_group', 'created' => $firstVersion, 'updated' => $lastVersion]; return $normalizedGroup; }
/** * Updates product with the provided request data * * @param ProductInterface $product * @param array $data */ protected function updateProduct(ProductInterface $product, array $data) { $values = $this->localizedConverter->convertToDefaultFormats($data['values'], ['locale' => $this->userContext->getUiLocale()->getCode()]); $values = $this->emptyValuesFilter->filter($product, $values); unset($data['values']); $data = array_replace($data, $values); $this->productUpdater->update($product, $data); }
/** * Convert localized values in template of a variant group * * @param GroupInterface $group */ protected function convertLocalizedValues(GroupInterface $group) { $template = $group->getProductTemplate(); if (null === $template) { return; } $options = ['locale' => $this->request->getLocale(), 'disable_grouping_separator' => true]; $valuesData = $this->localizedConverter->convertToDefaultFormats($template->getValuesData(), $options); $template->setValuesData($valuesData); }
/** * Apply current values to a fake product and test its integrity with the product validator. * If violations are raised, values are not valid. * * Errors are stored in json format to be useable by the Product Edit Form. * * @return bool */ public function hasValidValues() { $data = json_decode($this->values, true); $locale = $this->userContext->getUiLocale()->getCode(); $data = $this->localizedConverter->convertToDefaultFormats($data, ['locale' => $locale]); $product = $this->productBuilder->createProduct('FAKE_SKU_FOR_MASS_EDIT_VALIDATION_' . microtime()); $this->productUpdater->update($product, $data); $violations = $this->productValidator->validate($product); $violations->addAll($this->localizedConverter->getViolations()); $errors = ['values' => $this->internalNormalizer->normalize($violations, 'internal_api', ['product' => $product])]; $this->errors = json_encode($errors); return 0 === $violations->count(); }
/** * {@inheritdoc} */ public function convert(array $productStandard, array $options = []) { $productStandard['values'] = $this->localizer->convertToLocalizedFormats($productStandard['values'], $options); $productFlat = $this->converter->convert($productStandard, $options); return $productFlat; }
/** * Convert localized attributes to the default format * * @param array $data * * @return array */ protected function convertLocalizedAttributes(array $data) { $locale = $this->userContext->getUiLocale()->getCode(); $data['values'] = $this->attributeConverter->convertToDefaultFormats($data['values'], ['locale' => $locale]); return $data; }