Akeneo: Clone a product

情到浓时终转凉″ 提交于 2019-12-12 18:35:59

问题


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?


回答1:


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 !



来源:https://stackoverflow.com/questions/33823406/akeneo-clone-a-product

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!