/**
  * 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'));
 }
 /**
  * @return GroupInterface
  */
 protected function getGroup()
 {
     $groupId = $this->request->get('id', null);
     if (!$groupId) {
         $groupId = $this->requestParams->get('currentGroup', null);
     }
     $group = $this->groupRepository->find($groupId);
     return $group;
 }
 /**
  * {@inheritdoc}
  */
 public function process($product)
 {
     $actions = $this->getConfiguredActions();
     $variantGroup = $actions['value'];
     $variantGroup = $this->groupRepository->findOneByIdentifier($variantGroup);
     $variantGroup->addProduct($product);
     if (null !== $variantGroup->getProductTemplate()) {
         $this->templateUpdater->update($variantGroup->getProductTemplate(), [$product]);
     }
     if (null === $product || null !== $product && !$this->isProductValid($product)) {
         $this->stepExecution->incrementSummaryInfo('skipped_products');
         return null;
     }
     return $product;
 }
Ejemplo n.º 4
0
 /**
  * Get warning messages to display during the mass edit action
  *
  * @return string[]
  */
 protected function generateWarningMessages()
 {
     $messages = [];
     if (0 === count($this->groupRepository->getAllGroupsExceptVariant())) {
         $messages[] = ['key' => 'pim_enrich.mass_edit_action.add-to-groups.no_group', 'options' => []];
     }
     return $messages;
 }
Ejemplo n.º 5
0
 /**
  * Remove a variant group
  *
  * @param string $code
  *
  * @AclAncestor("pim_enrich_group_remove")
  *
  * @return JsonResponse
  */
 public function removeAction($code)
 {
     $group = $this->groupRepository->findOneByIdentifier($code);
     if (null === $group) {
         throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $code));
     }
     $this->remover->remove($group);
     return new JsonResponse();
 }
 /**
  * @return array
  */
 protected function getAttributeIdsFromProductGroupAxes()
 {
     $attributeIds = [];
     if (null !== ($productGroupId = $this->getProductGroupId())) {
         $group = $this->productGroupRepository->find($productGroupId);
         if ($group->getType()->isVariant()) {
             foreach ($group->getAxisAttributes() as $axis) {
                 $attributeIds[] = $axis->getId();
             }
         }
     }
     return $attributeIds;
 }
 /**
  * {@inheritdoc}
  */
 public function hasAttributeInVariantGroup($productId, $attributeCode)
 {
     $queryBuilder = $this->createQueryBuilder('p')->select('g.id')->leftJoin('p.groups', 'g')->where('p.id = :id')->setParameters(['id' => $productId]);
     $groupIds = $queryBuilder->getQuery()->getScalarResult();
     $groupIds = array_reduce($groupIds, function ($carry, $item) {
         if (isset($item['id'])) {
             $carry[] = $item['id'];
         }
         return $carry;
     }, []);
     if (0 === count($groupIds)) {
         return false;
     }
     return $this->groupRepository->hasAttribute($groupIds, $attributeCode);
 }
 /**
  * Check if the attribute is removable, otherwise throw an exception or redirect
  *
  * @param AttributeInterface $attribute
  *
  * @throws DeleteException For ajax requests if the attribute is not removable
  *
  * @return RedirectResponse|null
  */
 protected function validateRemoval(AttributeInterface $attribute)
 {
     if (AttributeTypes::IDENTIFIER === $attribute->getAttributeType()) {
         $errorMessage = 'flash.attribute.identifier not removable';
         $messageParameters = [];
     } else {
         $groupCount = $this->groupRepository->countVariantGroupAxis($attribute);
         if ($groupCount > 0) {
             $errorMessage = 'flash.attribute.used by groups';
             $messageParameters = ['%count%' => $groupCount];
         }
     }
     if (isset($errorMessage)) {
         if ($this->request->isXmlHttpRequest()) {
             throw new DeleteException($this->translator->trans($errorMessage, $messageParameters));
         } else {
             $this->request->getSession()->getFlashBag()->add('error', new Message($errorMessage, $messageParameters));
             return new RedirectResponse($this->router->generate('pim_enrich_attribute_index'));
         }
     }
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 protected function getResults()
 {
     return new \ArrayIterator($this->repository->getAllGroupsExceptVariant());
 }
 /**
  * Get valid variant groups to display
  *
  * @return array
  */
 public function getVariantGroups()
 {
     return $this->groupRepository->getAllVariantGroups();
 }