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?
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 !