No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

UpdateProductFamilySectionPropertyEventSubscriber.php 2.1KB

hace 3 años
hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Lc\CaracoleBundle\EventSubscriber\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
  5. use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class UpdateProductFamilySectionPropertyEventSubscriber implements EventSubscriberInterface
  8. {
  9. protected EntityManagerInterface $entityManager;
  10. public function __construct(EntityManagerInterface $entityManager)
  11. {
  12. $this->entityManager = $entityManager;
  13. }
  14. public static function getSubscribedEvents()
  15. {
  16. return [
  17. EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
  18. EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
  19. ];
  20. }
  21. public function processBeforePersistProductFamilySectionInterface(EntityManagerEvent $event)
  22. {
  23. $productFamilySectionProperty = $event->getEntity();
  24. if($productFamilySectionProperty instanceof ProductFamilySectionPropertyInterface) {
  25. $section = $productFamilySectionProperty->getSection();
  26. if($productFamilySectionProperty->getStatus() == 1) {
  27. $productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories();
  28. foreach($productCategoryArray as $productCategory) {
  29. if($productCategory->getSection() == $section) {
  30. // mise à jour du statut
  31. $productCategory->setStatus(1);
  32. $this->entityManager->update($productCategory);
  33. // mise à jour du statut du parent
  34. $productCategoryParent = $productCategory->getParent();
  35. if($productCategoryParent) {
  36. $productCategoryParent->setStatus(1);
  37. $this->entityManager->update($productCategoryParent);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }
  44. }