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.

ProductCategoryBuilder.php 2.7KB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if(!$productCategory->getStatus()) {
  22. $productCategory->setStatus(1);
  23. $this->entityManager->update($productCategory);
  24. $this->flashBagTranslator->add('success', 'setOnline', 'ProductCategory', array('%category%' => $productCategory, '%section%' => $productCategory->getSection()));
  25. }
  26. // mise à jour du statut du parent
  27. $productCategoryParent = $productCategory->getParent();
  28. if ($productCategoryParent) {
  29. if(!$productCategory->getStatus()) {
  30. $productCategoryParent->setStatus(1);
  31. $this->entityManager->update($productCategoryParent);
  32. }
  33. }
  34. }
  35. }
  36. public function setOfflineIfOfflineProductfamily(ProductCategoryInterface $productCategory)
  37. {
  38. if (!$this->productCategorySolver->hasOnlineProductFamily($productCategory)) {
  39. if($productCategory->getStatus()) {
  40. $productCategory->setStatus(0);
  41. $this->entityManager->update($productCategory);
  42. $this->flashBagTranslator->add('info', 'setOffline', 'ProductCategory', array('%category%' => $productCategory, '%section%' => $productCategory->getSection()));
  43. }
  44. // mise à jour du statut du parent
  45. $productCategoryParent = $productCategory->getParent();
  46. if ($productCategoryParent && !$this->productCategorySolver->hasOnlineProductFamily($productCategoryParent)) {
  47. if($productCategory->getStatus()) {
  48. $productCategoryParent->setStatus(0);
  49. $this->entityManager->update($productCategoryParent);
  50. }
  51. }
  52. }
  53. }
  54. }