|
- <?php
-
- namespace Lc\CaracoleBundle\EventSubscriber\Product;
-
- use Doctrine\ORM\EntityManagerInterface;
-
- use Lc\CaracoleBundle\Model\Address\AddressInterface;
- use Lc\CaracoleBundle\Model\Product\ProductInterface;
- use Lc\SovBundle\Doctrine\EntityInterface;
- use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
- use Lc\SovBundle\Doctrine\Extension\SortableInterface;
- use Lc\SovBundle\Doctrine\Extension\StatusInterface;
- use Lc\SovBundle\Doctrine\Extension\TreeInterface;
- use Lc\SovBundle\Event\EntityComponentEvent;
- use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
- use Lc\SovBundle\Repository\AbstractRepositoryInterface;
- use Symfony\Component\EventDispatcher\EventSubscriberInterface;
-
- class DuplicateProductEventSubscriber implements EventSubscriberInterface
- {
- protected $em;
- protected $adminUrlGenerator;
-
- public function __construct(EntityManagerInterface $entityManager)
- {
- $this->em = $entityManager;
- }
-
- public static function getSubscribedEvents()
- {
- return [
- EntityComponentEvent::DUPLICATE_EVENT => ['duplicateProductOnDuplicateEvent'],
- ];
- }
-
- public function duplicateProductOnDuplicateEvent(EntityComponentEvent $event)
- {
- $entity = $event->getEntity();
-
- $classMetadata = $this->em->getClassMetadata(get_class($entity));
-
- /*foreach ($classMetadata->getAssociationMappings() as $associationMapping){
- if(in_array(ProductInterface::class, class_implements($associationMapping['targetEntity']))){
-
- /*foreach ($productFamily->getProducts() as $i => $product) {
- $newProduct = clone $product;
- $newProduct->setProductFamily($productFamily);
- $this->em->persist($newProduct);
- $productFamily->addProduct($newProduct);
- }
-
- $methodGet = 'get'.ucfirst($associationMapping['fieldName']);
- $methodSet = 'set'.ucfirst($associationMapping['fieldName']);
- if(method_exists($entity, $methodGet) && method_exists($entity, $methodSet)){
- $newAddress = clone $entity->$methodGet();
- $entity->$methodSet($newAddress);
- $this->em->persist($newAddress);
- }
- }
-
- }*/
- }
-
- }
|