Copied to clipboard

Flag this post as spam?

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


  • Nelson Vicente 9 posts 29 karma points
    May 13, 2022 @ 10:29
    Nelson Vicente
    0

    Change finalized order

    Hi,

    Does vendr allow to programmatically change an order that has already been finalized?

    We have an order placed by the customer, at the checkout we go to the gateway to reserve the value of the order, but it may happen that not all items have been delivered.

    In that case we just need to capture the value of what was delivered and change the order to the amount charged and the items that were delivered.

    We are thinking of:

     1 - We change the finalized order
     2 - At the time of checkout we do not finalize the order and keep it in the cart to be able to change
     3 - Cancel the previous order and create a new one
    

    We would like to understand before starting the structure of the project if these paths are valid.

    ps: We are creating a custom payment provider on vendr (onpay)

    Thanks

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

    Hi Nelson,

    Currently finalized orders are final. You can change some things like properties and customer details, but not anything that would affect the price. We are looking at better refund options to allow partial refunds of an order which I think would be the right thing to do here but we currently only allow refunding the entire order.

    I guess the option you choose depends on the flow you need. You could go option 2 and capture on a payment gateway the customers payment details and store some kind of token on the order then create a custom button in the back office or something to trigger the capture against the stored credentials. Vendr does allow editing carts, but we don’t have a way yet in the backoffice to mark a cart as paid so this would need to be custom.

    My gut says you’d have most luck with either option 2 or 3 as option 1 would require hacking the order outside of Vendrs API.

    Hope this helps

  • Nelson Vicente 9 posts 29 karma points
    May 20, 2022 @ 17:19
    Nelson Vicente
    0

    Hi,

    We will use option 2, but our customer asked for unit testing this order change method.

    We have been looking at the umbraco documentation "https://our.umbraco.com/Documentation/Implementation/Unit-Testing/index-v8", but for vendr we are not able to use the VendrAPI(inside unit test project), so we can test the method.

    Any suggestion/example?

    ex: IVendrApi vendrApi = VendrApi.Instance;//Umbraco instance is null

    using (var uow = vendrApi.Uow.Create()) { var order = vendrApi.GetOrder(orderId)? .AsWritable(uow);

    order.UpdateItems(productsDelivered);
    

    }

    Thanks for your help

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 20, 2022 @ 17:27
    Matt Brailsford
    0

    IVendrApi is an interface so can it not be mocked? Also, IVendrApi is within the DI container so you should only use the singleton accessor in situations where you can’t inject it.

  • Nelson Vicente 9 posts 29 karma points
    May 21, 2022 @ 08:59
    Nelson Vicente
    0

    Hi,

    Sorry for the previous post, It was a little confused and not objective. Thank you for your help.

    We are trying to test the "changeorderitems" method, for that we tried to create a mock of the vendr order... as it doesn't have a constructor we tried to use the create method. From what we can understand, we need to mock UnitOfWork, and that's where our confusion is. How we can create one object order so we can test it?

    Ex:(we are getting object ot set, we suspect it is because of the mock ao unitofwork)

            GrntKo.Core.Models.Products.ProductSnapshot productSnapshotA = new Core.Models.Products.ProductSnapshot("Product A", "Product A", "A", 10M, new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"));
            GrntKo.Core.Models.Products.ProductSnapshot productSnapshotB = new Core.Models.Products.ProductSnapshot("Product B", "Product B", "B", 15M, new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"));
    
            Mock<IUnitOfWork> unit = new Mock<IUnitOfWork>();
    
            Order order = Order.Create(unit.Object, new Guid("ca0b66cb-1da3-458a-b7f5-017ef7ce257f"), "en-gb", new Guid("6ae57f51-ed1d-485d-a5fe-017ef7d77187"), new Guid("5b32dea4-712f-419f-a3e3-017ef7ce2977"), new Guid("0f5b1ede-3898-4ade-bbe7-017ef7ce2ae2"));
    
            order.AddProduct(productSnapshotA, 1, new Dictionary<string, string>(), string.Empty, string.Empty, new List<string>());
            order.AddProduct(productSnapshotB, 2, new Dictionary<string, string>(), string.Empty, string.Empty, new List<string>());
    

    Thanks

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 23, 2022 @ 07:45
    Matt Brailsford
    0

    Hi Nelson,

    I'm not sure what you mean by changeorderitems method as there is no method of that name. Or are you refering to the AddProduct method?

    For details on the Unit of Work and how to create one, you should review the docs at https://vendr.net/docs/core/2.1.0/umbraco-v9/key-concepts/unit-of-work/

    Hope this helps

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft