Developer forum

Forum » Development » Avoid having orderlines removed?

Avoid having orderlines removed?

Anders Ebdrup
Anders Ebdrup
Reply

Dear Dynamicweb,

 

We have a situation where a salesperson can create a quote for a user with items that are outside the assortment of the user, and the user should then be able to accept the quote with these items.

When impersonating we can give the salesperson access to items from outside the user's assortment with this subscriber: AssortmentsCalculateUserAssortments, but when the user is going to accept the quote, we cannot figure out have to avoid having these products removed.

My thought is to be able to cancel the remove handling in: RemoveNoneActiveProducts before the line is actually removed. Current snippet from the function

                    If doRemove Then
                        order.OrderLines.Remove(productLine)
                        Services.OrderLines.Delete(productLine.Id)
                        Services.Carts.NotifyCartLineRemoved(productLine, order, True)
                    End If

A second thought would be to know before a cart is loaded in the following section in: LoadCart:

                        Services.Carts.SetCurrentCart(cart, user, orderContext)

                        'Remove cached prices
                        Services.Orders.ClearCachedPrices(cart)

                        'Check if all the products are still available
                        Services.Orders.RemoveNoneActiveProducts(cart, user, orderContext, Common.Context.StockLocation)

                        NotificationManager.Notify(Notifications.Ecommerce.Cart.InitiallyLoaded, New Notifications.Ecommerce.Cart.InitiallyLoadedArgs(cart))

 

Because then we can set a flag in the context and remove it again in: Notifications.Ecommerce.Cart.InitiallyLoaded, a by this flag we can in the AssortmentsCalculateUserAssortments-subscriber extend the user's assortment a aviod having the products removed.

 

Please let me know your thoughts about this?

 

Best regards, Anders


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Sounds awful complicated. Why not add the product to the users assortment in code...? Maybe with a price of 0 or an other indication that the product cannot be purchased if that is a need.

An alternative could be adding a property on an orderline to not remove it (Stock, price, assortment, other rules). That would be more generic for future scenarios.

BR Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Yes, it will be great to have a flag on a product that says, that it should not be removed when performing the check in RemoveNoneActiveProducts. But this should not be cached as it will vary from user to user.

Can that we added easily?

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Sorry for pushing here, but we need to send an estimate to a client for handling this scenario, and the solution is going to the test phase in the beginning of November

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Anders

I have added a property on the orderline so that you can set DisableRemoveFromCartRules=true for each orderline - not the product, but the orderline so it is cart dependent.

Then if this is set to true and the remove rule disabled, it will not get removed. See logic in screen shot.

Attached find a pirate Dynamicweb.Ecommerce.dll v9.9.? for you to test. TFS#86930.

BR Nicolai

Capture.JPG
Votes for this answer: 1
 
Mark Preisler
Reply

Hi Nicolai

I have tried to use this new feature to avoid products being removed from quotes when a product is not in the customer's assortment. But have not been able to make it work.

I listen to the event Ecommerce.Order.State.Changed and test whether the order has been changed to a quote and updates all order lines to DisableRemoveFromCartRules = true. But when I log out from the sales person and log in to the customer to approve the quote, products that are not in the customer's assortment is removed.

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

That property is stateless - so when you logoff and in as an other user, the order is reloaded and that information is gone.

 
Mark Preisler
Reply

Hey Nicolai

 

Thanks for the quick response, I will find another solution then. :)

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Will it be possible to have a notificationsubscriber before "Notifications.Ecommerce.Cart.InitiallyLoaded" as we need to set the right values on DisableRemoveFromCartRules, as the products are removed before we can change these values?

 

See this section from the source code:

        Friend Function LoadCart(user As User, orderContext As OrderContext) As Order
                ...

                        'Check if all the products are still available
                        Services.Orders.RemoveNoneActiveProducts(cart, user, orderContext, Common.Context.StockLocation)

                        NotificationManager.Notify(Notifications.Ecommerce.Cart.InitiallyLoaded, New Notifications.Ecommerce.Cart.InitiallyLoadedArgs(cart))

