productAccessoryRepository = $this->loadService(ProductAccessoryRepository::class); } public function instanciateAccessory(Producer $producer): Accessory { $accessory = new Accessory(); $accessory->setProducer($producer); return $accessory; } public function initSelectedProductsIds(Accessory $accessory): void { $selectedProductsIdsArray = []; $productAccessoriesArray = $this->productAccessoryRepository->findProductAccessoriesByAccessory($accessory); foreach($productAccessoriesArray as $productAccessory) { $selectedProductsIdsArray[] = $productAccessory->getProduct()->id; } $accessory->setSelectedProductsIds($selectedProductsIdsArray); } }