Developer forum

Forum » Ecommerce - Standard features » Save master product information to variants for all products after

Save master product information to variants for all products after

Mikkel Hammer
Mikkel Hammer
Reply

Hi DW,

We have a customer that has made changes to how their field content should be saved across all variants for their products.
Before it was allow change across all variants, now it's not.
So we need to store the master product information for a lot of fields on the variants for all their products.

The problem is that the field content is manually added by the customer, so we can't just import the products again to fix it, since we don't have the field content information in the product import.

But since the information is already stored on the master product in the database, when we save a master product manually now after the "allow change of field content" setting has been changed, the information is saved across the variants as intended.

Is there another way than manually clicking into each product in the ecommerce and saving them, since the customer has thousand of products.
We need a way to trigger the same save process for every product that the manuel save does.

Best regards,
Mikkel Hammer


Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Mikkel,

There is nothing in the standard application that will do that for you. However, the request has popped up before, and a solution by code could look something like

        private static void SaveAllProducts()
        {
            Dynamicweb.Ecommerce.Products.ProductService ps = new Dynamicweb.Ecommerce.Products.ProductService();
            List<string> languages = new List<string> { "LANG1", "LANG2", "LANG3" };
            foreach (string language in languages)
            {
                foreach (var product in Dynamicweb.Ecommerce.Services.Products.GetAllProducts(language, false))
                {
                    ps.Save(product);
                }
            }
        }

In this case it is a static method called from a scheduled task. Alternatively you can put the same (with some small adjustments due to the context) in a cshtml of a page and simply call the page.

Hope the above helps.

BR
Snedker

 

Votes for this answer: 1
 
Mikkel Hammer
Mikkel Hammer
Reply

Hi Morten,

Thanks for the answer and code snippet, we'll look into creating a scheduled task with it :)

Best regards,
Mikkel Hammer

 

You must be logged in to post in the forum