Copied to clipboard

Flag this post as spam?

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


  • Frans Lammers 57 posts 400 karma points c-trib
    Jan 05, 2023 @ 15:30
    Frans Lammers
    0

    Vendr - Prices left 0 after adding an item to the order

    Hallo,

    We have made a custom product adapter, because our products do not reside on Umbraco nodes, but are stored in our own database. When adding an item to the cart all properties of the item are copied except for the price. Both the orderline and order-price are 0. I have looked through the documentation, but I can't seem to find where the error is.

    Here is how I add my items to the cart:

     using (var uow = _uowProvider.Create())
                        {
                            var store = currentPage.GetStore();
                            var order = _sessionManager.GetOrCreateCurrentOrder(store.Id)
                                .AsWritable(uow)
                                .AddProduct(model.ProductReference, model.ProductVariantReference, model.Quantity);
    
                            _orderService.SaveOrder(order);
    
                            uow.Complete();
                        }
    

    And here is the part in my productadapter where I fill the productsnapshot:

    if (variantService.GetVariant(variantId, languageIsoCode) is Variant variant)
                {
                    var prices = new List<ProductPrice>() {
                        new ProductPrice(variant.Price, store.BaseCurrencyId.Value)
                    };
                    return new Product()
                    {
                        ProductReference = productReference,
                        ProductVariantReference = productVariantReference,
                        Sku = variant.Sku,
                        Name = variant.Name,
                        StoreId = storeId,
                        TaxClassId = store.DefaultTaxClassId,
                        Prices = prices
                    };
                }
    

    While debugging I can see that the productsnapshot has got the right values of the price, but the order does not receive them.

    thanks,

    Frans

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jan 05, 2023 @ 15:46
    Matt Brailsford
    0

    Is your order set to be the same currency as the base currency? (check the order's CurrencyId)

  • Frans Lammers 57 posts 400 karma points c-trib
    Jan 05, 2023 @ 15:53
    Frans Lammers
    0

    Yes, it has the same currencyId as the base currency.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jan 05, 2023 @ 16:06
    Matt Brailsford
    0

    I mean, from what I can see it sounds fine, but clearly something else must be going on.

    If your product adapter returns a snapshot with prices this should all be ok.

    I'm not sure if it's relevant, but it's worth knowing the order line prices isn't imeditaly assigned after AddProduct is called until the order is recalculated as it's the OrderLineCalculator that is responsible for populating the order line price. With this, you should probably see 2 calls to your product adapter, 1 when the items is being added and 1 when the order line price is being calculated. If you have some code that only works during the first cycle, this could result in a zero value being returned within the order line calculator, but I'm just speculating. It's hard to say really without seeing all the related code.

  • Frans Lammers 57 posts 400 karma points c-trib
    Jan 05, 2023 @ 16:28
    Frans Lammers
    0

    Thanks, that lead me to what is happening: the method GetProductSnapShot passes the languageIsoCode, which I use this to get the name of the variant in the correct language. I assumed that this was always passed to the Productadapter, but it isn't.

    The first call from AddProduct passes the languageIsoCode, but the second call, somewhere inside SaveOrder does not pass the code. So my code returns the wrong value.

    What can I do about it? Of course I can check for null, but then the name of the variant and other translated properties will not be available to the productsnapshot.

  • Matt Brailsford 4125 posts 22223 karma points MVP 9x c-trib
    Jan 05, 2023 @ 16:35
    Matt Brailsford
    100

    Yea, so we assume the language code shouln't be needed for prices as the values shouldn't change per langauge (ie, things like name and description could be translated, but the price fields shouldn't) and as such it's not passed when the order line price calculator calculates it's price.

    Really, the product variant reference + product reference should be enough to resolve a price.

    How are your variants setup that they have different prices per language?

    PS if the language ISO code is null, you can assume Vendr is calling it just to access values it knows won't be translatable so you can safely handle null and return null or a default value for translated values that would normally require it.

  • Frans Lammers 57 posts 400 karma points c-trib
    Jan 05, 2023 @ 16:40
    Frans Lammers
    0

    OK, that answers my question.

    My variants do not have prices per language, so I am able to get the prices without the language. But I was not sure if the returned productsnapshot would overwrite the translatable properties.

    Thank you!

    Frans

Please Sign in or register to post replies

Write your reply to:

Draft