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.

AccessoryBuilder.php 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace domain\Product\Accessory;
  3. use domain\_\AbstractBuilder;
  4. use domain\Producer\Producer\Producer;
  5. use domain\Product\ProductAccessory\ProductAccessoryRepository;
  6. class AccessoryBuilder extends AbstractBuilder
  7. {
  8. protected ProductAccessoryRepository $productAccessoryRepository;
  9. public function loadDependencies(): void
  10. {
  11. $this->productAccessoryRepository = $this->loadService(ProductAccessoryRepository::class);
  12. }
  13. public function instanciateAccessory(Producer $producer): Accessory
  14. {
  15. $accessory = new Accessory();
  16. $accessory->setProducer($producer);
  17. return $accessory;
  18. }
  19. public function initSelectedProductsIds(Accessory $accessory): void
  20. {
  21. $selectedProductsIdsArray = [];
  22. $productAccessoriesArray = $this->productAccessoryRepository->findProductAccessoriesByAccessory($accessory);
  23. foreach($productAccessoriesArray as $productAccessory) {
  24. $selectedProductsIdsArray[] = $productAccessory->getProduct()->id;
  25. }
  26. $accessory->setSelectedProductsIds($selectedProductsIdsArray);
  27. }
  28. }