Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function store(\SplFileInfo $localFile, $destFsAlias, $deleteRawFile = false)
 {
     $filesystem = $this->mountManager->getFilesystem($destFsAlias);
     $file = $this->factory->createFromRawFile($localFile, $destFsAlias);
     $error = sprintf('Unable to move the file "%s" to the "%s" filesystem.', $localFile->getPathname(), $destFsAlias);
     if (false === ($resource = fopen($localFile->getPathname(), 'r'))) {
         throw new FileTransferException($error);
     }
     try {
         $options = [];
         $mimeType = $file->getMimeType();
         if (null !== $mimeType) {
             $options['ContentType'] = $mimeType;
         }
         $isFileWritten = $filesystem->writeStream($file->getKey(), $resource, $options);
     } catch (FileExistsException $e) {
         throw new FileTransferException($error, $e->getCode(), $e);
     }
     if (false === $isFileWritten) {
         throw new FileTransferException($error);
     }
     $this->saver->save($file);
     if (true === $deleteRawFile) {
         $this->deleteRawFile($localFile);
     }
     return $file;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function move(FileInterface $file, $srcFsAlias, $destFsAlias)
 {
     $isFileMoved = $this->mountManager->move(sprintf('%s://%s', $srcFsAlias, $file->getKey()), sprintf('%s://%s', $destFsAlias, $file->getKey()));
     if (!$isFileMoved) {
         throw new FileTransferException(sprintf('Impossible to move the file "%s" from "%s" to "%s".', $file->getKey(), $srcFsAlias, $destFsAlias));
     }
     $file->setStorage($destFsAlias);
     $this->saver->save($file);
 }
 /**
  * Saves a history item, by creating a new one if the page is visited for
  * the first time, or by updating an existing one if the user has already
  * visited the page.
  *
  * @param Request $request
  *
  * @return JsonResponse
  */
 public function postAction(Request $request)
 {
     $history = json_decode($request->getContent(), true);
     $historyItem = $this->findOrCreate($this->getUser(), $history['url']);
     $historyItem->setTitle(json_encode($history['title']));
     $historyItem->doUpdate();
     $this->saver->save($historyItem);
     return new JsonResponse();
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function write(array $items)
 {
     $this->versionManager->setRealTimeVersioning($this->realTimeVersioning);
     foreach ($items as $item) {
         $this->incrementCount($item);
     }
     $this->mediaManager->handleAllProductsMedias($items);
     $this->productSaver->saveAll($items, ['recalculate' => false]);
     $this->cacheClearer->clear();
 }
Exemplo n.º 5
0
 /**
  * Call when form is valid
  *
  * @param GroupInterface $group
  */
 protected function onSuccess(GroupInterface $group)
 {
     $appendProducts = $this->form->get('appendProducts')->getData();
     $removeProducts = $this->form->get('removeProducts')->getData();
     $options = ['add_products' => $appendProducts, 'remove_products' => $removeProducts];
     if ($group->getType()->isVariant()) {
         $options['copy_values_to_products'] = true;
     }
     $this->groupSaver->save($group, $options);
 }
 /**
  * Remove an attribute form a variant group
  *
  * @param string $code        The variant group code
  * @param int    $attributeId The attribute id
  *
  * @AclAncestor("pim_enrich_group_remove_attribute")
  *
  * @throws NotFoundHttpException If variant group or attribute is not found or the user cannot see it
  *
  * @return JsonResponse
  */
 public function removeAttributeAction($code, $attributeId)
 {
     $group = $this->findVariantGroupOr404($code);
     $attribute = $this->findAttributeOr404($attributeId);
     $template = $group->getProductTemplate();
     if (null !== $template) {
         $this->templateBuilder->removeAttribute($template, $attribute);
         $this->groupSaver->save($group);
     }
     return new JsonResponse();
 }
 /**
  * Activate/Deactivate a currency
  *
  * @param Currency $currency
  *
  * @AclAncestor("pim_enrich_currency_toggle")
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function toggleAction(Currency $currency)
 {
     try {
         $currency->toggleActivation();
         $this->currencySaver->save($currency);
         $this->addFlash('success', 'flash.currency.updated');
     } catch (\Exception $e) {
         $this->addFlash('error', 'flash.error ocurred');
     }
     return $this->redirect($this->generateUrl('pim_enrich_currency_index'));
 }
 /**
  * Add attributes to a group
  *
  * @param AttributeGroupInterface $group
  * @param AttributeInterface[]    $attributes
  */
 public function addAttributes(AttributeGroupInterface $group, $attributes)
 {
     $maxOrder = $group->getMaxAttributeSortOrder();
     foreach ($attributes as $attribute) {
         $maxOrder++;
         $attribute->setSortOrder($maxOrder);
         $group->addAttribute($attribute);
     }
     $this->attributeSaver->saveAll($attributes);
     $this->groupSaver->save($group);
 }
Exemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function process($entity)
 {
     $this->form->setData($entity);
     if ($this->request->isMethod('POST')) {
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->saver->save($entity);
             return true;
         }
     }
     return false;
 }
 /**
  * @param RemoveEvent $event
  */
 public function postRemove(RemoveEvent $event)
 {
     $author = '';
     $subject = $event->getSubject();
     if (null !== ($token = $this->tokenStorage->getToken()) && $this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $author = $token->getUser()->getUsername();
     }
     $previousVersion = $this->versionRepository->getNewestLogEntry(ClassUtils::getClass($subject), $event->getSubjectId());
     $version = $this->versionFactory->create(ClassUtils::getClass($subject), $event->getSubjectId(), $author, 'Deleted');
     $version->setVersion(null !== $previousVersion ? $previousVersion->getVersion() + 1 : 1)->setSnapshot(null !== $previousVersion ? $previousVersion->getSnapshot() : [])->setChangeset([]);
     $this->versionSaver->save($version);
 }
 /**
  * Activate/Deactivate a currency
  *
  * @param Currency $currency
  *
  * @AclAncestor("pim_enrich_currency_toggle")
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function toggleAction(Currency $currency)
 {
     try {
         $currency->toggleActivation();
         $this->currencySaver->save($currency);
         $this->request->getSession()->getFlashBag()->add('success', new Message('flash.currency.updated'));
     } catch (LinkedChannelException $e) {
         $this->request->getSession()->getFlashBag()->add('error', new Message('flash.currency.error.linked_to_channel'));
     } catch (\Exception $e) {
         $this->request->getSession()->getFlashBag()->add('error', new Message('flash.error ocurred'));
     }
     return new RedirectResponse($this->router->generate('pim_enrich_currency_index'));
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification, array $users)
 {
     $userNotifications = [];
     foreach ($users as $user) {
         try {
             $user = is_object($user) ? $user : $this->userProvider->loadUserByUsername($user);
             $userNotifications[] = $this->userNotifFactory->createUserNotification($notification, $user);
         } catch (UsernameNotFoundException $e) {
             continue;
         }
     }
     $this->notificationSaver->save($notification);
     $this->userNotifsSaver->saveAll($userNotifications);
     return $this;
 }
 /**
  * Remove an attribute
  *
  * @param int $familyId
  * @param int $attributeId
  *
  * @AclAncestor("pim_enrich_family_edit_attributes")
  *
  * @throws DeleteException
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAttributeAction($familyId, $attributeId)
 {
     $family = $this->findOr404('PimCatalogBundle:Family', $familyId);
     $attribute = $this->findOr404($this->attributeClass, $attributeId);
     if (false === $family->hasAttribute($attribute)) {
         throw new DeleteException($this->getTranslator()->trans('flash.family.attribute not found'));
     } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         throw new DeleteException($this->getTranslator()->trans('flash.family.identifier not removable'));
     } elseif ($attribute === $family->getAttributeAsLabel()) {
         throw new DeleteException($this->getTranslator()->trans('flash.family.label attribute not removable'));
     } else {
         $family->removeAttribute($attribute);
         foreach ($family->getAttributeRequirements() as $requirement) {
             if ($requirement->getAttribute() === $attribute) {
                 $family->removeAttributeRequirement($requirement);
                 $this->getManagerForClass(ClassUtils::getClass($requirement))->remove($requirement);
             }
         }
         $this->familySaver->save($family);
     }
     if ($this->getRequest()->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return $this->redirectToRoute('pim_enrich_family_edit', ['id' => $family->getId()]);
     }
 }
 /**
  * Update product
  *
  * @param Request $request
  * @param integer $id
  *
  * @Template("PimEnrichBundle:Product:edit.html.twig")
  * @AclAncestor("pim_enrich_product_index")
  * @return RedirectResponse
  */
 public function updateAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     $this->productManager->ensureAllAssociationTypes($product);
     $form = $this->createForm('pim_product_edit', $product, $this->getEditFormOptions($product));
     $form->submit($request, false);
     if ($form->isValid()) {
         try {
             $this->mediaManager->handleProductMedias($product);
             $this->productSaver->save($product);
             $this->addFlash('success', 'flash.product.updated');
         } catch (MediaManagementException $e) {
             $this->addFlash('error', $e->getMessage());
         }
         $params = ['id' => $product->getId(), 'dataLocale' => $this->getDataLocaleCode()];
         if ($comparisonLocale = $this->getComparisonLocale()) {
             $params['compareWith'] = $comparisonLocale;
         }
         return $this->redirectAfterEdit($params);
     } else {
         $this->addFlash('error', 'flash.product.invalid');
     }
     $channels = $this->getRepository('PimCatalogBundle:Channel')->findAll();
     $trees = $this->productCatManager->getProductCountByTree($product);
     return $this->getProductEditTemplateParams($form, $product, $channels, $trees);
 }
