Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DuplicateProductEventSubscriber.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace Lc\CaracoleBundle\EventSubscriber\Product;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  5. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  6. use Lc\SovBundle\Doctrine\EntityInterface;
  7. use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
  8. use Lc\SovBundle\Doctrine\Extension\SortableInterface;
  9. use Lc\SovBundle\Doctrine\Extension\StatusInterface;
  10. use Lc\SovBundle\Doctrine\Extension\TreeInterface;
  11. use Lc\SovBundle\Event\EntityComponentEvent;
  12. use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
  13. use Lc\SovBundle\Repository\AbstractRepositoryInterface;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. class DuplicateProductEventSubscriber implements EventSubscriberInterface
  16. {
  17. protected $em;
  18. protected $adminUrlGenerator;
  19. public function __construct(EntityManagerInterface $entityManager)
  20. {
  21. $this->em = $entityManager;
  22. }
  23. public static function getSubscribedEvents()
  24. {
  25. return [
  26. EntityComponentEvent::DUPLICATE_EVENT => ['duplicateProductOnDuplicateEvent'],
  27. ];
  28. }
  29. public function duplicateProductOnDuplicateEvent(EntityComponentEvent $event)
  30. {
  31. $entity = $event->getEntity();
  32. $classMetadata = $this->em->getClassMetadata(get_class($entity));
  33. /*foreach ($classMetadata->getAssociationMappings() as $associationMapping){
  34. if(in_array(ProductInterface::class, class_implements($associationMapping['targetEntity']))){
  35. /*foreach ($productFamily->getProducts() as $i => $product) {
  36. $newProduct = clone $product;
  37. $newProduct->setProductFamily($productFamily);
  38. $this->em->persist($newProduct);
  39. $productFamily->addProduct($newProduct);
  40. }
  41. $methodGet = 'get'.ucfirst($associationMapping['fieldName']);
  42. $methodSet = 'set'.ucfirst($associationMapping['fieldName']);
  43. if(method_exists($entity, $methodGet) && method_exists($entity, $methodSet)){
  44. $newAddress = clone $entity->$methodGet();
  45. $entity->$methodSet($newAddress);
  46. $this->em->persist($newAddress);
  47. }
  48. }
  49. }*/
  50. }
  51. }