You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
- <?php
-
- namespace domain\Product\Accessory;
-
- use domain\_\AbstractBuilder;
- use domain\Producer\Producer\Producer;
- use domain\Product\ProductAccessory\ProductAccessoryRepository;
-
- class AccessoryBuilder extends AbstractBuilder
- {
- protected ProductAccessoryRepository $productAccessoryRepository;
-
- public function loadDependencies(): void
- {
- $this->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);
- }
- }
|