function it_returns_association_type_field_names($managerRegistry, AssociationTypeRepositoryInterface $repository, AssociationTypeInterface $assocType1, AssociationTypeInterface $assocType2)
 {
     $assocType1->getCode()->willReturn("ASSOC_TYPE_1");
     $assocType2->getCode()->willReturn("ASSOC_TYPE_2");
     $repository->findAll()->willReturn([$assocType1, $assocType2]);
     $managerRegistry->getRepository(self::ASSOC_TYPE_CLASS)->willReturn($repository);
     $this->getAssociationFieldNames()->shouldReturn(["ASSOC_TYPE_1-groups", "ASSOC_TYPE_1-products", "ASSOC_TYPE_2-groups", "ASSOC_TYPE_2-products"]);
 }
 /**
  * Remove associated products from a list of product ids
  *
  * @param GenericEvent $event
  */
 public function removeAssociatedProducts(GenericEvent $event)
 {
     $productIds = $event->getSubject();
     $assocTypeCount = $this->assocTypeRepository->countAll();
     foreach ($productIds as $productId) {
         $this->productRepository->removeAssociatedProduct($productId, $assocTypeCount);
     }
 }
 /**
  * @return AssociationTypeInterface
  */
 protected function getAssociationType()
 {
     $params = $this->extractor->getDatagridParameter(RequestParameters::ADDITIONAL_PARAMETERS, []);
     $associationTypeId = isset($params['associationType']) ? $params['associationType'] : null;
     if (!$associationTypeId) {
         $associationTypeId = $this->extractor->getDatagridParameter('associationType');
     }
     if (!$associationTypeId) {
         throw new \LogicException('The current association type must be configured');
     }
     $associationType = $this->assocTypeRepository->findOneBy(['id' => $associationTypeId]);
     return $associationType;
 }
 /**
  * Get the association field names
  *
  * @return array
  */
 public function resolveAssociationColumns()
 {
     if (empty($this->associationFieldsCache)) {
         $fieldNames = [];
         $assocTypes = $this->associationTypeRepo->findAll();
         foreach ($assocTypes as $assocType) {
             $fieldNames[] = $assocType->getCode() . self::GROUP_ASSOCIATION_SUFFIX;
             $fieldNames[] = $assocType->getCode() . self::PRODUCT_ASSOCIATION_SUFFIX;
         }
         $this->associationFieldsCache = $fieldNames;
     }
     return $this->associationFieldsCache;
 }
 /**
  * @param ProductInterface $product
  */
 public function ensureAllAssociationTypes(ProductInterface $product)
 {
     $missingAssocTypes = $this->assocTypeRepository->findMissingAssociationTypes($product);
     if (!empty($missingAssocTypes)) {
         foreach ($missingAssocTypes as $associationType) {
             $association = new Association();
             $association->setAssociationType($associationType);
             $product->addAssociation($association);
         }
     }
 }
 /**
  * Edit an association type
  *
  * @param int     $id
  *
  * @Template
  * @AclAncestor("pim_enrich_associationtype_edit")
  *
  * @return array
  */
 public function editAction($id)
 {
     $associationType = $this->assocTypeRepo->find($id);
     if (!$associationType) {
         throw new NotFoundHttpException(sprintf('%s entity not found', 'PimCatalogBundle:AssociationType'));
     }
     if ($this->assocTypeHandler->process($associationType)) {
         $this->request->getSession()->getFlashBag()->add('success', new Message('flash.association type.updated'));
         return new RedirectResponse($this->router->generate('pim_enrich_associationtype_edit', ['id' => $id]));
     }
     $usageCount = $this->assocRepository->countForAssociationType($associationType);
     return ['form' => $this->assocTypeForm->createView(), 'usageCount' => $usageCount];
 }
 /**
  * Prepare fields list for CSV headers
  *
  * @param array $attributesList
  *
  * @return array
  */
 protected function prepareFieldsList(array $attributesList = [])
 {
     $fieldsList = $this->prepareAttributesList($attributesList);
     $fieldsList[] = ProductNormalizer::FIELD_FAMILY;
     $fieldsList[] = ProductNormalizer::FIELD_CATEGORY;
     $fieldsList[] = ProductNormalizer::FIELD_GROUPS;
     $associationTypes = $this->assocTypeRepo->findAll();
     foreach ($associationTypes as $associationType) {
         $fieldsList[] = sprintf('%s-groups', $associationType->getCode());
         $fieldsList[] = sprintf('%s-products', $associationType->getCode());
     }
     return $fieldsList;
 }
 /**
  * Display association grids
  *
  * @param Request $request the request
  * @param int     $id      the product id (owner)
  *
  * @AclAncestor("pim_enrich_associations_view")
  *
  * @return Response
  */
 public function associationsAction(Request $request, $id)
 {
     $product = $this->findProductOr404($id);
     $associationTypes = $this->assocTypeRepository->findAll();
     return $this->templating->renderResponse('PimEnrichBundle:Association:_associations.html.twig', ['product' => $product, 'associationTypes' => $associationTypes, 'dataLocale' => $request->get('dataLocale', null)]);
 }
 /**
  * @return JsonResponse
  */
 public function indexAction()
 {
     $associationTypes = $this->associationTypeRepo->findAll();
     $data = $this->normalizer->normalize($associationTypes, 'internal_api');
     return new JsonResponse($data);
 }
 /**
  * Get association types
  *
  * @return array
  */
 public function getAssociationTypes()
 {
     return $this->repository->findAll();
 }