Developer forum

Forum » Development » Get all products from service regardless of GlobalSettings

Get all products from service regardless of GlobalSettings

Chris Søgaard
Chris Søgaard
Reply

Hi DW

Is there any way to get all products in the database using the product service from Dynamicweb.Ecommerce DLL.

I have checked it and it seems that all versions of GetAllProducts will in the end reach a method in the repository that would filter out products based on these settings in global settings:

  • /Globalsettings/Ecom/Product/DontShowProductIfNotOnStock
  • /Globalsettings/Ecom/Product/DontShowProductIfHasNoPrice
  • /Globalsettings/Ecom/Product/DontAllowLinksToProductIfNotActive

I understand why it would do that, but is there any option to get all products from a shop, languageId or similar, where it doesn't take these settings into account. Or maybe make it optional if you want these settings to be considered or not.

DW version 9.10.13. Dynamicweb.Ecommerce version 1.10.87

BR Chris

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Chris

Yeah, it would do that mostly.

But you can call GetProductById(string productId, string productVariantId, string productLanguageId, bool useAssortments) with useAssortments = false.

Then first find the IDs by querying the database directly

var query = new CommandBuilder();
            query.Add("SELECT EcomProducts.productId, EcomProducts.productVariantId, EcomProducts.productLanguageId  ");
            query.Add("FROM (EcomGroupProductRelation ");
            query.Add("INNER JOIN EcomProducts ON EcomGroupProductRelation.GroupProductRelationProductID = EcomProducts.ProductID) ");
            query.Add("INNER JOIN EcomShopGroupRelation ON EcomGroupProductRelation.GroupProductRelationGroupID = EcomShopGroupRelation.ShopGroupGroupID ");
            query.Add("WHERE (((EcomShopGroupRelation.ShopGroupShopID) = {0})", shopId);
            if (!string.IsNullOrEmpty(productLanguageId))
            {
                query.Add(" AND EcomProducts.ProductLanguageID = {0}", productLanguageId);
            }

            query.Add(")");
            query.Add(" AND (ISNULL(EcomProducts.ProductHidden, 0) <> {0}) ", Database.SqlBool(true));
            query.Add(" ORDER BY EcomProducts.ProductId, EcomProducts.ProductLanguageId, EcomProducts.ProductVariantId ");

Alternatively you can set those 3 settings to false before calling the API and set them back when done. A bit hacky, yes, but might work for your case.

BR Nicolai

 

You must be logged in to post in the forum