/** * Link new product with category from source product * * @param ProductDuplicateAfterEvent $event */ public function onDuplicateAfter(ProductDuplicateAfterEvent $event) { $product = $event->getProduct(); $sourceProduct = $event->getSourceProduct(); $category = $this->getCategoryRepository()->findOneByProduct($sourceProduct); if ($category !== null) { $category->addProduct($product); $objectManager = $this->doctrineHelper->getEntityManager($this->categoryClass); $objectManager->flush(); } }
/** * Copy product prices * * @param ProductDuplicateAfterEvent $event */ public function onDuplicateAfter(ProductDuplicateAfterEvent $event) { $product = $event->getProduct(); $sourceProduct = $event->getSourceProduct(); $productPrices = $this->getProductPriceRepository()->getPricesByProduct($sourceProduct); $objectManager = $this->doctrineHelper->getEntityManager($this->productPriceClass); foreach ($productPrices as $productPrice) { $productPriceCopy = clone $productPrice; $productPriceCopy->setProduct($product); $objectManager->persist($productPriceCopy); } $objectManager->flush(); }