When trying to replicate Commerce Product exception is thrown, because the column is unique.
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'TCMTV' for key 'sku': INSERT INTO {commerce_product} (revision_id, sku, title, type, language, uid, status, created, changed, data) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => [:db_insert_placeholder_1] => TCMTV [:db_insert_placeholder_2] => Test Custom Mirror TV [:db_insert_placeholder_3] => product [:db_insert_placeholder_4] => und [:db_insert_placeholder_5] => 1 [:db_insert_placeholder_6] => 1 [:db_insert_placeholder_7] => 1422365157 [:db_insert_placeholder_8] => 1422377566 [:db_insert_placeholder_9] => b:0; ) в функции drupal_write_record() (строка 7202 в файле /home/webmaster/domains/d7c.ru/avistv.d7c.ru/includes/common.inc).
What I suggest is to add to the end of SKU date of replication.
Comments
Comment #1
sam152 commentedI was using commerce_autosku at the time of development which handled this situation. I could set the SKU to something random but I'm not sure if that is a good default behaviour, given people who aren't automatically generating SKU's probably need them to represent a catalogue in some way.
Here is the patch, not sure if this will make it in.
Comment #2
artemboikoI think need add some string like "replicate_some_hash". What you think about this?
Comment #3
ASGAlex commentedSam152, could you explain your commerce_autosku configuration for succesfully cloned product? I also use commerce_autosku, but also have this error. The patch fixed it.
Comment #4
arefen commented#1 patch fixed my problem.
Comment #5
shahidbscs commentedYeah #1 fix the problem, thank you
Comment #6
gravisrs commentedPatch #1 is generally bad approach to add random numbers. After cloning one product from another few times you'd have sku like SHIRT1-1111-2222-333-44-5-666-777-888..... and remember that database field is limited characters so you will eventually stuck with exactly same error after few clones. Moreover some modules actually shows SKU by default (invoice printing) so better to keep them "nice".
For better approach I'd suggest to use name like:
[SKU]-[cloned productid]
Of course first we should try to remove "-[current productid]" part to avoid problem described above.
I know that [cloned productid] isn't available at the moment of cloning so it should be created temporarily (eg [SKU]-temp) and then updated in post-cloning.
Would be easiest if replicate module have post-cloning hooks.
Comment #7
ouissla commentedI worked around this issue one a website I'm working on by implementing the following hook in a custom module:
In my case, the base SKUs have no hyphens, so it works by exploding the sku to make sure I always get the "base" sku, and then increment the SKU until I find a unique value.