Copied to clipboard

Flag this post as spam?

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


  • Nalysa 48 posts 269 karma points
    May 17, 2021 @ 04:18
    Nalysa
    0

    Vendr deprecated function issues after version upgraded from 1.3.2 to 1.4.2

    Hi,

    I upgraded the Vendr version to 1.4.2 previously version 1.3.2. There are several deprecated functions.

    I want to validate that the changed that I did is solved the deprecated function issues.

    1) WithoutDiscounts >> WithoutAdjustments

    Deprecated :

    OrderReadOnly.SubtotalPrice.WithoutDiscounts.WithoutTax;
    

    New :

    OrderReadOnly.SubtotalPrice.WithoutAdjustments.WithoutTax;
    

    I also want to ask how to solve these deprecated issues,

    1) Gift card

    Previously, to display the gift card code and amount in the summary page, the code is like this

    @if (currentOrder.TotalPrice.GiftCardsAmount.Value > 0)
    {
        <hr class="border-t border-gray-300 my-2" />
    
        foreach (var giftCard in currentOrder.GiftCards)
        {
            <div class="flex w-full justify-between items-center mt-2">
                <div class="">@Umbraco.GetDictionaryValue("Checkout_GiftCard") (@(giftCard.Code))</div>
                <div class="font-medium">-@(giftCard.Amount.Formatted())</div>
            </div>
        }
    }
    

    Gift card object inside the OrderReadOnly doesn't contain amount in the new vesion. also, TotalPrice object doesn't contain the GiftCardsAmount. How to solve this?

    2) How to implement the price adjustment? Previously, I implemented the discount using

    DiscountRewardProviderBase<CustomDiscountRewardProviderSettings>
    

    Thanks.

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    May 17, 2021 @ 08:27
    Matt Brailsford
    0

    Hi Nalysa,

    If you haven't already I would urge you to read the blog post we wrote on the 1.4.0 RC (which is still relevant) that documents all the changes around "Adjustments" https://vendr.net/blog/vendr-1-4-0-release-candidate/

    In addition, I'd suggest reviewing the demo store order summary view ( https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore.Web/Views/CheckoutStepPage.cshtml ) to see how we are fetching things like GiftCards to display on the order summary screen ( https://github.com/vendrhub/vendr-demo-store/blob/main/src/Vendr.DemoStore.Web/Views/CheckoutStepPage.cshtml#L122 )

    Lastly, you can find documentation about how to implement a price adjustment on the Vendr docs site at https://vendr.net/docs/core/1.7.0/key-concepts/price-amount-adjustments/

    Hope this helps

    Matt

  • Nalysa 48 posts 269 karma points
    May 18, 2021 @ 03:30
    Nalysa
    0

    Hi Matt

    Thank you for the documents you've shared. Appreciate it.

    Another question, I already created the custom amount adjuster. My question is how can I apply the custom amount adjuster?

    In the documentation, it is written "Adjustments are applied using a IPriceAdjuster or IAmountAdjuster ...". I accessed the ApplyAmountAdjustments method from IAmountAdjuster but the method requires the AmountAdjusterArgs param. How can I get the AmountAdjusterArgs?

    Thanks

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    May 18, 2021 @ 08:16
    Matt Brailsford
    0

    Hi Nalysa,

    You don't create the AdjusterArgs yourself, rather this is passed into you custom adjuster by Vendr.

    There is an example adjuster in the docs

    public class MyPriceAdjuster : PriceAdjusterBase
    {
        public override void ApplyPriceAdjustments(PriceAdjusterArgs args)
        {
            // Calculate Adjustment
            // Discount adjustments should be negative in 
            // where as Fee adjustments should be positive
    
            // Create a £10 discount
            var price = new Price(-8.33, -1.67, args.Order.CurrencyId);
            var adjustment = new MyAdjustment("My Discount", "MD-001", price);
    
            // Add the adjustment to the sub total price
            args.SubtotalPriceAdjustments.Add(adjustment);
        }
    }
    

    So you create your own Adjuster, which is passed the AdjusterArgs by Vendr and then you modify the args, adding your custom adjustment (that you instantiate in your adjuster) to the list of adjusters for the price you wish to modify.

    Once you have your adjuster + adjustment defined, you then register the adjuster so that it is known to Vendr

    [ComposeAfter(typeof(VendrWebComposer))]
    public class MyComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.WithPriceAdjusters()
                .Append<MyPriceAdjuster>();
        }
    }
    

    Each of these steps is detailed on the docs page here https://vendr.net/docs/core/1.7.0/key-concepts/price-amount-adjustments/

    Matt

  • Nalysa 48 posts 269 karma points
    May 18, 2021 @ 08:28
    Nalysa
    0

    Hi Matt,

    I've followed the documentation you gave. I already created the adjuster and adjustment.

    I still don't really understand how this adjuster works. I will explain my question with some example, maybe it helps to make my question clear.

    For example, I created Adjuster A + Adjustment A and I create another one, Adjuster B + Adjustment B.

    When the user clicks button 1, it triggers the Adjuster A.

    When the user clicks button 2, it triggers the Adjuster B.

    How can I achieve those behavior?

    Thank you.

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    May 18, 2021 @ 09:33
    Matt Brailsford
    100

    Hi Nalysa,

    All registered adjusters are executed whenever an order is recalculated. In your adjuster you need to decide whether the adjustment should be applied or not and if it is, create your adjustment and apply it to whever price you want adjusted.

    For your use case, where the adjustment is applied based on a user interaction you'll probably want to do something like have the buttons store a property on the order and then in your adjuster check that property to see if it's Value A, in which case apply Adjustment A or if it is Value B in which case apply Adjustment B.

    If you implemented a discount previously, it shouldn't be that different, you still run on every order calculation and you decide whether to apply an adjustment or not. It's just adjustments can be positive (fees) or negative (discounts) unlike the previous functionality which was discounts only.

    Hope this helps clarify

    Matt

  • Nalysa 48 posts 269 karma points
    May 18, 2021 @ 09:43
    Nalysa
    1

    Hi Matt,

    Thank you for your clarification and explanation, appreciate it.

  • Nalysa 48 posts 269 karma points
    May 19, 2021 @ 05:40
    Nalysa
    0

    Hi Matt,

    I've upgraded my Vendr.Chcekout to v1.2.0 (*note: Vendr v1.4.2). I adjusted the transaction amount to 0. Then I got this error when I want to continue the checkout process. Do you know how to fix this? Thanks

    Zero value payment method error message

  • Matt Brailsford 4123 posts 22194 karma points MVP 9x c-trib
    May 19, 2021 @ 08:18
    Matt Brailsford
    0

    Hi Nalya,

    Looking back at the changelog, it looks like there was a bug where the Zero Value Payment Provider wasn't updated in the 1.4.x release to use the new TransactionAmount property so it's erroring because it's using the Order.TotalPrice property still which won't be zero.

    This was fixed though in 1.5.2 https://vendr.net/docs/core/changelog/#v152 so I'd recommend upgrading to that version. Unfortunately 1.5.x requires an Umbraco version bump to 8.10.x due to it containing the new Variants Property Editor which is based on the block list editor that was introduced in 8.10.

    If you are going to upgrade, I would probably suggest the best thing to do would just be to upgrade to the latest of Vendr and Umbraco.

    Matt

    PS Can you try and keep forum posts to one topic at a time please. This really should have been raised as a separate topic.

  • Nalysa 48 posts 269 karma points
    May 19, 2021 @ 08:54
    Nalysa
    0

    Hi Matt,

    Thank you for you explanation.

Please Sign in or register to post replies

Write your reply to:

Draft