/**
  * Find a product by its id or return a 404 response
  *
  * @param string $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneByWithValues($id);
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', (string) $id));
     }
     return $product;
 }
 /**
  * Displays completeness for a product
  *
  * @param int $id
  *
  * @return Response
  */
 public function completenessAction($id)
 {
     $product = $this->productRepository->getFullProduct($id);
     $channels = $this->channelRepository->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $locales, $this->userContext->getCurrentLocale()->getCode());
     return $this->templating->renderResponse('PimEnrichBundle:Completeness:_completeness.html.twig', ['product' => $product, 'channels' => $channels, 'locales' => $locales, 'completenesses' => $completenesses]);
 }
 /**
  * Display the products of a group
  *
  * @param string $identifier
  *
  * @return JsonResponse
  *
  * @AclAncestor("pim_enrich_product_index")
  */
 public function listProductsAction($identifier)
 {
     $group = $this->groupRepository->findOneBy(['code' => $identifier]);
     if (!$group) {
         throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $identifier));
     }
     return new JsonResponse($this->normalizer->normalize(['products' => array_values($this->productRepository->getProductsByGroup($group, self::MAX_PRODUCTS)), 'productCount' => $this->productRepository->getProductCountByGroup($group)], 'internal_api'));
 }
 /**
  * Find a product by its id or return a 404 response
  *
  * @param int $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneById($id);
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', $id));
     }
     $this->productBuilder->addMissingAssociations($product);
     return $product;
 }
 /**
  * @return array
  */
 protected function prepareParameters()
 {
     $queryParameters = parent::prepareParameters();
     $variantGroupId = $queryParameters['currentGroup'];
     if (null !== $variantGroupId) {
         $productIds = $this->productRepository->getEligibleProductIdsForVariantGroup($variantGroupId);
         if (count($productIds) === 0) {
             $productIds = [0];
         }
     } else {
         $productIds = [0];
     }
     $queryParameters['productIds'] = $productIds;
     return $queryParameters;
 }
 /**
  * Get matching products for variant group
  *
  * @param GroupInterface $variantGroup the variant group
  *
  * @return ProductInterface[]
  */
 protected function getMatchingProductsForVariantGroup(GroupInterface $variantGroup)
 {
     if (!$variantGroup->getId()) {
         return [];
     }
     return $this->repository->findAllForVariantGroup($variantGroup);
 }
 /**
  * Inject current product in the datagrid configuration
  */
 protected function addCurrentProduct()
 {
     $path = $this->getSourcePath(self::CURRENT_PRODUCT_KEY);
     $id = $this->requestParams->get('product', null);
     $product = null !== $id ? $this->productRepository->findOneByWithValues($id) : null;
     $this->configuration->offsetSetByPath($path, $product);
 }
 /**
  * @return ProductInterface
  */
 protected function getCurrentProduct()
 {
     $productId = $this->extractor->getDatagridParameter('product');
     if (!$productId) {
         throw new \LogicException('The current product type must be configured');
     }
     $product = $this->productRepository->findOneByWithValues($productId);
     return $product;
 }
 /**
  * Find a product by its id or return a 404 response
  *
  * @param string $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneByWithValues($id);
     $product = $this->objectFilter->filterObject($product, 'pim.internal_api.product.view') ? null : $product;
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', $id));
     }
     return $product;
 }
 /**
  * Find previous sequential edit entity
  *
  * @param SequentialEdit $sequentialEdit
  * @param int            $currentKey
  *
  * @return null|ProductInterface
  */
 protected function findPrevious(SequentialEdit $sequentialEdit, $currentKey)
 {
     $previous = null;
     $objectSet = $sequentialEdit->getObjectSet();
     while ($currentKey-- > 0 && null === $previous) {
         $previous = $this->productRepository->findOneByWithValues($objectSet[$currentKey]);
     }
     return $previous;
 }
 /**
  * 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'));
 }
 /**
  * @param ProductInterface $product
  * @param $attributeCode
  *
  * @return bool
  */
 protected function isAttributeEditable(ProductInterface $product, $attributeCode)
 {
     if (!$this->productRepository->hasAttributeInFamily($product->getId(), $attributeCode)) {
         return false;
     }
     if ($this->productRepository->hasAttributeInVariantGroup($product->getId(), $attributeCode)) {
         return false;
     }
     return true;
 }
