/** * 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' => $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; }
/** * Find a variant group by its id or return a 404 response * * @param int $id * * @throws NotFoundHttpException * * @return GroupInterface */ protected function findVariantGroupOr404($id) { $group = $this->groupRepository->find($id); if (!$group || !$group->getType()->isVariant()) { throw new NotFoundHttpException(sprintf('Variant group with id %d could not be found.', $id)); } return $group; }
/** * 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; }
/** * {@inheritdoc} */ public function process($product) { $configuration = $this->getJobConfiguration(); if (!array_key_exists('actions', $configuration)) { throw new InvalidArgumentException('Missing configuration for \'actions\'.'); } $actions = $configuration['actions']; $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; }
/** * Returns all variant groups with common attributes with selected $products * * @param array $products * * @return array */ protected function getVariantGroupsWithCommonAttributes(array $products) { $validVariantGroups = []; if ($products) { $productIds = array_map(function (ProductInterface $product) { return $product->getId(); }, $products); $commonAttributeIds = $this->productMassActionRepo->findCommonAttributeIds($productIds); $validVariantGroups = $this->groupRepository->getVariantGroupsByAttributeIds($commonAttributeIds); } return $validVariantGroups; }
/** * @return array */ protected function getAttributeIdsFromProductGroupAxes() { $attributeIds = []; if (null !== ($productGroupId = $this->getProductGroupId()) && null !== $this->productGroupRepository) { $group = $this->productGroupRepository->find($productGroupId); if ($group->getType()->isVariant()) { foreach ($group->getAxisAttributes() as $axis) { $attributeIds[] = $axis->getId(); } } } return $attributeIds; }
/** * 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 \Symfony\Component\HttpFoundation\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->getRequest()->isXmlHttpRequest()) { throw new DeleteException($this->getTranslator()->trans($errorMessage, $messageParameters)); } else { $this->addFlash($errorMessage, $messageParameters); return $this->redirectToRoute('pim_enrich_attribute_index'); } } }
/** * Get valid variant groups to display * * @return array */ public function getVariantGroups() { return $this->groupRepository->getAllVariantGroups(); }
/** * {@inheritdoc} */ protected function readItems() { return $this->repository->getAllGroupsExceptVariant(); }