Selaa lähdekoodia

UpdateProductFamilySectionPropertyEventSubscriber

packProduct
Guillaume 3 vuotta sitten
vanhempi
commit
66168f06a7
2 muutettua tiedostoa jossa 49 lisäystä ja 2 poistoa
  1. +4
    -2
      Builder/Product/ProductFamilySectionPropertyBuilder.php
  2. +45
    -0
      EventSubscriber/Product/UpdateProductFamilySectionPropertyEventSubscriber.php

+ 4
- 2
Builder/Product/ProductFamilySectionPropertyBuilder.php Näytä tiedosto

@@ -24,7 +24,7 @@ class ProductFamilySectionPropertyBuilder
$this->productFamilySectionPropertyStore = $productFamilySectionPropertyStore;
}

public function enable(ProductFamilyInterface $productFamily, SectionInterface $section): void
public function enable(ProductFamilyInterface $productFamily, SectionInterface $section, bool $flush = true): void
{
$productFamilySectionProperty = $this->productFamilySectionPropertyStore
->setSection($section)
@@ -41,7 +41,9 @@ class ProductFamilySectionPropertyBuilder
$this->entityManager->create($productFamilySectionProperty);
}

$this->entityManager->flush();
if($flush) {
$this->entityManager->flush();
}
}

}

+ 45
- 0
EventSubscriber/Product/UpdateProductFamilySectionPropertyEventSubscriber.php Näytä tiedosto

@@ -0,0 +1,45 @@
<?php

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Product\ProductFamilySectionPropertyInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class UpdateProductFamilySectionPropertyEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamilySectionInterface'],
];
}

public function processBeforePersistProductFamilySectionInterface(EntityManagerEvent $event)
{
$productFamilySectionProperty = $event->getEntity();

if($productFamilySectionProperty instanceof ProductFamilySectionPropertyInterface) {
if($productFamilySectionProperty->getStatus() == 1) {
$productCategoryArray = $productFamilySectionProperty->getProductFamily()->getProductCategories();
foreach($productCategoryArray as $productCategory) {
$productCategory->setStatus(1);
$this->entityManager->update($productCategory);
}
}
}

$this->entityManager->flush();
}

}

Loading…
Peruuta
Tallenna