Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


These support forums are now closed for new topics and comments.
Please head on over to http://eureka.ucommerce.net/ for support.

  • Søren Kottal 712 posts 4570 karma points MVP 6x c-trib
    Feb 20, 2014 @ 13:23
    Søren Kottal
    0

    Programmatically hiding all products of specific definition

    I'm trying to set DisplayOnSite to false on every product of a specific defintion in my solution. I'm a bit of a newbie at .net, so all I can think of is the following code:

     

    var products = Product.Find(x => x.ProductDefinition == pd);
    foreach (var product in products)
    {
    product.DisplayOnSite = false;
    product.Save();
    }

    But it seems to me, like thats a really bad way to do it if you have more than a few products. Is there any better way to set DisplayOnSite to false for every product of a specific definition?

  • Morten Skjoldager 440 posts 1499 karma points
    Feb 20, 2014 @ 15:30
    Morten Skjoldager
    100

    Hi Søren

    You can do it directly in database if you need to do this only once :)

    Otherwise use ObjectFactory.Instance.Resolve<IRepository<Product>>() to save a list of products after you've modified them.

    update uCommerce_Product Set DisplayOnSite = 0 where ProductDefinitionId = 12345
Please Sign in or register to post replies

Write your reply to:

Draft