/**
  * {@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;
 }
 /**
  * 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();
 }
 /**
  * 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;
 }