Exemplo n.º 15
0
 /**
  * Remove an attribute
  *
  * @param int $familyId
  * @param int $attributeId
  *
  * @AclAncestor("pim_enrich_family_edit_attributes")
  *
  * @throws DeleteException
  *
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function removeAttributeAction($familyId, $attributeId)
 {
     $family = $this->familyRepository->find($familyId);
     if (null === $family) {
         throw new NotFoundHttpException(sprintf('%s entity not found', $this->familyClass));
     }
     $attribute = $this->attributeRepo->find($attributeId);
     if (null === $attribute) {
         throw new NotFoundHttpException(sprintf('%s entity not found', $this->attributeClass));
     }
     if (false === $family->hasAttribute($attribute)) {
         throw new DeleteException($this->translator->trans('flash.family.attribute not found'));
     } elseif (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         throw new DeleteException($this->translator->trans('flash.family.identifier not removable'));
     } elseif ($attribute === $family->getAttributeAsLabel()) {
         throw new DeleteException($this->translator->trans('flash.family.label attribute not removable'));
     } else {
         $family->removeAttribute($attribute);
         foreach ($family->getAttributeRequirements() as $requirement) {
             if ($requirement->getAttribute() === $attribute) {
                 $family->removeAttributeRequirement($requirement);
                 $this->doctrine->getManagerForClass(ClassUtils::getClass($requirement))->remove($requirement);
             }
         }
         $this->familySaver->save($family);
     }
     if ($this->request->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return new RedirectResponse($this->router->generate('pim_enrich_family_edit', ['id' => $family->getId()]));
     }
 }
 /**
  * Save the job configuration
  *
  * @param string $configuration
  */
 protected function setJobConfiguration($configuration)
 {
     $jobExecution = $this->stepExecution->getJobExecution();
     $massEditJobConf = $this->jobConfigurationRepo->findOneBy(['jobExecution' => $jobExecution]);
     $massEditJobConf->setConfiguration($configuration);
     $this->jobConfigurationSaver->save($massEditJobConf);
 }
