Developer forum

Forum » Development » Best way to to check if a product should render

Best way to to check if a product should render

Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

We are importing some ledgers/invoices and all works well. Doing so we have some products that are visible on the website and others that are not (although they are in PIM). For example:

  • Product A - has a Product detail page
  • Product B - does not have a product detail page (only visible in the PIM)

 

Our challenge is to determine when to render the link to the PDP. Using the API we can get the product, but because it's not null, we need to do more. We figured we can check if any of the groups the product belongs to, is a valid group of the shop context (in website settings). 

 

Is there a better way to do this? Something like a IsProductValidForShop method/property?

 

Best Regards,

Nuno Aguiar


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Well, I may have found a simple way to do it, but in any case if anyone has an input, I'd appreciate it

 

public static void IsProductValidForShop(string productId, string variantId) {
    var productGroups = Dynamicweb.Ecommerce.Services.Products.GetProductById(productId, variantId, true);
    var shopGroups = Dynamicweb.Ecommerce.Services.Shops.GetShop(Pageview.Area.EcomShopId).get_Groups(Pageview.Area.EcomLanguageId);

    return shopGroups.Any(g => productGroups.Equals(g));
}

 

Nuno

 

You must be logged in to post in the forum