Best regards,

Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Any update here as our client is waiting for a solution?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Sorry for spamming this thread, but we really need to find a solution here and I know that you are busy with the 9.10 release

 

Best regards, Anders

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

We have to take another approach.

I suggest what you see in the screenshot. An implementation is in the attached pirate 9.9 ecommerce.dll

Screenshot_2021-01-15_153811.JPG
 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

And the config key for cut and paste: /Globalsettings/Ecom/Cart/DoNotDeleteProductsNotInAssortment

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Works?

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

No, it is still not working as the products seems to be removed in the frontend then displaying the quote to the user. Please see the call stack here: https://www.screencast.com/t/NEBgEigjI8wy.

 

Best regards, Anders

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Well - that is because the product service of course takes assortments into consideration.

I am affraid it is not easy to solve. Assortments are all over the place and the entire idea is that if you do not have that product in assortment, forget about buying it.

We probably have to go down many paths to override this and that would be risky business - so you have to find another way to do this...

Sorry, Nicolai

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

I have done some more debugging and what is missing, is to add false to the line here: Services.Products.GetProductById(ProductId, ProductVariantId, Order.LanguageId, False), so it does not use assortments when loading the products in OrderLine.vb. And I cannot see that is should be necessary to load products with assortments as invalid orderlines/products are removed other places in the code.

So can "False" be added here:

        Public Property Product As Product
            Get
                If Not _productsLoaded Then
                    Order.OrderLines.LoadProducts()
                    _productsLoaded = True
                End If

                Dim productFromDatabase As Product = Services.Products.GetProductById(ProductId, ProductVariantId, Order.LanguageId, False)
                If productFromDatabase Is Nothing Then
                    Return New Product()
                End If
                Return productFromDatabase
            End Get
            Set
                If Value Is Nothing Then
                    ProductId = Nothing
                    ProductVariantId = Nothing
                    _isDirty = True
                End If

                If Value IsNot Nothing AndAlso Not String.Equals(ProductId, Value.Id, StringComparison.Ordinal) AndAlso Not String.Equals(ProductVariantId, Value.VariantId, StringComparison.Ordinal) Then
                    ProductId = Value.Id
                    ProductVariantId = Value.VariantId
                    _isDirty = True
                End If
                CachedPrice = Nothing
            End Set
        End Property

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Will my suggestion be possible for you to change?

 

Best regards, Anders

 
Anders Ebdrup
Anders Ebdrup
Reply

Dear Nicolai,

 

Any news here as our client is awaiting a solution?

 

Best regards, Anders

 
Martin Vang Dynamicweb Employee
Martin Vang
Reply

Hi Anders,

Just giving you an update: When I try to do what you suggest, some of our other checks break down. Specifically, if you have a product in a restored cart, it wont respect the assortments of the user on restore after your suggested change. This is too breaking a behavior for us to move forward with it.

I will take a look at the places in our software where we use orderline.Product and review what changes need to be implemented to  get you your fix. It's 154 places, some of which are a bit tricky, though, so please be patient while I dig to see IF it's possible (I assume it will be possible, and you'll get a PBI# when I've confirmed that it can be fixed).

BR

Martin

 

 
Anders Ebdrup
Anders Ebdrup
Reply

Sounds great! Thank you, Martin,

 

I appreciate that you look into the issue!

 
Martin Vang Dynamicweb Employee
Martin Vang
Reply

Hi Anders,

I've created the feature Feature 771: Avoid cart logic regarding removal of products

It should be possible to merge this to the DW9 branch, so I expect it to come there as well. Testing this might take a bit of time, though, as it affects a lot of different things.

You'll get an update here once there is something to download.

BR

Martin

 
Anders Ebdrup
Anders Ebdrup
Reply

Excellent! Thanks! :-)

 

You must be logged in to post in the forum