Exemplo n.º 17
0
 /**
  * Deletes values that link an attribute to a product
  *
  * @param ProductInterface   $product
  * @param AttributeInterface $attribute
  * @param array              $savingOptions
  *
  * @deprecated Will be removed in 1.5, please use ProductBuilderInterface::removeAttributeFromProduct() and
  *             ProductSaver::save() instead.
  */
 public function removeAttributeFromProduct(ProductInterface $product, AttributeInterface $attribute, array $savingOptions = [])
 {
     foreach ($product->getValues() as $value) {
         if ($attribute === $value->getAttribute()) {
             $product->removeValue($value);
         }
     }
     $options = array_merge(['recalculate' => false, 'schedule' => false], $savingOptions);
     $this->productSaver->save($product, $options);
 }
 /**
  * Manage form submission of an attribute option
  *
  * @param AttributeOptionInterface $attributeOption
  * @param array                    $data
  *
  * @return FormInterface
  */
 protected function manageFormSubmission(AttributeOptionInterface $attributeOption, array $data = [])
 {
     $form = $this->formFactory->createNamed('option', 'pim_enrich_attribute_option', $attributeOption);
     $form->submit($data, false);
     if ($form->isValid()) {
         $this->optionSaver->save($attributeOption);
         $option = $this->normalizer->normalize($attributeOption, 'array', ['onlyActivatedLocales' => true]);
         return new JsonResponse($option);
     }
     return $this->viewHandler->handle(RestView::create($form));
 }
