Sonson123
Sonson123

Reputation: 11447

Akeneo: Clone a product

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:

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?

Upvotes: 4

Views: 1178

Answers (1)

Julien Sanchez
Julien Sanchez

Reputation: 841

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 !

Upvotes: 3

Related Questions