Developer forum

Forum » Dynamicweb 9.0 Upgrade issues » OrderSearchFilter pulling seemingly random orders

OrderSearchFilter pulling seemingly random orders

Kevin Byrd
Kevin Byrd
Reply

Hello everyone,

I am trying to pull all products ordered within the past 13months.  Utilizing an OrderSearchFilter seems to yeild the same 4-5 products regardless of user, and those products have no coorelating orders.  Seemingly a random set of products.

When using OrderSearchFilter, I am getting those results when adding CustomerNumber to the constructor.  If I use CustomerId, it will yeild no results.  Am I missing something?


Replies

 
Nicolai Pedersen
Reply

I cannot see your context where this code executes or what data you have in your database.

Here is an example of how we do it:

if (userId > 0)
{
    var filter = new OrderSearchFilter();
    filter.CustomerId = userId;
    filter.IsCart = true;
    filter.Completed = OrderSearchFilter.CompletedStates.NotCompleted;
    filter.PageNumber = CurrentPage;
    filter.PageSize = PageSize;
    filter.OrderBy = $"OrderDate DESC";
    foreach (var order in Services.Orders.GetOrdersBySearch(filter).ResultOrders)
    {
        //...
    }
}

It requires that the orders have OrderCustomerAccessUserID or OrderSecondaryUserId set to the id you pass as CustomerID.

BR Nicolai

 
Kevin Byrd
Kevin Byrd
Reply

Thanks Nicolai,

Sorry for not providing more details, but an example of it being used is exactly what I needed.  If it requires the use of the customerId, what is the purpose of providing the customerNumber?

 

Thanks,

Kevin

 
Nicolai Pedersen
Reply

Customer number is different. 2 users can share customer number - that is the account number. So using customer number, if set on the user when making the purchase, would give you orders across several users.

BR Nicolai

 
Kevin Byrd
Kevin Byrd
Reply

Nicolai, In this instance we actually want to be able pull orders from mulitple users if they share the same customer number.  Is there a work around for this?

 
Nicolai Pedersen
Reply

It also works with customer number. We do that our selves as well.

The order objects in the database have to have the customer number on them though.

So if the order objects only have userid and the users on the user database have customer number, the orders from other users with same customer number is not located.

The orders on the order table will have to have the customer number on them as well.

Could that be the case - that it is missing?

 
Kevin Byrd
Kevin Byrd
Reply

Thanks Nicolai,

Sorry for the delay in response, I wanted to double check some things before posting again.  On this particular project we currently don't utilize OrderCustomerAccessUserId, instead we track OrderCustomerNumber.  However when running the search based upon OrderCustomerNumber, we are given the same 4 products regardless of logged in user.  

 

 

 

 

I ran a SQL query to pull up what should be shown from user CustomerNumber 000100-000100 and it yeilded 2 pages of results: 

 

Hopefully that gives a better picture of the issues we are having.  Does anything stand out to you as a possible issue?

Thanks again,

Kevin

 

 
Nicolai Pedersen
Reply

Yeah, it is not that simple since that method also handles security in terms of what can be seen and not.

Try to set all these properties on your filter:

IncludeImpersonation = False
CustomerID = 123 (This ID has to be of a user that has the below customer number)
CustomerNumber = '000100-001-00'

 
Kevin Byrd
Kevin Byrd
Reply

Thanks Nicolai, we will first need to add userID to the orders then I can try and implement your recommendations.

Thanks,

Kevin

 

You must be logged in to post in the forum