Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Rune Grønkjær 1372 posts 3103 karma points
    May 03, 2022 @ 11:41
    Rune Grønkjær
    0

    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:

    1. How can I see which CustomerReference an order have?

    2. 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

  • Rune Grønkjær 1372 posts 3103 karma points
    May 03, 2022 @ 12:06
    Rune Grønkjær
    0

    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.

    :)

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 03, 2022 @ 12:54
    Matt Brailsford
    100

    Hey Rune,

    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.

    Hope this helps

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    May 03, 2022 @ 13:42
    Rune Grønkjær
    0

    I will take at look at that. Looks like the way to to it.

    Cheers

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 06:44
    Rune Grønkjær
    0

    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:

    builder.WithCollectionBuilder<OrderFinderCollectionBuilder>().Append( builder.TypeLoader.GetTypes<IOrderFinder>() );
    

    Are there some other way to add the order finder to the OrderFinderCollection?

    /Rune

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 04, 2022 @ 07:55
    Matt Brailsford
    0

    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.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

    builder.WithOrderFinders()
        .Append<MyOrderFinder>();
    

    Hope this helps

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 09:27
    Rune Grønkjær
    0

    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?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 04, 2022 @ 09:46
    Matt Brailsford
    0

    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

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 11:05
    Rune Grønkjær
    0

    I was actually thinking about using

    IEnumerable<OrderReadOnly> carts = _vendrApi.GetOpenOrdersForCustomer( store.Id, cartMemberIdentifier );
    

    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.

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 12:18
    Rune Grønkjær
    0

    And this might be a noob question. But how would I install the unstable-version in my project?

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 04, 2022 @ 12:43
    Matt Brailsford
    0

    Hey Rune,

    Sure, then yea, in that scenario if you want to retrieve multiple I'd use the SeachOrder API like

    _vendrApi.SearchOrders(where => where.IsFinalized().Not()
                .And(where.ByCustomer(customerReference)));
    

    Or actually, we do also have the following which should do the same.

    _vendrApi.GetAllOrdersForCustomer(storeId, customerReference);
    

    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.

    enter image description here

    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 👍

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 13:37
    Rune Grønkjær
    0

    That is brilliant. We learn something new everyday. I hope someone else passes by this post for extra nuggets of gold :)

  • Rune Grønkjær 1372 posts 3103 karma points
    May 04, 2022 @ 14:23
    Rune Grønkjær
    0

    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.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 04, 2022 @ 14:51
    Matt Brailsford
    1

    Hey Rune

    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

    builder.Services.AddUnique<IMembershipHelper, MyMembershipHelper>();
    

    Hope this helps

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    May 05, 2022 @ 05:36
    Rune Grønkjær
    0

    It WORKS... And it's brilliant 🥳

    Cheers for all your hard work. You have really taken this product to a new level.

    /Rune

  • Rune Grønkjær 1372 posts 3103 karma points
    May 05, 2022 @ 07:24
    Rune Grønkjær
    0

    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

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 05, 2022 @ 08:12
    Matt Brailsford
    1

    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

  • Rune Grønkjær 1372 posts 3103 karma points
    May 05, 2022 @ 08:22
    Rune Grønkjær
    1

    One gold star for you 😊

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    May 06, 2022 @ 09:12
    Matt Brailsford
    0

    2.2.0 has just been released 👍

Please Sign in or register to post replies

Write your reply to:

Draft