function it_returns_association_type_field_names($managerRegistry, AssociationTypeRepository $repository, AssociationType $assocType1, AssociationType $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 AssociationType */ 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; }
/** * @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); } } }
/** * Get association types * * @return array */ public function getAssociationTypes() { return $this->repository->findAll(); }