Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

40 linhas
1.2KB

  1. <?php
  2. namespace domain\Product\RotatingProduct;
  3. use domain\_\AbstractBuilder;
  4. use domain\_\StatusInterface;
  5. use domain\Product\Rotating\Rotating;
  6. class RotatingProductBuilder extends AbstractBuilder
  7. {
  8. protected RotatingProductRepository $rotatingProductRepository;
  9. public function loadDependencies(): void
  10. {
  11. $this->rotatingProductRepository = $this->loadService(RotatingProductRepository::class);
  12. }
  13. public function instanciateRotatingProduct(Rotating $rotating): RotatingProduct
  14. {
  15. $rotatingProduct = new RotatingProduct();
  16. $rotatingProduct
  17. ->setRotating($rotating)
  18. ->setStatus(StatusInterface::STATUS_ONLINE);
  19. return $rotatingProduct;
  20. }
  21. public function initRotatingProductPosition(RotatingProduct $rotatingProduct): RotatingProduct
  22. {
  23. $lastRotatingProduct = $this->rotatingProductRepository->findOneLastRotatingProduct($rotatingProduct->getRotating());
  24. if($lastRotatingProduct) {
  25. $rotatingProduct->setPosition($lastRotatingProduct->getPosition() + 1);
  26. }
  27. else {
  28. $rotatingProduct->setPosition(1);
  29. }
  30. return $rotatingProduct;
  31. }
  32. }