/** * @param AssociationInterface $association * @param array $productsIdentifiers */ protected function addAssociatedProducts(AssociationInterface $association, $productsIdentifiers) { foreach ($productsIdentifiers as $productIdentifier) { $associatedProduct = $this->productRepository->findOneByIdentifier($productIdentifier); if (null === $associatedProduct) { throw InvalidArgumentException::expected('associations', 'existing product identifier', 'adder', 'association', $productIdentifier); } $association->addProduct($associatedProduct); } }