I'm trying to create shared carts between devices based on a CustomerReference.
I can create a new order with a specific customer reference and I can see that I can call AssignToCustomer() on orders, if it doesn't have the correct CustomerReference.
I'm struggling to figure out two things:
How can I see which CustomerReference an order have?
Are there some magic way to make sure that my customer always get's he's or her's CURRENT cart? When the customer visits the page in another browser the cart should be the same.
Number 1. is the most important question I guess. If I know the CustomerReference I can easily switch the order in the cookie.
Number 2 is only if there is an inbuilt functionality for this.
So I guess I only need to know if there's an inbuilt feature for controlling the cart that the user is working on. Fetching the current cart, if there is one.
Yup, your answer to #1 is correct. RE #2 you'd probably want to implement an IOrderFinder. These get called when GetCurrentOrder or GetOrCreateCurrentOrder are called and there is not currently an order in the session. If there isn't on in the session, Vendr then tries all registered IOrderFinder's before finally creating a new order.
For you needs then, you'd probably want to do a search for the most recent open orders by the known customer reference. If you return an order then Vendr will set that as being the current order for the current session and then will use that order from then on.
Looking at this now. Is there any particular reason that the IOrderFinder.FindOrder( string customerReference ) does not take a Store id? Seems like I would need that to find the correct order.
And then maybe a stupid question. I cannot seem to figure out how to add my order finder. I would think it was something like this, but nothing seems to happen:
You're absolutely right that FindOrder should accept a store ID. I've made the change on our open minor release so there should be a 2.2.0-beta0000 on our unstable feed shortly if you want to test this https://nuget.outfield.digital/unstable/vendr/v3/index.json
RE how you go about registering an order finder, you need to have a using Vendr.Extensions statement and a nuget reference to Vendr.Umbraco.Startup and then you'd use the following
Yes. That did the trick.
Looks like it's only called on _vendrApi.GetOrCreateCurrentOrder() and not GetCurrentOrder(), which doesn't take the string customerReference parameter. Shouldn't it work on GetCurrentOrder() as well so the cart from e.g. another browser can be loaded?
Or am I supposed to call GetOrCreateCurrentOrder always when using customerReferences?
Very good point. Pushing an update to our unstable feed now with another GetCurrentOrder method that accepts a customer reference. I've also implemented it such that if the old method is used, then the current member ID is used by default.
From a lookup perspective, in your order finder, I think you might need some logic to ensure that it only finds the current latest order where there isn't a finalized order the occurs after it. You'll basically want to ensure that if there are historic carts for that customer that after checking out order B you don't want it then to claim an old order A that was abandoned before it.
It'll probably be a few minutes whilst our build server builds the new beta build.
And then Deleting the carts that are not the newest one. It's either that or maybe use the
_vendrApi.SearchOrders()
What would be best you think. Maybe there's a third option. I looks like the repositories are protected when it comes to the ones that could return Order objects from at custom sql-query.
PS I'd just make sure you install the specific beta version I mention as we have a number of unstable branches they build too so you want to make sure you install the one I've added the feature to 👍
Ok. So now I got a bit closer, but I want to make sure I do this right.
If my custom IOrderFinder returns null the vendr throws a nullpointer exception in Vendr.Core.Services.OrderService.FindOrder(Guid storeId, string customerReference)
I'm not supposed to create a new order in my IOrderFinder, am I? Seems like that should just result in no cart.
Also it looks like you have an IMembershipHelper.GetCurrentMemberId() that finds the default customerReference, is that correct? Should I implement that as well, so I don't have to get it myself every time I'm calling GetCurrentOrder? I have a few different ways of creating the customerReference, so that would make sense to me.
So IOrderFinder returns an OrderFinderResult. If you are unable to locate an order to return, then you should return OrderFinderResult.Fail() where if you to find an order, you should return OrderFinderResult.Succeed(order). So you should never need to return null.
If you have different ways of getting the current member ID beyond Umbraco's logged in member, then yea, you could replace IMembershipHelper with your own implementation. Just make sure you register it after Vendr has been registered
I like to leave at least a week between releases, which the last release was exactly a week ago today so I can probably look at getting it pushed out today / tomorrow.
All our beta builds are migratable though so you should be fine to use the beta for the immediate time being 👍
How to work with CustomerReferences
Hi,
I'm trying to create shared carts between devices based on a CustomerReference. I can create a new order with a specific customer reference and I can see that I can call AssignToCustomer() on orders, if it doesn't have the correct CustomerReference.
I'm struggling to figure out two things:
How can I see which CustomerReference an order have?
Are there some magic way to make sure that my customer always get's he's or her's CURRENT cart? When the customer visits the page in another browser the cart should be the same.
Number 1. is the most important question I guess. If I know the CustomerReference I can easily switch the order in the cookie.
Number 2 is only if there is an inbuilt functionality for this.
Thanks /Rune
Ok. I actually found the answer to 1:
order.CustomerInfo.CustomerReference
So I guess I only need to know if there's an inbuilt feature for controlling the cart that the user is working on. Fetching the current cart, if there is one.
:)
Hey Rune,
Yup, your answer to #1 is correct. RE #2 you'd probably want to implement an
IOrderFinder
. These get called whenGetCurrentOrder
orGetOrCreateCurrentOrder
are called and there is not currently an order in the session. If there isn't on in the session, Vendr then tries all registeredIOrderFinder
's before finally creating a new order.For you needs then, you'd probably want to do a search for the most recent open orders by the known customer reference. If you return an order then Vendr will set that as being the current order for the current session and then will use that order from then on.
Hope this helps
Matt
I will take at look at that. Looks like the way to to it.
Cheers
Looking at this now. Is there any particular reason that the IOrderFinder.FindOrder( string customerReference ) does not take a Store id? Seems like I would need that to find the correct order.
And then maybe a stupid question. I cannot seem to figure out how to add my order finder. I would think it was something like this, but nothing seems to happen:
Are there some other way to add the order finder to the OrderFinderCollection?
/Rune
Hey Rune,
You're absolutely right that
FindOrder
should accept a store ID. I've made the change on our open minor release so there should be a 2.2.0-beta0000 on our unstable feed shortly if you want to test this https://nuget.outfield.digital/unstable/vendr/v3/index.jsonRE how you go about registering an order finder, you need to have a
using Vendr.Extensions
statement and a nuget reference toVendr.Umbraco.Startup
and then you'd use the followingHope this helps
Matt
Hi Matt,
Yes. That did the trick. Looks like it's only called on _vendrApi.GetOrCreateCurrentOrder() and not GetCurrentOrder(), which doesn't take the string customerReference parameter. Shouldn't it work on GetCurrentOrder() as well so the cart from e.g. another browser can be loaded? Or am I supposed to call GetOrCreateCurrentOrder always when using customerReferences?
Very good point. Pushing an update to our unstable feed now with another
GetCurrentOrder
method that accepts a customer reference. I've also implemented it such that if the old method is used, then the current member ID is used by default.From a lookup perspective, in your order finder, I think you might need some logic to ensure that it only finds the current latest order where there isn't a finalized order the occurs after it. You'll basically want to ensure that if there are historic carts for that customer that after checking out order B you don't want it then to claim an old order A that was abandoned before it.
It'll probably be a few minutes whilst our build server builds the new beta build.
Matt
I was actually thinking about using
And then Deleting the carts that are not the newest one. It's either that or maybe use the
What would be best you think. Maybe there's a third option. I looks like the repositories are protected when it comes to the ones that could return Order objects from at custom sql-query.
And this might be a noob question. But how would I install the unstable-version in my project?
Hey Rune,
Sure, then yea, in that scenario if you want to retrieve multiple I'd use the
SeachOrder
API likeOr actually, we do also have the following which should do the same.
RE how to use the unstable feed, you'll want to add this in visual studio as a custom nuget source (see MS docs here https://docs.microsoft.com/en-us/azure/devops/artifacts/nuget/consume?view=azure-devops&tabs=windows#set-up-visual-studio) and then in your nuget package manger make sure you have "Include prereleases" checked and your custom nuget source selected as the package source.
Hope this helps
Matt
PS I'd just make sure you install the specific beta version I mention as we have a number of unstable branches they build too so you want to make sure you install the one I've added the feature to 👍
That is brilliant. We learn something new everyday. I hope someone else passes by this post for extra nuggets of gold :)
Ok. So now I got a bit closer, but I want to make sure I do this right.
If my custom IOrderFinder returns null the vendr throws a nullpointer exception in Vendr.Core.Services.OrderService.FindOrder(Guid storeId, string customerReference)
I'm not supposed to create a new order in my IOrderFinder, am I? Seems like that should just result in no cart.
Also it looks like you have an IMembershipHelper.GetCurrentMemberId() that finds the default customerReference, is that correct? Should I implement that as well, so I don't have to get it myself every time I'm calling GetCurrentOrder? I have a few different ways of creating the customerReference, so that would make sense to me.
Hey Rune
So
IOrderFinder
returns anOrderFinderResult
. If you are unable to locate an order to return, then you should returnOrderFinderResult.Fail()
where if you to find an order, you should returnOrderFinderResult.Succeed(order)
. So you should never need to returnnull
.If you have different ways of getting the current member ID beyond Umbraco's logged in member, then yea, you could replace
IMembershipHelper
with your own implementation. Just make sure you register it after Vendr has been registeredHope this helps
Matt
It WORKS... And it's brilliant 🥳
Cheers for all your hard work. You have really taken this product to a new level.
/Rune
Hi Matt,
My feature is now working as expected with the 2.2.0-beta0001 version. have you planned an estimated release date?
And if that's far in the future. What is you feeling of the beta version? Is it somewhat stable?
/Rune
Hi Rune,
I like to leave at least a week between releases, which the last release was exactly a week ago today so I can probably look at getting it pushed out today / tomorrow.
All our beta builds are migratable though so you should be fine to use the beta for the immediate time being 👍
Matt
One gold star for you 😊
2.2.0 has just been released 👍
is working on a reply...