/** * Get the list of all locales * * @return JsonResponse all activated locales */ public function indexAction() { $locales = $this->localeRepository->getActivatedLocales(); $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view'); $normalizedLocales = $this->normalizer->normalize($filteredLocales, 'internal_api'); return new JsonResponse($normalizedLocales); }
/** * Get the attribute collection * * @return JsonResponse */ public function indexAction() { $attributes = $this->attributeRepository->findAll(); $filteredAttributes = $this->collectionFilter->filterCollection($attributes, 'pim.internal_api.attribute.view'); $normalizedAttributes = $this->normalizer->normalize($filteredAttributes, 'internal_api'); return new JsonResponse($normalizedAttributes); }
/** * Filter & return the given $data for the given $type * * @param string $type * @param mixed $data * * @return mixed */ protected function filterData($type, $data) { if ('values' === $type) { $data = $this->productValuesFilter->filterCollection($data, 'pim.internal_api.product_values_data.edit'); } return $data; }
/** * Normalize and return given $locales * * @param $locales * * @return array|\ArrayAccess */ protected function normalizeLocales($locales) { $normalizedLocales = []; foreach ($this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view') as $locale) { $normalizedLocales[] = $this->localeNormalizer->normalize($locale, 'json'); } return $normalizedLocales; }
/** * Normalize the attributes * * @param FamilyInterface $family * * @return array */ protected function normalizeAttributes(FamilyInterface $family) { $filteredAttributes = $this->collectionFilter ? $this->collectionFilter->filterCollection($family->getAttributes(), 'pim.internal_api.attribute.view') : $family->getAttributes(); $normalizedAttributes = []; foreach ($filteredAttributes as $attribute) { $normalizedAttributes[] = $attribute->getCode(); } return $normalizedAttributes; }
/** * Get completeness for a product * * @param int $id * * @return JSONResponse */ public function getAction($id) { $product = $this->productRepository->getFullProduct($id); $this->completenessManager->generateMissingForProduct($product); $channels = $this->channelRepository->getFullChannels(); $locales = $this->userContext->getUserLocales(); $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view'); $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales, $this->userContext->getCurrentLocale()->getCode()); return new JsonResponse($this->completenessNormalizer->normalize($completenesses, 'internal_api')); }
/** * Return the list of all Datagrid Views that belong to the current user for the given $alias grid. * Response data is in Json format and is paginated. * * @param Request $request * @param string $alias * * @return JsonResponse */ public function indexAction(Request $request, $alias) { $user = $this->tokenStorage->getToken()->getUser(); $options = $request->query->get('options', ['limit' => 20, 'page' => 1]); $term = $request->query->get('search', ''); $views = $this->datagridViewRepo->findDatagridViewBySearch($user, $alias, $term, $options); $views = $this->datagridViewFilter->filterCollection($views, 'pim.internal_api.datagrid_view.view'); $normalizedViews = $this->normalizer->normalize($views, 'internal_api'); return new JsonResponse($normalizedViews); }
/** * Normalize the attributes * * @param FamilyInterface $family * * @return array */ protected function normalizeAttributes(FamilyInterface $family) { $attributes = $this->collectionFilter->filterCollection($this->attributeRepository->findAttributesByFamily($family), 'pim.internal_api.attribute.view'); $normalizedAttributes = []; foreach ($attributes as $attribute) { $normalizedAttributes[] = $attribute->getCode(); } sort($normalizedAttributes); return $normalizedAttributes; }
/** * Get attribute group collection * * @return JsonResponse */ public function indexAction() { $attributeGroups = $this->attributeGroupRepo->findAll(); $filteredAttrGroups = $this->collectionFilter->filterCollection($attributeGroups, 'pim.internal_api.attribute_group.view'); $normalizedAttrGroups = []; foreach ($filteredAttrGroups as $attributeGroup) { $normalizedAttrGroups[$attributeGroup->getCode()] = $this->normalizer->normalize($attributeGroup, 'json'); } return new JsonResponse($normalizedAttrGroups); }
/** * Normalize the values of the product * * @param ArrayCollection $values * @param array $context * * @return ArrayCollection */ private function normalizeValues(ArrayCollection $values, array $context = []) { foreach ($context['filter_types'] as $filterType) { $values = $this->filter->filterCollection($values, $filterType, $context); } $data = []; foreach ($values as $value) { $data[$value->getAttribute()->getCode()][] = $this->serializer->normalize($value, 'standard', $context); } return $data; }
/** * Get the attribute collection * * @return JsonResponse */ public function indexAction(Request $request) { $criteria = []; if ($request->query->has('identifiers')) { $criteria['code'] = explode(',', $request->query->get('identifiers')); } if ($request->query->has('types')) { $criteria['attributeType'] = explode(',', $request->query->get('types')); } $attributes = $this->attributeRepository->findBy($criteria); $filteredAttributes = $this->collectionFilter->filterCollection($attributes, 'pim.internal_api.attribute.view'); $normalizedAttributes = $this->normalizer->normalize($filteredAttributes, 'internal_api'); return new JsonResponse($normalizedAttributes); }
/** * @param Request $request * @param string $id * * @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, $id) { $product = $this->findProductOr404($id); if ($this->objectFilter->filterObject($product, 'pim.internal_api.product.edit')) { throw new AccessDeniedHttpException(); } $data = json_decode($request->getContent(), true); try { $data = $this->productEditDataFilter->filterCollection($data, null, ['product' => $product]); } catch (ObjectNotFoundException $e) { throw new BadRequestHttpException(); } // TODO: PEF should never update groups, no way to do so from the screen, if a product is added to // another group during the save, this relation will be removed, other issue is that variant groups are never // passed here, so a product is always removed from it's variant group when saved unset($data['groups']); $data = $this->convertLocalizedAttributes($data); $this->updateProduct($product, $data); $violations = $this->validator->validate($product); $violations->addAll($this->localizedConverter->getViolations()); if (0 === $violations->count()) { $this->productSaver->save($product); return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $this->buildContext())); } else { $errors = $this->transformViolations($violations, $product); return new JsonResponse($errors, 400); } }
/** * Get filtered values * * @param ProductInterface $product * @param array $context * * @return ProductValueInterface[] */ protected function getFilteredValues(ProductInterface $product, array $context = []) { if (null === $this->filter) { return $product->getValues(); } $values = $this->filter->filterCollection($product->getValues(), isset($context['filter_type']) ? $context['filter_type'] : 'pim.transform.product_value.flat', ['channels' => [$context['scopeCode']], 'locales' => $context['localeCodes']]); return $values; }
/** * Normalize the values of the product * * @param ArrayCollection $values * @param string $format * @param array $context * * @return ArrayCollection */ protected function normalizeValues(ArrayCollection $values, $format, array $context = []) { foreach ($context['filter_types'] as $filterType) { $values = $this->filter->filterCollection($values, $filterType, $context); } $data = $this->valuesNormalizer->normalize($values, $format, $context); return $data; }
/** * Get completeness for a product * * @param int|string $id * * @return JSONResponse */ public function getAction($id) { $product = $this->productRepository->getFullProduct($id); if (null === $product->getFamily()) { return new JsonResponse(); } $this->completenessManager->generateMissingForProduct($product); // Product have to be refreshed to have the completeness values generated by generateMissingForProduct() // (on ORM, completeness is not calculated the same way and product doesn't need to be refreshed) if (AkeneoStorageUtilsExtension::DOCTRINE_MONGODB_ODM === $this->storageDriver) { $this->productManager->refresh($product); } $channels = $this->channelRepository->getFullChannels(); $locales = $this->userContext->getUserLocales(); $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view'); $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales); return new JsonResponse($this->compNormalizer->normalize($completenesses, 'internal_api')); }
/** * Normalize the values of the product * * @param ArrayCollection $values * @param string $format * @param array $context * * @return ArrayCollection */ protected function normalizeValues(ArrayCollection $values, $format, array $context = []) { $values = $this->filter->filterCollection($values, isset($context['filter_type']) ? $context['filter_type'] : 'pim.transform.product_value.structured', $context); $data = []; foreach ($values as $value) { $data[$value->getAttribute()->getCode()][] = $this->serializer->normalize($value, $format, $context); } return $data; }
/** * {@inheritdoc} */ public function finalize() { $data = json_decode($this->values, true); $data = $this->filterScopableAndLocalizableData($data, $this->getAttributeLocale(), $this->getAttributeChannel()); $data = $this->productValuesFilter->filterCollection($data, 'pim.internal_api.product_values_data.edit'); $data = $this->delocalizeData($data, $this->userContext->getUiLocale()->getCode()); $data = $this->storeUploadedFile($data); $this->values = json_encode($data); }
/** * Get filtered values * * @param ProductInterface $product * @param array $context * * @return ProductValueInterface[] */ protected function getFilteredValues(ProductInterface $product, array $context = []) { if (null === $this->filter) { return $product->getValues(); } $values = $product->getValues(); foreach ($context['filter_types'] as $filterType) { $values = $this->filter->filterCollection($values, $filterType, ['channels' => [$context['scopeCode']], 'locales' => $context['localeCodes']]); } return $values; }
/** * @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])); }
/** * @param Request $request * @param string $id * * @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, $id) { $product = $this->findProductOr404($id); if ($this->objectFilter->filterObject($product, 'pim.internal_api.product.edit')) { throw new AccessDeniedHttpException(); } $data = json_decode($request->getContent(), true); try { $data = $this->productEditDataFilter->filterCollection($data, null, ['product' => $product]); } catch (ObjectNotFoundException $e) { throw new BadRequestHttpException(); } $this->updateProduct($product, $data); $violations = $this->validator->validate($product); $violations->addAll($this->localizedConverter->getViolations()); if (0 === $violations->count()) { $this->productSaver->save($product); $normalizationContext = $this->userContext->toArray() + ['filter_types' => ['pim.internal_api.product_value.view'], 'disable_grouping_separator' => true]; return new JsonResponse($this->normalizer->normalize($product, 'internal_api', $normalizationContext)); } $errors = ['values' => $this->normalizer->normalize($violations, 'internal_api', ['product' => $product])]; return new JsonResponse($errors, 400); }