Copied to clipboard

Flag this post as spam?

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


  • Puck Holshuijsen 184 posts 727 karma points
    Feb 16, 2022 @ 07:17
    Puck Holshuijsen
    0

    Multiple carts for a member

    Hi!

    I was wondering if it would be possible to have multiple carts (open orders) for a customer/member.

    What I have in my situation: We have a customer/business which can have multiple members to login. All of the members have to be able to save carts, open carts en finish carts from eachother.

    What I was trying to do was using the customer reference, and set the customer/business key as customerreference.

    What I have so far, when a member logs in:

          var openOrder = _orderService.GetOpenOrdersForCustomer(storeId, customerKey)
                        .OrderBy(x => x.CreateDate, Umbraco.Cms.Core.Direction.Descending)
                        .FirstOrDefault();
                    if (openOrder != null)
                    {
                        _vendrApi.SetCurrentOrder(storeId, openOrder);
                    }
                    else
                    {
                        _vendrApi.GetOrCreateCurrentOrder(storeId, customerKey);
                    }
    

    Which works fine to a degree, but I cannot create a new cart/open order without getting the old one.

    Is there a way to search the orders for a reference that start with something for example? Or is there a way to create a new order without getting the old one? Do you have an idea which I can try to implement or work on :)

    Also - which is a different question, but connected to this situation - is there a way to add custom fields to an order? I basically want to add the member key of the person logged in to the order, so I can see which person created this cart/order. Or maybe there is something like this already which i missed.

    Thanks!

    Kind regards Puck

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 16, 2022 @ 08:46
    Matt Brailsford
    100

    Hi Puck,

    I'll answer your second question first, and it's yes, you can store extra information on an order using the properties feature https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/properties/

    For your first question, I think your best bet would be to introduce a page that lists all open orders for a company (which you can use similar code to what you have, looking up open orders for a customer/company). From there, your visitor could then review the orders and then have a button to load that cart into their session using the ISessionManager.SetCurrentOrder(storeId, orderId). From that point on, the selected order is now in their current session and they can continue the order.

    Another option on that page could then be a "Create new Order" button which when clicked calls two methods on the session manager

    • ISessionManager.ClearCurrentOrder()
    • ISessionManager.GetOrCreateCurrentOrder()

    (we could probably do with a method that just forces the creation of a new order in session, but the above should do the same for now).

    Assuming you assign this to your company in the same way, this cart should then be available to other company members that can see that new carts page.

    I'm not sure how far people got, but I know a couple of people were working on a wishlists package which isn't too different to what you want to achieve in a way. Maybe it's worth reviewing their code to see if there is anything worth borrowing https://github.com/vendrcontrib/vendr-wishlists

    Hope this helps

    Matt

  • Puck Holshuijsen 184 posts 727 karma points
    Feb 16, 2022 @ 09:07
    Puck Holshuijsen
    0

    Hi Matt,

    Awesome! I will look into the suggestions you gave me.

    Will let you know if I got it working :)

    Thanks Puck

  • Puck Holshuijsen 184 posts 727 karma points
    Feb 16, 2022 @ 14:02
    Puck Holshuijsen
    0

    Just an update, but I got the basics working! Still need to test it thoroughly and finetune it, but I am glad with the first results :)

    I can create a new cart (nieuwe winkelwagen in the picture) and can take over the carts in the list.

    Thanks for the help you gave me already.

    enter image description here

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Feb 16, 2022 @ 14:39
    Matt Brailsford
    1

    Fantastic! That was really pretty quick.

    Nicely done 👏

    Matt

  • Puck Holshuijsen 184 posts 727 karma points
    Mar 01, 2022 @ 09:42
    Puck Holshuijsen
    0

    Hi Matt,

    I am still busy working on this part, but I'm at the point of the checkout and I am running into some issues :)

    I am using your checkout package, but when i finish the order, the logged in memberkey is stored in the customer reference field. And I want to save the company id as reference. I am not sure how to do this.

    What I tried on the reviewpage, which sets the correct customerreference at this point, but when the order is finished the member key is still used as customerreference.

    enter image description here

    Thanks!

    Puck

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 01, 2022 @ 09:49
    Matt Brailsford
    0

    Hi Puck,

    At 2 points in the check out flow, Vendr will automatically attempt to assign the order to the current logged in member. This is at the point of order creation and at the point of payment form generation.

    You could override this behaviour in a couple of ways.

    1. Implement an alternative IMembershipHelper which is responsible for getting the current member ID to assign to the order. You could replace this with something that gets the company ID instead.

    2. Hook into the OrderSavingNotification and enforce the use of the company ID every time before the order is saved, thus overriding any automatically assigned values.

    Hope this helps

    Matt

  • Puck Holshuijsen 184 posts 727 karma points
    Mar 01, 2022 @ 12:31
    Puck Holshuijsen
    1

    Hi Matt,

    Awesome! Got it working :D Thanks again!

    enter image description here

Please Sign in or register to post replies

Write your reply to:

Draft