Copied to clipboard

Flag this post as spam?

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


  • Fedor Krutko 13 posts 123 karma points
    May 31, 2021 @ 11:32
    Fedor Krutko
    0

    Product price missing on external product when added to order

    Hi Matt,

    I'm trying to implement adding an external product to vendr order, and it seem to be adding it without any errors, but when I query the orderlines, the price of such product is 0. Here's the code:

    using (var uow = uowProvider.Create())
                {
                    var order = sessionManager.GetOrCreateCurrentOrder(store.Id)?.AsWritable(uow);
                    if (order != null)
                    {
                        var productProperties = new Dictionary<string, string>();
                        productProperties.Add(VendrOrderProperties.ItemType, CartItemTypeEnum.Accessory.ToString());
    
                        ExternalProduct q = new ExternalProduct();
    
                        q.Description = "description";
                        q.Name = "external product";
                        var prices = new List<ProductPrice>();
                        prices.Add(new ProductPrice(138m, new Guid("a79ce70d-c9b5-415d-ad3c-5d98283ea7d9")));
                        q.Prices = prices;
    
                        q.ProductReference = "ex1";
                        q.Sku = "ex1";
                        q.StoreId = new Guid("536a8ebb-f1e5-4d8e-891a-b902bb21d354");
                        q.TaxClassId = new Guid("c54c07af-ea58-4143-ac35-21d255686641");
    
                        order.AddProduct(q, 1, productProperties);
    
                        orderService.SaveOrder(order);
                    }
                    uow.Complete();
                }
    

    Also, I've implemented custom product adapter as per the docs, where GetProductSnapshot method just returns the same object that I'm adding to the order. The adapter is registered via composition.RegisterUnique<IProductAdapter, CustomProductAdapter>();, so should be no problem.

    Maybe there is something I'm missing here?

    Thanks, Fedor

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    May 31, 2021 @ 11:47
    Matt Brailsford
    100

    Hi Fedor

    If you have implemented a product adapter than there shouldn't bee a need to also create a manual product snapshot whilst adding the item to the order. You should be able to pass the product ID and then it requests the product snapshot from the product adapter.

    If the price is empty, the usual culprit for this is that the product doesn't have a price defined for the currency the order is in. You might want to check to make sure the currency you define for the price on the snapshot, is the same as the currency of the the order.CurrencyId

    Matt

  • Fedor Krutko 13 posts 123 karma points
    Jun 01, 2021 @ 10:04
    Fedor Krutko
    0

    Hi Matt,

    thanks for the hint, it all works now.

    One thing I've had to add is [ComposeAfter(typeof(VendrWebComposer))] to the composer class where I've registered the custom product adapter.

  • Matt Brailsford 4125 posts 22222 karma points MVP 9x c-trib
    Jun 01, 2021 @ 10:11
    Matt Brailsford
    0

    Ahh yea, we do document this here https://vendr.net/docs/core/1.7.0/key-concepts/dependency-injection/#registering-dependencies but we don't show it in every example as it detracts from what is being documented. It does mean you have to have read that section first though, which people probably should, but I'll bare that in mind.

    Glad you got it all working 👍

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft