commerce_product_clone, inline_entity_form duplicate uuid problem, whem clone commerce product variant

There are 2 modules allow us to copy commerce product variant.

  1. commerce_product_clone

  2. inline_entity_form

For commerce_product_clone, you can use it in and individual commerce product variant page. But mostly we will prefer to copy with inline form, when we edit commerce product display, clone a variant and attache to current product display.

Unfortunately, both module release versions have not fix uuid duplicate problem.


For commerce_product_clone, you can fix it as below: 

//edit commerce_product_clone/commerce_product_clone.pages.inc add bold two line.

 46 function commerce_product_clone_cloneform($original_product) {

 47   if (isset($original_product->product_id)) {

 48     if (commerce_product_clone_is_permitted($original_product->type)) {

 49       global $user;

 50 

 51       // Reset some values we want to be unique.

 52       $product = clone $original_product;

 53       $product->product_id = NULL;

 54       $product->revision_id = NULL;

 55       $product->uid = $user->uid;

 56       $product->created = NULL;

 57       $product->sku = NULL;

 58       $product->uuid = NULL;

 59       $product->vuuid = NULL;

 60       $product->title = t('Clone of !title', array('!title' => $product->title));


For inline_entity_form, you can fix it as below: 

//edit inline_entity_form/includes/commerce_product.inline_entity_form.inc add bold two line.

337   /**

338    * Overrides EntityInlineEntityFormController::createClone().

339    */

340   public function createClone($entity) {

341     $cloned_entity = parent::createClone($entity);

342     $cloned_entity->sku = NULL;

343     $cloned_entity->uuid = NULL;

344     $cloned_entity->vuuid = NULL;

345 

346     return $cloned_entity;

347   }