Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

35 lines
1.1KB

  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. }