Developer forum

Forum » Development » Products in stock - live integration

Products in stock - live integration

Mario Kožić
Reply

Hello,

We need to display a list of products that are in stock. I tried to change a query/index and add that the stock is greater than zero. This works, but the problem is the stock level. The stock comes from the NAV live integration and we do not have any information about the stock during rendering (preparing the index query in ecommerce.dll) the list/pagination after we get the stock information, but that is too late. In this process, we have a list (empty list) or a list where some products are not in stock. This is the situation we need to avoid. How can I create a list of products and paginate it with data from live integration? The stock level depends on the customer (B2C, B2B, B2I, other customer types), the location of the customer, and the stock level of the customer region. The full stock logic is in NAV. Also, with some subscribers we have tried to intercept a process without success. Some types of subscribers we have tried:

[Subscribe(Dynamicweb.Indexing.Notifications.Query.AfterQuery)]
[Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.AfterQuery)][Subscribe(Dynamicweb.Indexing.Notifications.Query.BeforeQuery)]
[Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.BeforeQuery)]
[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.ProductList.BeforePaging)]
[Dynamicweb.Extensibility.Notifications.Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.ProductList.BeforeRender)]
...
DW version 9.15,8
Swift 1.21.0

Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Mario

That is not very simple. In order for that to work, you need to have the stock levels for all products that you potentially need to list. So if the complete list is 10.000 products, you need to calculate the stocklevels for all of them. That will never work very well because of serious performance issues. If your lists are always 'small' i.e. 50 products, you can increase paging size to 50, get all products, calculate stock live and then remove the ones not in stock. But will only work with one page short lists.

Queries work on data that is stored in the index - and if you change the results after the query has been executed, paging, facets, counts etc. will not work anymore. So that is not a good way to go.

So the best way is to calculate stock for all products with intervals - i.e. 15 minutes or 1 hour or whatever in BC/NAV, move that data to DW and update the index, and then use that almost precise information to display the list. Of course it will have some false positives sometimes, but it will work and solve the problem.

BR Nicolai

 
Mario Kožić
Reply

Thank you, Nicolai.
that is the kind of solution that we have considered. We also tried stock calculation based on productGroup, but as you said, too many products - performance issues. I should definitely update DW.

Technical question:
out of curiosity, why this notification is not triggered?
​
namespace xyz.LiveIntegration.NotificationSubscribers
{
    [Subscribe(Dynamicweb.Ecommerce.Notifications.Ecommerce.Querying.BeforeQuery)]
    public class BeforeQueryNotify : NotificationSubscriber
    {
        public override void OnNotify(string notification, NotificationArgs args)
        {
            //some code..
        }
    }
}

 

You must be logged in to post in the forum