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
    Jan 09, 2023 @ 10:26
    Puck Holshuijsen
    0

    Save cart in Backoffice - Set shipping method gets cleared

    Hi Matt,

    I am trying to think of a solution for our customer to add a shipping method for the ordering customer. This way a customer can get a quotation for shippingcosts before ordering.

    When I open the cart in the Backoffice, i can set the shipping method (while the method is empty). I see the shipping method being selected. But when i save the cart, the shippingmethod gets cleared.

    I don't get any errors in the devtools.

    I am talking about this field right here.

    enter image description here

    Do you have an idea where to look, or what might be the problem?

    Thanks!

    Kind regards,

    //Puck

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 09, 2023 @ 10:30
    Matt Brailsford
    0

    Are you using Vendr Checkout?

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 09, 2023 @ 10:31
    Puck Holshuijsen
    0

    yes!

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 09, 2023 @ 10:38
    Matt Brailsford
    100

    So that will be why.

    Vendr Checkout will clear the billing / shipping details when an order is updated. It does this to ensure shipping / billing prices are not included in the initial cart total, but it will just apply this rule whenver the cart is updated, regardless of it being front end or back end update.

    If you'd prefer not to have these event handlers enabled you can disable them by removing them at startup after Vendr Checkout has done it's initialization.

    You can see the list of events Vendr Checkout adds here https://github.com/vendrhub/vendr-checkout/blob/b9922ca5e02e45352aa87be3448643da0d99d8b0/src/Vendr.Checkout/Extensions/CompositionExtensions.cs#L23-L39 you'll basically need to create a composer that does the same, but calls Remove for each of those event handlers.

    Hope this helps

    Matt

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 09, 2023 @ 11:00
    Puck Holshuijsen
    0

    Alright! I will give it a try.

    Thanks

    Puck

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 09, 2023 @ 12:03
    Puck Holshuijsen
    0

    Hmmm can't seem to get it working. Probably my own fault.

    I tried adding this to my Composer, but it didn't work. The shipping method is still being cleared.

        // an order change
            builder.WithNotificationEvent<OrderLineChangingNotification>().RemoveHandler<OrderLineChangingHandler>();
            builder.WithNotificationEvent<OrderLineRemovingNotification>().RemoveHandler<OrderLineRemovingHandler>();
            builder.WithNotificationEvent<OrderPaymentCountryRegionChangingNotification>().RemoveHandler<OrderPaymentCountryRegionChangingHandler>();
            builder.WithNotificationEvent<OrderShippingCountryRegionChangingNotification>().RemoveHandler<OrderShippingCountryRegionChangingHandler>();
            builder.WithNotificationEvent<OrderShippingMethodChangingNotification>().RemoveHandler<OrderShippingMethodChangingHandler>();
    

    After this i tried making an extension for the VendrBuilder. But it also doesn't work.

    Startup + extension:

    enter image description here enter image description here

    I also tried it as it's own composer which should be run after the VendrCheckoutComposer, but also no luck.

    enter image description here

    //Puck

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 09, 2023 @ 13:38
    Matt Brailsford
    0

    So these would have to be via a composer and they would have to be configured to run after the VendrCheckoutComposer so the latter approach should really work.

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 09, 2023 @ 13:55
    Puck Holshuijsen
    0

    It does say that it is deprecated, might be an issue?

    I am using Vendr 3.0.5 and Checkout 3.0.0 by the way

    enter image description here

    When debugging my project it does hit my breakpoint, which means it gets in my composer. But when I want to set the shipping method for the cart in the backoffice, it keeps clearing it.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jan 09, 2023 @ 14:01
    Matt Brailsford
    0

    Yea, it is depricated, but Vendr Checkout supports a lot of back versions so it uses the older API for it.

    Hmm, this should be working.

    The only other thing I could suggest atm is to pull the source code for the Vendr Checkout plugin and compile a version with those event handler disabled 🤔

  • Puck Holshuijsen 184 posts 727 karma points
    Jan 09, 2023 @ 14:05
    Puck Holshuijsen
    1

    Alright, got it working!

    I found the last version of that extension and noticed an extra line of code. Added the removehandler for that one and also added the using IBuilder, and now its working!

    enter image description here

    This is the complete Composer right now:

    using Umbraco.Cms.Core.Composing;
    using Vendr.Checkout.Composing;
    using Vendr.Checkout.Events;
    using Vendr.Core;
    using Vendr.Core.Events.Notification;
    using Vendr.Extensions;
    using Vendr.Umbraco;
    using IBuilder = Umbraco.Cms.Core.DependencyInjection.IUmbracoBuilder;
    
    namespace Project.Repository.Composers {
        [ComposeAfter(typeof(VendrCheckoutComposer))]
        public class StoreExtraComposer : IComposer {
    
            public void Compose(IBuilder builder)
            {
                // Remove reset shipping / payment methods when certain elements of
                // an order change
                builder.WithNotificationEvent<OrderProductAddingNotification>().RemoveHandler<OrderProductAddingHandler>();
                builder.WithNotificationEvent<OrderLineChangingNotification>().RemoveHandler<OrderLineChangingHandler>();
                builder.WithNotificationEvent<OrderLineRemovingNotification>().RemoveHandler<OrderLineRemovingHandler>();
                builder.WithNotificationEvent<OrderPaymentCountryRegionChangingNotification>().RemoveHandler<OrderPaymentCountryRegionChangingHandler>();
                builder.WithNotificationEvent<OrderShippingCountryRegionChangingNotification>().RemoveHandler<OrderShippingCountryRegionChangingHandler>();
                builder.WithNotificationEvent<OrderShippingMethodChangingNotification>().RemoveHandler<OrderShippingMethodChangingHandler>();
            }
        }
    }
    

    Thanks again for everything!

    //Puck

Please Sign in or register to post replies

Write your reply to:

Draft