選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

65 行
2.7KB

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