/**
  * 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);
 }
 /**
  * {@inheritdoc}
  */
 public function getActions()
 {
     $actions = [];
     $options = ['entity' => 'product', 'locale' => $this->userContext->getUiLocale(), 'disable_grouping_separator' => true];
     foreach ($this->values as $value) {
         $rawData = $this->normalizer->normalize($value->getData(), 'json', $options);
         // if the value is localizable, let's use the locale the user has chosen in the form
         $locale = null !== $value->getLocale() ? $this->getLocale()->getCode() : null;
         $actions[] = ['field' => $value->getAttribute()->getCode(), 'value' => $rawData, 'options' => ['locale' => $locale, 'scope' => $value->getScope()]];
     }
     return $actions;
 }
 /**
  * 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();
 }
 /**
  * Build context for normalizer
  *
  * @return array
  */
 protected function buildContext()
 {
     $channels = array_keys($this->userContext->getChannelChoicesWithUserChannel());
     $locales = $this->userContext->getUserLocaleCodes();
     return ['locales' => $locales, 'channels' => $channels, 'filter_type' => 'pim.internal_api.product_value.view', 'locale' => $this->userContext->getUiLocale()->getCode(), 'disable_grouping_separator' => true];
 }
 /**
  * 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;
 }