Exemplo n.º 13
0
 /**
  * Find a product by its id or return a 404 response
  *
  * @param int $id the product id
  *
  * @throws NotFoundHttpException
  *
  * @return ProductInterface
  */
 protected function findProductOr404($id)
 {
     $product = $this->productRepository->findOneByWithValues($id);
     if (!$product) {
         throw new NotFoundHttpException(sprintf('Product with id %s could not be found.', (string) $id));
     }
     // With this version of the form we need to add missing values from family
     $this->productBuilder->addMissingProductValues($product);
     $this->productBuilder->addMissingAssociations($product);
     return $product;
 }
Exemplo n.º 14
0
 /**
  * {@inheritdoc}
  */
 public function process($group)
 {
     $this->form->setData($group);
     if ($this->request->isMethod('POST')) {
         // TODO : how to fix this ? Load products when ODM storage is used to enable validation
         if (null === $group->getProducts()) {
             $products = $this->productRepository->findAllForGroup($group)->toArray();
             $group->setProducts($products);
         }
         $this->form->submit($this->request);
         if ($this->form->isValid()) {
             $this->onSuccess($group);
             return true;
         } elseif ($group->getType()->isVariant() && $group->getId()) {
             $products = $this->productRepository->findAllForVariantGroup($group);
             $group->setProducts($products);
         }
     }
     return false;
 }
 /**
  * Clean the filters to keep only non duplicated.
  * This method send "skipped" message for every duplicated product for a variant group.
  *
  * When all the selected products are skipped, there is no remaining products to mass-edit. The standard behaviour
  * should return a single filter like "id IN ()", which is equivalent to "nothing", and it's it is very poorly
  * managed by Doctrine.
  * Instead of returning this filter, we return a "is IS NULL" filter, which in this case is completely
  * equivalent to "nothing" (there can not be null ids).
  *
  * @param StepExecution $stepExecution
  * @param array         $filters
  * @param array         $actions
  *
  * @return array
  */
 public function clean(StepExecution $stepExecution, $filters, $actions)
 {
     $variantGroupCode = $actions['value'];
     $variantGroup = $this->groupRepository->findOneByIdentifier($variantGroupCode);
     $axisAttributeCodes = $this->getAxisAttributeCodes($variantGroup);
     $eligibleProductIds = $this->productRepository->getEligibleProductIdsForVariantGroup($variantGroup->getId());
     $cursor = $this->getProductsCursor($filters);
     $paginator = $this->paginatorFactory->createPaginator($cursor);
     list($productAttributeAxis, $acceptedIds) = $this->filterDuplicateAxisCombinations($stepExecution, $paginator, $eligibleProductIds, $axisAttributeCodes);
     $excludedIds = $this->addSkippedMessageForDuplicatedProducts($stepExecution, $productAttributeAxis);
     $acceptedIds = array_diff($acceptedIds, $excludedIds);
     if (0 === count($acceptedIds)) {
         return [['field' => 'id', 'operator' => Operators::IN_LIST, 'value' => ['']]];
     }
     return [['field' => 'id', 'operator' => Operators::IN_LIST, 'value' => $acceptedIds]];
 }
Exemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function collect()
 {
     return ['nb_channels' => $this->channelRepository->countAll(), 'nb_locales' => $this->localeRepository->countAllActivated(), 'nb_products' => $this->productRepository->countAll(), 'nb_attributes' => $this->attributeRepository->countAll(), 'nb_families' => $this->familyRepository->countAll(), 'nb_users' => $this->userRepository->countAll()];
 }
 function it_does_not_validate_with_empty_value(ProductRepositoryInterface $productRepository, ProductValueInterface $value, ExecutionContextInterface $context, Constraint $constraint)
 {
     $productRepository->valueExists($value)->shouldNotBeCalled();
     $context->buildViolation(Argument::any())->shouldNotBeCalled();
     $this->validate("", $constraint)->shouldReturn(null);
 }
 /**
  * Prepare available attribute ids
  *
  * @param array $productIds
  */
 protected function prepareAvailableAttributeIds($productIds)
 {
     $this->attributeIds = $this->productRepository->getAvailableAttributeIdsToExport($productIds);
 }
 /**
  * @param ProductValueInterface $productValue
  *
  * @return bool
  */
 protected function alreadyExists(ProductValueInterface $productValue)
 {
     return $this->repository->valueExists($productValue);
 }