duplicate entry on using commerce_product_ui_product_type_save()? Reference to the code https://www.drupal.org/node/1059624#comment-4083864

 $product_type = commerce_product_ui_product_type_new();

  $product_type['type'] = 'prestation';
  $product_type['name'] = t('Prestation');
  $product_type['description'] = t('A basic prestation.');
  $product_type['is_new'] = TRUE;

  commerce_product_ui_product_type_save($product_type, FALSE);


When I execute the folllowing code given above I get a 


  PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062
  Duplicate entry 'prestation' for key 'PRIMARY': INSERT INTO
  {commerce_product_type} (type, name, description, help, revision)
  VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1,
  :db_insert_placeholder_2, :db_insert_placeholder_3,
  :db_insert_placeholder_4); Array ( [:db_insert_placeholder_0] =>
  abcs_new15 [:db_insert_placeholder_1] => abcs new15
  [:db_insert_placeholder_2] => abcs new15 [:db_insert_placeholder_3] =>
  [:db_insert_placeholder_4] => 1 ) in drupal_write_record() (line 7239
  of
You are getting the error because you are setting $product_type['is_new'] to TRUE, which is saying to the module the product type is new, but that evidently is not true. That is what the error is telling you.

Set $product_type['is_new'] to FALSE, or don't set it at all, and you will not get any error.

If you are programmatically creating new product types, be sure you give to $product_type['type'] a unique value for each of the product types you create.

Reference


commerce_product_ui_product_type_save()