4

We need to clone a product in Akeneo 1.4 (only the SKU should change).

I've found a similar questions (1, 2) in the Akeneo forum, but no answer for the most interesting parts:

  • clone product (PimCatalogProduct)
  • clone product values list (PimCatalogProductValue) and attributes
  • ...

Should I use ProductPropertyCopier, ProductTemplateBuilder, ... for this?

Do the target attributes already need to exists when using theProductPropertyCopier?

Is there now in Akeneo 1.4 an easier way to clone a product?

Sonson123
  • 10,879
  • 12
  • 54
  • 72

1 Answers1

3

Akeneo does not come with a native way to duplicate products but it's a common need and we are aware of this problem we may prioritise it in the future.

The easiest way to duplicate a product is to normalize it and denormalize it right after that:

$normalizedProduct = $this->serializer->normalize($sourceProduct, 'csv');
$duplicatedProduct = $this->serializer->denormalize(
    $normalizedProduct,
    'Pim\Bundle\CatalogBundle\Model\Product',
    'csv',
    [
         'entity' => new Pim\Bundle\CatalogBundle\Model\Product()
    ]
);

// You can now modify the product identifier :)

$this->productSaver->save($duplicatedProduct);

Your product is now duplicated and ready to be used !

Julien Sanchez
  • 843
  • 4
  • 12
  • Great, I didn't expected such a simple solution, thanks! – Sonson123 Nov 20 '15 at 14:59
  • The `denormalize` doesn't work like this with Akeneo 1.5: "Could not denormalize object of type Pim\Bundle\CatalogBundle\Model\Product, no supporting normalizer found.". Could you give me a hint, how I can migrate this to Akeneo 1.5? – Sonson123 Mar 17 '16 at 08:57
  • 1
    From Ronan in the Akeneo forum: "the method still works, bu the Product class has been moved. try changing Pim\Bundle\CatalogBundle\Model\Product to Pim\Component\Catalog\Model\Product in your code." – Sonson123 Apr 04 '16 at 13:50