Developer forum

Forum » Development » Product Copy no product ID

Product Copy no product ID

Jonas Mersholm
Reply

Hi,

When copying a product

                            Dynamicweb.eCommerce.Products.Product NP = new Dynamicweb.eCommerce.Products.Product();
                            NP = E.Copy();

All product attributes are copied over correctly, but the new product is not assigned a product id, it is simply blank which breaks the solution. How come?

 

I tried

Not assigning any product-id, thereby leaving it blank.

Assigning an empty string as ID

NP.ID = string.Empty;

 

None of them works.


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Jonas,

Try this instead:

var newProduct = existingProduct.Clone();
newProduct.ID = "";
newProduct.VariantID = "";
newProduct.Save();

The Copy method tries to save over the original product because of a mix of IDs. This is the reason you can't fix it by assigning empty string after the Copy, because it's too late at that point. The code sample above does almost the same thing as Copy does, except it assigns a new product ID to the clone when it's saved.

I've create a bug report to get the Copy method fixed. Bug number 16045.

- Jeppe

 
Kristian Kirkholt
Reply

Hi Jonas

The bug TFS#16045 Product Copy method tries to overwrite original product

Has now been resolved in Dynamicweb version 8.8.0.0

You are able to find this build in the download section:

http://developer.dynamicweb-cms.com/downloads/dynamicweb-8.aspx

Please contact Dynamicweb Support if you need any additional help regarding this.

Kind Regards
Dynamicweb Support
Kristian Kirkholt

 

You must be logged in to post in the forum