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 1371 posts 3102 karma points
    Oct 10, 2022 @ 09:39
    Rune Grønkjær
    0

    GetOrCreateCurrentOrder() after BeginPaymentForm()

    Hi,

    I'm having problems finding the correct way of doing this.

    On my cart page I edit the quantity of the cart. I do this by GetOrCreateCurrentOrder().AsWritable() and then editing the order. The same goes for when I add new products to the cart.

    My scenario is 1. Add product to cart 2. Go to the step in the Checkout with the BeginPaymentForm() 3. Go back to the edit cart step 4. GetOrCreateCurrentOrder() now returns a new and very empty order and my old order i gone.

    Should I not use GetOrCreateCurrentOrder() anywhere? Unless GetCurrentOrder() returns null?

    My goal is to keep my old order until it has bee finalized.

    Note: I use both GetCurrentOrder() and GetOrCreateCurrentOrder() with a customerReference, to make sure two customers can share the same cart. In this case there's only me though.

    /Rune

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 09:53
    Matt Brailsford
    0

    Hey Rune,

    BeginPaymentForm will initialize the transaction and assigned the orde rnumber but it shouldn't yet move the order out of the current order state so GetOrCreateCurrentOrder should return the current order still.

    If you call GetCurrentOrder does that actually return the current order? or does it return null?

    Also, if you call GetCurrentFinalizedOrder can you confirm the order hasn't been moved to that state somehow?

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 10:43
    Rune Grønkjær
    0

    GetCurrentOrder returns the correct old order. Only GetOrCreateCurrentOrder discards the old order and makes a new one. I can confirm that GetCurrentFinalizedOrder returns null.

    Sounds like it could be a bug?

    I can perform the problem on a v2.4

    /Rune

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 10:53
    Matt Brailsford
    0

    Ok, so we know the current order is still in the current order state.

    So, the GetOrCreateCurrentOrder firstly calls GetCurrentOrder so this should be doing the same thing, but on top of fetching the current order it also does a customer reference check. Are you doing anything with customer reference assignments?

    Generally speaking, if you are not logged in, then it should just return the found order, if you are logged in though if the order has no customer reference it will become assigned to you and then returned, or if the order has a customer reference and it's not your customer reference then this should be the only time a new order is created.

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 10:59
    Rune Grønkjær
    0

    I am sending my own string as customer reference. So yes, that might be a source of error. Using the same customer reference for all my tests.

    I am logged in with a member at the same time, but I create my own customer reference.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 11:13
    Matt Brailsford
    0

    Ok, so that’s likely the issue. If you don’t pass the customer reference to the GetOrCreateOrder method then the current logged in members ID will be used so if you are using some other customer reference, you’ll need to pass it to the method.

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 11:19
    Rune Grønkjær
    0

    No. I'm using the same customer reference for all calls throughout. There's never not a customer reference.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 11:22
    Matt Brailsford
    100

    But are you passing that to your Get OrCreateCurrentOrder method call? There is an overload that takes it as a second argument. If you don’t pass it, the current logged in member ID is used and you mentioned these aren’t the same thing which should be the only scenario under which the current order isn’t returned (ie, Vendr thinks the current order doesn’t belong to you)

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 11:27
    Rune Grønkjær
    0

    Oups. Just marked you previous comment as the solution. Miss click.

    enter image description here

    I send the customer reference to all the methods that allows it. And that part works very fine.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 11:36
    Matt Brailsford
    0

    Ok, and so passing that reference still results in a new order being created?

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 11:43
    Rune Grønkjær
    0

    Correct. That has been the case all along.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 11:52
    Matt Brailsford
    0

    Gotcha. Ok, let me take another look.

    It would seem it’s around this comparison that the issue lies.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 12:27
    Matt Brailsford
    0

    It's not a casing issue is it? We do a simple == comparison for the current orders CustomerReference so I think that would be case sensitive.

    If you call GetCurrentOrder and compare it's customer reference with the one you passed in, does it say it matches?

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 12:29
    Rune Grønkjær
    0

    Nope. The current customer reference I'm using is a telephone number with only 8 digits and nothing else.

    Edit: As a string of cause

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 12:46
    Matt Brailsford
    0

    And regarding my second question, if you retrieve the order via GetCurrentOrder does it have a customer reference set to that same value?

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 10, 2022 @ 12:49
    Rune Grønkjær
    0

    Yes. GetCurrentOrder has the same customer reference number, but returns the correct order. So I guess I could just use that method, but it seems like I shouldn't have to. GetOrCreateOrder should do the same.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 10, 2022 @ 13:40
    Matt Brailsford
    0

    Indeed. I can't for the life of me figure out why it's wrong though. Maybe if you replicate the code Vendr is using you can see where it's going wrong?

    This is basically the code that is the start of the GetOrCreateCurrentOrder method and is responsible for returning the current order

    var currentOrder = GetCurrentOrder(storeId, customerReference);
    if (currentOrder != null)
    {
        if (string.IsNullOrWhiteSpace(customerReference)) 
        {
            // If no customer reference is supplied, then just return whatever the current order is
            // this could be an order assigned to a customer or not.
            return currentOrder;
        } 
        else if (!string.IsNullOrWhiteSpace(customerReference) && string.IsNullOrWhiteSpace(currentOrder.CustomerInfo.CustomerReference))
        {
            // Order has no customer ref, but one was supplied so assign the order to the customer now and return it
            using (var uow = _uowProvider.Create())
            {
                var writableOrder = currentOrder.AsWritable(uow)
                    .AssignToCustomer(customerReference);
    
                _orderService.SaveOrder(writableOrder);
    
                currentOrder = writableOrder;
    
                uow.Complete();
            }
    
            return currentOrder;
        }
        else if (!string.IsNullOrWhiteSpace(customerReference) && currentOrder.CustomerInfo.CustomerReference == customerReference)
        {
            // Customer ref was supplied and it matches the order customer ref, so we can continue to use this order
            return currentOrder;
        }
    
        // The only other option left is that as customer ref was passed but it doesn't match the
        // customer ref on the current order, so we won't return it and will fall through to create a new order
    }
    

    If you can let me know what that hits in your code, I believe in your case it should hit the last else if but it sounds like it's not matching any of those statements for some reason.

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 11, 2022 @ 05:31
    Rune Grønkjær
    0

    Thanks for the code bit. It's my customer reference that is not the same as currentOrder.CustomerInfo.CustomerReference.

    enter image description here

    So the code runs past your code example. So what happens if the line in the screenshot is false? And why is currentOrder.CustomerInfo.CustomerReference not the same as mine? Is it my responsibility to set it at some point? My expectation is that it should be set right in the beginning when I created the order with my own customer reference.

    /Rune

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 11, 2022 @ 07:13
    Matt Brailsford
    0

    Bingo! Ok, so it looks like it's a problem in BeginPaymentForm as this is when it also attempts to assign the customer reference, but it's basically saying if it's not the same than that coming from the membership helper then overrwrite it, which really it should be if the reference is set, don't bother attempting to set it again.

    I'll see if I can push a v2 patch out with an update to this

    UPDATE I've pushed the fix to our unstable feed at https://nuget.outfield.digital/unstable/vendr/v3/index.json if you install v2.4.1-beta0002 this should resolve the issue. If you are able to test and let me know this is the case I'll get a full patch release out.

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 11, 2022 @ 09:20
    Rune Grønkjær
    0

    Not sure if it's me that's a nuget n00b but I cannot seem to find your beta. As you can see on my screenshot I have added your unstable nuget link to VS, but there's no beta's and the latest version is the 2.4.0 which I have already installed.

    Am I missing something?

    enter image description here

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 11, 2022 @ 09:36
    Matt Brailsford
    0

    There should also be a checkbox when searching for the packages for "Include Prerelease" which needs to be checked

    enter image description here

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 11, 2022 @ 10:01
    Rune Grønkjær
    0

    *Facepalm I knew that.

    Thanks

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 11, 2022 @ 10:42
    Rune Grønkjær
    0

    It works 👍

    I cannot replicate the bug with v2.4.1-beta0002. I can also complete a payment, so the payment form still works as well. Good work.

    Will you be making a release of 2.4.1?

    /Rune

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 11, 2022 @ 11:18
    Matt Brailsford
    0

    Yea, I’ll see if I can do that this afternoon 👍🏻

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Oct 11, 2022 @ 12:21
    Matt Brailsford
    100

    2.4.1 should be out now. I won't be making a big public announcement though, but it's there for you anyway :D

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 12, 2022 @ 05:24
    Rune Grønkjær
    0

    I will test it asap. There's a small issue with my staging environment, so I cannot test it there yet. But my local version works as expected.

    Good work as always 👍

  • Rune Grønkjær 1371 posts 3102 karma points
    Oct 13, 2022 @ 05:31
    Rune Grønkjær
    1

    FYI we just released the v2.4.1 version to the live site and all seems good.

Please Sign in or register to post replies

Write your reply to:

Draft