Updating sku's so it will synchronize with the product id

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 years ago
Hi
I'm looking for a (non risky) solution for updating all product's sku's (currently there are some products with sku and most without) , all SKU's should be the same as the product ID.
8 years ago
You have to change core code for that. It is not available out of box.
8 years ago
You can edit the database directly with a simple sql script. Just copy the product id field to the sku field. of course backup the database before doing any modifications.
8 years ago
Agree that using SQL is the easiest way. This would set all Skus equal to the Product Id where the Sku is currently NULL or empty:

UPDATE dbo.Product
   SET Sku = Id
WHERE (Sku IS NULL OR Sku = '')
       AND ProductTypeId = 5 --(restrict to simple product type?)
8 years ago
By doing change only in sql it will work on previous product. When you want add new product it will not work. So for working it future product you have to change in core code also.
You have to add this line

product.Sku = product.Id.ToString();


After this line


product = model.ToEntity(product);


In below action methods of Productcontroller of Nop.Admin

[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
        public ActionResult Edit(ProductModel model, bool continueEditing)

and

[HttpPost, ParameterBasedOnFormName("save-continue", "continueEditing")]
        public ActionResult Create(ProductModel model, bool continueEditing)
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.