Developer forum

Forum » Development » GetActiveProducts always only returns assortment

GetActiveProducts always only returns assortment

Magnus Holmberg
Reply

Hi,

Dynamicweb.Ecommerce.Services.Products.GetActiveProducts("LANG1", false) seems always to return only products in Assortment even if useAssortments is passed as false.
Using version 9.17.2. 

BR, Magnus


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

I can see that.

That method is marked as obsolete and you should not use it. It will cause issues for you if you have many products.

If you choose to use it still, you can always call Services.Products.ReFactorProductList(products, useAssortments) to apply the assortments of the current logged in user. Or ReFactorProductList(ICollection<Product> products, Currency currency, Country country, StockLocation stockLocation, User user, bool useAssortments) if you are not in a context where a user is present.

 
Magnus Holmberg
Reply

GetActiveProducts is not showing as Obsolete for me, GetAllProducts is marked as Obsolete.

I switched to using GetAllProductsWithoutVariants, is this method ok to use?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Sorry - I looked at product.GetActiveProducts and not Productservice.GetActiveProducts. I was looking at its call stack and it is not in use anymore due to performance issues and later refacs.

In general you should never call methods that returns all products as that is bound to go wrong - could read and load million of records....

GetAllProductsWithoutVariants is a better option if you choose to do it anyway. That method will check for assortment and other settings related to frontend viewing, e.g. active products, products in stock etc. Be aware that this function only works in the context of the frontend - and assortments requires a logged in user (unless the assortment is anonymous)

Can you tell a bit about what you are trying to do - maybe there is a better way. E.g. the index and queries supports assortments and is better suited to handle performance, sorting, paging and filtering.

BR Nicolai

 

 
Magnus Holmberg
Reply

We are fetching some products with Dynamicweb.Ecommerce.Services.Products.GetActiveProducts("LANG1", false).Where(... to filter out products with specific properties. The solution have much to offer in terms of performance etc. and we are ongoing refatoring the solution. We will look into the possibilitie to use Index instead.

BR, Magnus.

 

You must be logged in to post in the forum