Akeneo: Clone a product

2019-08-09 01:45发布

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
1条回答
等我变得足够好
2楼-- · 2019-08-09 02:10

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 !

查看更多
登录 后发表回答