Exemplo n.º 19
0
 /**
  * {@inheritdoc}
  */
 public function store(\SplFileInfo $localFile, $destFsAlias)
 {
     $filesystem = $this->mountManager->getFilesystem($destFsAlias);
     $storageData = $this->pathGenerator->generate($localFile);
     $file = $this->factory->create($localFile, $storageData, $destFsAlias);
     $error = sprintf('Unable to move the file "%s" to the "%s" filesystem.', $localFile->getPathname(), $destFsAlias);
     if (false === ($resource = fopen($localFile->getPathname(), 'r'))) {
         throw new FileTransferException($error);
     }
     try {
         $isFileWritten = $filesystem->writeStream($file->getKey(), $resource);
     } catch (FileExistsException $e) {
         throw new FileTransferException($error, $e->getCode(), $e);
     }
     if (false === $isFileWritten) {
         throw new FileTransferException($error);
     }
     $this->saver->save($file, ['flush_only_object' => true]);
     $this->deleteRawFile($localFile);
     return $file;
 }
 /**
  * Toggle product status (enabled/disabled)
  *
  * @param Request $request
  * @param int     $id
  *
  * @return Response|RedirectResponse
  *
  * @AclAncestor("pim_enrich_product_edit_attributes")
  */
 public function toggleStatusAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     $toggledStatus = !$product->isEnabled();
     $product->setEnabled($toggledStatus);
     $this->productSaver->save($product);
     $successMessage = $toggledStatus ? 'flash.product.enabled' : 'flash.product.disabled';
     if ($request->isXmlHttpRequest()) {
         return new JsonResponse(['successful' => true, 'message' => $this->translator->trans($successMessage)]);
     } else {
         return $this->redirectToRoute('pim_enrich_product_index');
     }
 }
Exemplo n.º 21
0
 /**
  * Remove an optional attribute from a product
  *
  * @param int $id          The product id
  * @param int $attributeId The attribute id
  *
  * @AclAncestor("pim_enrich_product_remove_attribute")
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have right to edit the product
  * @throws BadRequestHttpException   If the attribute is not removable
  *
  * @return JsonResponse
  */
 public function removeAttributeAction($id, $attributeId)
 {
     $product = $this->findProductOr404($id);
     if ($this->objectFilter->filterObject($product, 'pim.internal_api.product.edit')) {
         throw new AccessDeniedHttpException();
     }
     $attribute = $this->findAttributeOr404($attributeId);
     if (!$product->isAttributeRemovable($attribute)) {
         throw new BadRequestHttpException();
     }
     $this->productBuilder->removeAttributeFromProduct($product, $attribute);
     $this->productSaver->save($product);
     return new JsonResponse();
 }
 /**
  * Remove an attribute form a variant group
  *
  * @param Request $request
  * @param int     $groupId
  * @param int     $attributeId
  *
  * @AclAncestor("pim_enrich_group_remove_attribute")
  *
  * @throws NotFoundHttpException
  *
  * @return RedirectResponse
  */
 public function removeAttributeAction(Request $request, $groupId, $attributeId)
 {
     $group = $this->findVariantGroupOr404($groupId);
     $attribute = $this->findAttributeOr404($attributeId);
     $template = $group->getProductTemplate();
     if (null !== $template) {
         $this->templateBuilder->removeAttribute($template, $attribute);
         $this->groupSaver->save($group);
     }
     if ($request->isXmlHttpRequest()) {
         return new Response('', 204);
     }
     return $this->redirectToRoute('pim_enrich_variant_group_edit', ['id' => $groupId]);
 }
 /**
  * Edit tree action
  *
  * @param Request $request
  * @param int     $id
  *
  * @AclAncestor("pim_enrich_category_edit")
  *
  * @return Response
  */
 public function editAction(Request $request, $id)
 {
     $category = $this->findCategory($id);
     $this->eventDispatcher->dispatch(CategoryEvents::PRE_EDIT, new GenericEvent($category));
     $form = $this->createForm('pim_category', $category, $this->getFormOptions($category));
     if ($request->isMethod('POST')) {
         $form->bind($request);
         if ($form->isValid()) {
             $this->categorySaver->save($category);
             $this->addFlash('success', sprintf('flash.%s.updated', $category->getParent() ? 'category' : 'tree'));
             $this->eventDispatcher->dispatch(CategoryEvents::POST_EDIT, new GenericEvent($category));
         }
     }
     return $this->render(sprintf('PimEnrichBundle:CategoryTree:%s.html.twig', $request->get('content', 'edit')), ['form' => $form->createView()]);
 }
