Hi.

I am trying to import some commerce products but i get this message

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_product-2462' for key 1

In my csv file i only have one row to import and here is a part of the import process log

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_product-2462' for key 1
Original item
array (
'fldgiftid' => '10768900009',
'fldgifttitle' => 'My product Test1',
'fldgiftsubtitle' => 'teststtsts',
'fldgiftlocationdetails' => 'test ets tsts ',
'fldgiftcontactid' => '2',
'fldgifthasgiftsuprise' => '-1',
'fldgiftsupriseid' => '4',
)

Entity
stdClass::__set_state(array(
'type' => 'products_with_voucher',
'product_id' => '2462',
'uid' => '1',
'status' => 1,
'created' => 1326905059,
'changed' => 1326905059,
'feeds_item' =>
stdClass::__set_state(array(
'entity_id' => '2462',
'entity_type' => 'commerce_product',
'id' => 'commerce_product_importer',
'feed_nid' => 0,
'imported' => 1326905059,
'hash' => '92c9a2adb3da76593e7b0be5d71b76f2',
'url' => '',
'guid' => '',
)),
'sku' => '10768900009',
'title' => 'My product Test1',
'field_location_details' =>
array (
'und' =>
array (
0 =>
array (
'value' => 'Οι υπηρεσίες του συγκεκριμένου δώρου παρέχονται στην Αρχαία Αγορά στο κέντρο της Αθήνας. ',
'format' => 'plain_text',
),
),
),

any idea what seems to be the problem? I have done all the appropriate mappings and the sku's used for the import process are unique,

Thank you.

Comments

rfay’s picture

Category: bug » support
Priority: Critical » Normal

You already have that product in your products table I imagine.

frixos12’s picture

No. as i told you the product sku's used for this import process are uinique.

And even so shouldn't update the products with the same sku??

(Using update existing products on commerce product processor settings)

pcambra’s picture

Status: Active » Postponed (maintainer needs more info)

Do you have any existing products?
If you try to import this in a clean install (no content), does it work?
Are you using latest -dev (Jan-14)?

It seems that you've got already a product with that product id, but that shouldn't happen.

Anyways, we need more information to track this problem, things such as an export of the feeds importer and a sample of failing data.

frixos12’s picture

No i dont have any existing products and commerce_product database table is empty. Also using the latest dev version

I have made a test importer using rfay feed example (http://d7.randyfay.com/books/feed).

Here is the export.



$feeds_importer = new stdClass;
$feeds_importer->disabled = FALSE; /* Edit this to true to make a default feeds_importer disabled initially */
$feeds_importer->api_version = 1;
$feeds_importer->id = 'test_importer';
$feeds_importer->config = array(
  'name' => 'Test Importer',
  'description' => 'Test import',
  'fetcher' => array(
    'plugin_key' => 'FeedsHTTPFetcher',
    'config' => array(
      'auto_detect_feeds' => FALSE,
      'use_pubsubhubbub' => FALSE,
      'designated_hub' => '',
    ),
  ),
  'parser' => array(
    'plugin_key' => 'FeedsCSVParser',
    'config' => array(
      'delimiter' => ',',
      'no_headers' => 0,
    ),
  ),
  'processor' => array(
    'plugin_key' => 'FeedsCommerceProductProcessor',
    'config' => array(
      'product_type' => 'products_with_voucher',
      'author' => '1',
      'tax_rate' => 'greek_tax_rate',
      'mappings' => array(
        0 => array(
          'source' => 'SKU',
          'target' => 'sku',
          'unique' => 1,
        ),
        1 => array(
          'source' => 'Title',
          'target' => 'title',
          'unique' => FALSE,
        ),
        2 => array(
          'source' => 'Price',
          'target' => 'commerce_price:amount',
          'unique' => FALSE,
        ),
        3 => array(
          'source' => 'Image',
          'target' => 'field_gift_photos',
          'unique' => FALSE,
        ),
        4 => array(
          'source' => 'Description',
          'target' => 'field_description',
          'unique' => FALSE,
        ),
      ),
      'update_existing' => '2',
      'input_format' => 'plain_text',
    ),
  ),
  'content_type' => '',
  'update' => 0,
  'import_period' => '-1',
  'expire_period' => 3600,
  'import_on_create' => 1,
  'process_in_background' => 0,
);

And here is a part of the log data in the test importer.

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'commerce_product-2564' for key 1
Original item
array (
  'sku' => '0471176494',
  'title' => 'The Computer Consultant\'s Guide: Real-Life Strategies for Building a Successful Consulting Career',
  'price' => '5000',
  'image' => 'http://ecx.images-amazon.com/images/I/51nnXx9tUCL.jpg',
  'description' => 'THE COMPUTER CONSULTANT\'S GUIDEIf you\'re ideas od marketing skills * Find and manage the highest paying clients * Set fees and bid on the big jobs * Handle important tax and accounting issues * Work through brokers with confidence',
  'stock' => '100',
)
Entity
stdClass::__set_state(array(
   'type' => 'products_with_voucher',
   'product_id' => '2564',
   'uid' => '1',
   'status' => 1,
   'created' => 1326964794,
   'changed' => 1326964794,
   'feeds_item' => 
  stdClass::__set_state(array(
     'entity_id' => '2564',
     'entity_type' => 'commerce_product',
     'id' => 'test_importer',
     'feed_nid' => 0,
     'imported' => 1326964794,
     'hash' => '422315c389ea35d07a6fcb37aa50e00b',
     'url' => '',
     'guid' => '',
  )),
   'sku' => '0471176494',
   'title' => 'The Computer Consultant\'s Guide: Real-Life Strategies for Building a Successful Consulting Career',
   'commerce_price' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'currency_code' => 'EUR',
        'amount' => '5000',
        'data' => 
        array (
          'include_tax' => 'greek_tax_rate',
          'components' => 
          array (
          ),
        ),
      ),
    ),
  ),
   'field_gift_photos' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'fid' => '2656',
        'uri' => 'public://Product Images/51nnXx9tUCL.jpg',
        'filename' => '51nnXx9tUCL.jpg',
        'filemime' => 'image/jpeg',
        'uid' => '1',
        'status' => 1,
        'timestamp' => 1326964794,
        'filesize' => 48724,
        'type' => 'image',
        'display' => 1,
        'width' => 328,
        'height' => 500,
      ),
    ),
  ),
   'field_description' => 
  array (
    'und' => 
    array (
      0 => 
      array (
        'value' => 'THE COMPUTER CONSULTANT\'S GUIDEIf you\'re serious al business and marketing skills * Find and manage the highest paying clients * Set fees and bid on the big jobs * Handle important tax and accounting issues * Work through brokers with confidence',
        'format' => 'plain_text',
      ),
    ),
frixos12’s picture

Ok here is another interesting thing i found.

If i choose the default product type that comes with drupal commerce for the imported products, the process completes successfully.

In the mapping settings i have selected the default fields only ( Product Sku , Title, Price), no custom fields.

So when i change back to my custom product type with the same default fields i get the error message above.

Both of tests with no existing products in any product type

Any idea why this is happening?

Also i can add any product of any product type via the product administration form without any errors

rfay’s picture

Status: Postponed (maintainer needs more info) » Active

Good info. Does this happen with the latest stable version? (A new commit that could affect this went in recently)

It would help if you can sort this out a bit more. Does it happen exactly the same with the same import and a new product type? I didn't quite follow that. If you can recreate it exactly with a different product type that has the same fields as the default product type, that's a pretty interesting result.

frixos12’s picture

Finally i found what the problem is.

The problem lies in Rules. I had created two custom rules that react on "after saving a product" and "after updating a product" and calculated some of my product fields which are read-only.

After disabling them, the import process completed successfully. So we can't have rules applied "on saving new products " events during the import process i guess?!

frixos12’s picture

Also during the non-successfull import processes download to my server hunderds of images (each of them had 5 duplicates).

After i removed them from the public file and tried to import one product with the same image source i got a similar error for duplicate files.

As i suspect the file_managed table must be emptied in order to avoid this collision??

rfay’s picture

Status: Active » Fixed

Thanks for sorting that out! It had to be something like that.

You'll need to do something more sophisticated than "emptying" the file_managed table unless this is a new site.

frixos12’s picture

Yes this is a new site in test mode.. so i think it's safe in this mode..

As far as concerning these rules, could these be fixed..?

rfay’s picture

I don't think we can answer that here. You can probably figure it out. But it looks like your rules were actually creating duplicates, not doing updates.

pcambra’s picture

frixos12, thanks for the details, but maybe you could share what those rules actually do

frixos12’s picture

Those rules work just fine when i add a product via the product administration form.

Nevertheless, i maybe open another issue if i dont figure this out. Thanks for your posts.

zeta1600’s picture

Thanks frixos12, emptying the field_managed did it for me.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

SandraVdv’s picture

Status: Closed (fixed) » Active

Emptying file_managed table doesn't seem like a solution to me...
Anyone knows how to fix this issue?
I import product entities and I don't specify the image field in my feed importer mapping but it does try to update the image field? Why is that? I only have the internal path to the image (/sites/default/files/products/productX.jpg) so I can't use that in my feed importer, or am I wrong here?

pcambra’s picture

Status: Active » Closed (fixed)

Please don't reopen issues closed for almost a year, open new ones.

Commerce feeds takes care of the integration of drupal commerce, if the issue is coming from images or other fields than the ones provided by commerce, it's an issue with feeds itself.