/** * @param ProductInterface $product * @param ProductAssociationTypeInterface $productAssociationType * @param array $associatedProducts */ private function createProductAssociation(ProductInterface $product, ProductAssociationTypeInterface $productAssociationType, array $associatedProducts) { /** @var ProductAssociationInterface $productAssociation */ $productAssociation = $this->productAssociationFactory->createNew(); $productAssociation->setType($productAssociationType); foreach ($associatedProducts as $associatedProduct) { $productAssociation->addAssociatedProduct($associatedProduct); } $product->addAssociation($productAssociation); $this->productAssociationRepository->add($productAssociation); }