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.

58 lines
2.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  5. use Lc\CaracoleBundle\Solver\Product\ProductCategorySolver;
  6. use Lc\SovBundle\Translation\FlashBagTranslator;
  7. class ProductCategoryBuilder
  8. {
  9. protected EntityManagerInterface $entityManager;
  10. protected ProductCategorySolver $productCategorySolver;
  11. protected FlashBagTranslator $flashBagTranslator;
  12. public function __construct(EntityManagerInterface $entityManager, ProductCategorySolver $productCategorySolver, FlashBagTranslator $flashBagTranslator)
  13. {
  14. $this->entityManager = $entityManager;
  15. $this->productCategorySolver = $productCategorySolver;
  16. $this->flashBagTranslator = $flashBagTranslator;
  17. }
  18. public function setOnlineIfOnlineProductfamily(ProductCategoryInterface $productCategory)
  19. {
  20. if ($this->productCategorySolver->hasOnlineProductFamily($productCategory)) {
  21. $productCategory->setStatus(1);
  22. $this->entityManager->update($productCategory);
  23. $this->flashBagTranslator->add('success', 'setOnline','ProductCategory', array('%category%'=> $productCategory, '%section%'=> $productCategory->getSection()));
  24. // mise à jour du statut du parent
  25. $productCategoryParent = $productCategory->getParent();
  26. if ($productCategoryParent) {
  27. $productCategoryParent->setStatus(1);
  28. $this->entityManager->update($productCategoryParent);
  29. }
  30. }
  31. }
  32. public function setOfflineIfOfflineProductfamily(ProductCategoryInterface $productCategory)
  33. {
  34. if (!$this->productCategorySolver->hasOnlineProductFamily($productCategory)) {
  35. $productCategory->setStatus(0);
  36. $this->entityManager->update($productCategory);
  37. $this->flashBagTranslator->add('info', 'setOffline','ProductCategory', array('%category%'=> $productCategory, '%section%'=> $productCategory->getSection()));
  38. // mise à jour du statut du parent
  39. $productCategoryParent = $productCategory->getParent();
  40. if ($productCategoryParent && !$this->productCategorySolver->hasOnlineProductFamily($productCategoryParent)) {
  41. $productCategoryParent->setStatus(0);
  42. $this->entityManager->update($productCategoryParent);
  43. }
  44. }
  45. }
  46. }