accessoryBuilder = $this->loadService(AccessoryBuilder::class); $this->productAccessoryManager = $this->loadService(ProductAccessoryManager::class); $this->productRepository = $this->loadService(ProductRepository::class); } public function createAccessory(Producer $producer, string $name, ?int $quantity): Accessory { $accessory = $this->accessoryBuilder->instanciateAccessory($producer); $accessory->setName($name); $accessory->setQuantity($quantity); $accessory->save(); return $accessory; } public function manageProducts(Accessory $accessory, array $selectedProductsIds = []): void { $this->productAccessoryManager->deleteAllProductAccessoriesByAccessory($accessory); foreach($selectedProductsIds as $selectedProductId) { $product = $this->productRepository->findOneProductById($selectedProductId); if($product) { $this->productAccessoryManager->createProductAccessory($product, $accessory, 1); } } } public function deleteAccessory(Accessory $accessory): bool { foreach($accessory->getProductAccessories() as $productAccessory) { $productAccessory->delete(); } return $accessory->delete(); } }