Exemplo n.º 24
0
 /**
  * @param Request $request
  * @param string  $code
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have permissions to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $code)
 {
     $group = $this->groupRepository->findOneByIdentifier($code);
     if (null === $group) {
         throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $code));
     }
     $data = json_decode($request->getContent(), true);
     $this->updater->update($group, $data);
     $violations = $this->validator->validate($group);
     if (0 < $violations->count()) {
         $errors = $this->violationNormalizer->normalize($violations, 'internal_api', $this->userContext->toArray());
         return new JsonResponse($errors, 400);
     }
     $this->saver->save($group);
     return new JsonResponse($this->normalizer->normalize($group, 'internal_api', $this->userContext->toArray()));
 }
 /**
  * Edit tree action
  *
  * @param Request $request
  * @param int     $id
  *
  * @throws AccessDeniedException
  *
  * @return Response
  */
 public function editAction(Request $request, $id)
 {
     if (false === $this->securityFacade->isGranted($this->buildAclName('category_edit'))) {
         throw new AccessDeniedException();
     }
     $category = $this->findCategory($id);
     $this->eventDispatcher->dispatch(CategoryEvents::PRE_EDIT, new GenericEvent($category));
     $form = $this->createForm($this->rawConfiguration['form_type'], $category, $this->getFormOptions($category));
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $this->categorySaver->save($category);
             $message = new Message(sprintf('flash.%s.updated', $category->getParent() ? 'category' : 'tree'));
             $this->addFlash('success', $message);
             $this->eventDispatcher->dispatch(CategoryEvents::POST_EDIT, new GenericEvent($category));
         }
     }
     return $this->render(sprintf('PimEnrichBundle:CategoryTree:%s.html.twig', $request->get('content', 'edit')), ['form' => $form->createView(), 'related_entity' => $this->rawConfiguration['related_entity'], 'acl' => $this->rawConfiguration['acl'], 'route' => $this->rawConfiguration['route']]);
 }
 /**
  * @param Request $request
  * @param string  $code
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have right to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $code)
 {
     $variantGroup = $this->repository->findOneByIdentifier($code);
     if (null === $variantGroup) {
         throw new NotFoundHttpException(sprintf('Variant group with code "%s" not found', $code));
     }
     $data = json_decode($request->getContent(), true);
     $data = $this->convertLocalizedAttributes($data);
     $data = $this->variantGroupDataFilter->filterCollection($data, null);
     $this->updater->update($variantGroup, $data);
     $violations = $this->validator->validate($variantGroup);
     $violations->addAll($this->validator->validate($variantGroup->getProductTemplate()));
     $violations->addAll($this->attributeConverter->getViolations());
     if (0 < $violations->count()) {
         $errors = $this->violationNormalizer->normalize($violations, 'internal_api', $this->userContext->toArray() + ['product' => $variantGroup->getProductTemplate()]);
         return new JsonResponse($errors, 400);
     }
     $this->saver->save($variantGroup, ['copy_values_to_products' => true]);
     return new JsonResponse($this->normalizer->normalize($variantGroup, 'internal_api', $this->userContext->toArray() + ['with_variant_group_values' => true]));
 }
 /**
  * Create a new option for a simple/multi-select attribute
  *
  * @param Request $request
  * @param int     $id
  * @param string  $dataLocale
  *
  * @Template("PimEnrichBundle:Attribute:form_options.html.twig")
  * @AclAncestor("pim_enrich_attribute_edit")
  *
  * @return Response
  */
 public function createOptionAction(Request $request, $id, $dataLocale)
 {
     $attribute = $this->findAttributeOr404($id);
     if (!$request->isXmlHttpRequest() || !in_array($attribute->getAttributeType(), $this->choiceAttributeTypes)) {
         return $this->redirectToRoute('pim_enrich_attribute_edit', ['id' => $attribute->getId()]);
     }
     $option = $this->optionManager->createAttributeOption();
     $optionValue = $this->optionManager->createAttributeOptionValue();
     $optionValue->setLocale($dataLocale);
     $optionValue->setValue('');
     $option->addOptionValue($optionValue);
     $attribute->addOption($option);
     $form = $this->createForm('pim_attribute_option_create', $option);
     if ($request->isMethod('POST')) {
         $form->submit($request);
         if ($form->isValid()) {
             $this->optionSaver->save($option);
             $response = ['status' => 1, 'option' => ['id' => $option->getId(), 'label' => $option->setLocale($dataLocale)->__toString()]];
             return new Response(json_encode($response));
         }
     }
     return ['attribute' => $attribute, 'form' => $form->createView()];
 }
 /**
  * Save the Datagrid View received through the $request for the grid with the given $alias.
  *
  * If any errors occur during the writing process, a Json response is sent with {'errors' => 'Error message'}.
  * If success, return a Json response with the id of the saved View.
  *
  * @param Request $request
  * @param string  $alias
  *
  * @return JsonResponse
  */
 public function saveAction(Request $request, $alias)
 {
     $view = $request->request->get('view', null);
     if (null === $view) {
         return new BadRequestHttpException('Parameter "view" needed in the request.');
     }
     if (isset($view['id'])) {
         $creation = false;
         $datagridView = $this->datagridViewRepo->find($view['id']);
     } else {
         $creation = true;
         $user = $this->tokenStorage->getToken()->getUser();
         $datagridView = new DatagridView();
         $datagridView->setOwner($user);
         $datagridView->setDatagridAlias($alias);
         $datagridView->setLabel($view['label']);
     }
     if (null === $datagridView) {
         return new NotFoundHttpException();
     }
     $datagridView->setColumns(explode(',', $view['columns']));
     $datagridView->setFilters($view['filters']);
     $violations = $this->validator->validate($datagridView);
     if ($violations->count()) {
         $messages = [];
         foreach ($violations as $violation) {
             $messages[] = $this->translator->trans($violation->getMessage());
         }
         return new JsonResponse($messages, 400);
     }
     $this->saver->save($datagridView);
     if ($creation) {
         $request->getSession()->getFlashBag()->add('success', new Message('grid.view_selector.flash.created'));
     }
     return new JsonResponse(['id' => $datagridView->getId()]);
 }
 /**
  * Reply to a product comment
  *
  * @param Request $request
  * @param string  $id
  * @param string  $commentId
  *
  * @return JsonResponse
  */
 public function postReplyAction(Request $request, $id, $commentId)
 {
     $product = $this->findProductOr404($id);
     $data = json_decode($request->getContent(), true);
     $data['parent'] = $commentId;
     $reply = $this->commentBuilder->buildComment($product, $this->getUser());
     $form = $this->formFactory->create('pim_comment_comment', $reply, ['is_reply' => true, 'csrf_protection' => false]);
     $form->submit($data, false);
     if ($form->isValid()) {
         $now = new \DateTime();
         $reply->setCreatedAt($now);
         $reply->setRepliedAt($now);
         $comment = $reply->getParent();
         $comment->setRepliedAt($now);
         $this->commentSaver->save($reply);
         return new JsonResponse($this->normalizer->normalize($reply, 'json'));
     }
     $violations = $this->validator->validate($reply);
     $errors = [];
     foreach ($violations as $violation) {
         $errors[$violation->getPropertyPath()] = ['message' => $violation->getMessage(), 'invalid_value' => $violation->getInvalidValue()];
     }
     return new JsonResponse($errors, 400);
 }
 /**
  * Save the variant group and related product template
  *
  * @param GroupInterface $variantGroup
  */
 protected function saveVariantGroup(GroupInterface $variantGroup)
 {
     $this->incrementUpdatedVariantGroupCount($variantGroup);
     $this->groupSaver->save($variantGroup);
 }