/** * Localize the changeset values * * @param array $changeset * * @return array */ protected function convertChangeset(array $changeset) { $formats = $this->localeResolver->getFormats(); foreach ($changeset as $attribute => $changes) { $attributeName = $attribute; if (preg_match('/^(?<attribute>[a-zA-Z0-9_]+)-.+$/', $attribute, $matches)) { $attributeName = $matches['attribute']; } foreach ($changes as $key => $value) { $changeset[$attribute][$key] = $this->converter->convertDefaultToLocalizedValue($attributeName, $value, $formats); } } return $changeset; }
/** * 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->convertLocalizedToDefaultValues($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->convertLocalizedToDefaultValues($data, ['locale' => $locale]); $product = $this->productBuilder->createProduct('0'); $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(); }
/** * Check and convert localized attributes to default format * * @param array $convertedItem * * @return array */ protected function convertLocalizedAttributes(array $convertedItem) { return $this->localizedConverter->convertLocalizedToDefaultValues($convertedItem, ['decimal_separator' => $this->decimalSeparator, 'date_format' => $this->dateFormat]); }
/** * 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->localizedConverter->convertLocalizedToDefaultValues($data['values'], ['locale' => $locale]); return $data; }