Copied to clipboard

Flag this post as spam?

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


  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jan 10, 2022 @ 16:37
    Owain Williams
    0

    Displaying the price difference once discount code applied

    Hi,

    I've a question with regards to discount codes and displaying the difference between the original price and the discounted price on the confirmation page just before the user pays for the products.

    If I have a product in my basket and the user adds a discount code, the new total price is displayed as expected but I can't seem to find a way to display the adjusted price.

    Ideally I'd have something like (simple example)

    Original Price - £10 Discounted Price - £5

    Total £5

    I thought using Adjustment and WithoutAdjustment I could get this info but it .Adjustment always comes back as 0.

       @foreach (var line in order.OrderLines.Select((ol, i) => new { OrderLine = ol, Index = i }))
        {
            <div class="eccommerce-checkout-body-info-label">
                <p>@line.OrderLine.Name<span>x@(line.OrderLine.Quantity.ToString("0"))</span></p>
                @if (Umbraco.MemberIsLoggedOn())
                {
                    <p>@line.OrderLine.UnitPrice.Adjustment.Formatted().WithoutTax</p>
    
                    <p>@line.OrderLine.UnitPrice.WithoutAdjustments.Formatted().WithoutTax</p>
                }
            </div>
        }
    

    While .WithAdjustment shows the correct Cost.

    I also tried:

      <div class="eccommerce-checkout-body-info-button __total __light">
            <span>Total</span>
    
            @order.TransactionAmount.Adjustment.Value
            <span>@order.TransactionAmount.Value.Formatted()</span>
        </div>
    

    The output I get is:

    enter image description here

    This is with a 50% off the total amount discount code.

    Am I using this correctly?

    Thanks, O.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Jan 11, 2022 @ 09:29
    Matt Brailsford
    101

    Hi Owain,

    Sure, so with a "total amount discount" the discount is only present on the order.TotalPrice and so the order lines aren't going to show a level of discount as it doesn't apply at that point. The order lines would only contain info for order line discounts.

    You might want to review something like our confirmation email templates as these are the most thorough places where we show price breakdowns with discounts amounts etc

    https://github.com/vendrhub/vendr-demo-store/blob/v2/netcore/main/src/Vendr.DemoStore.Web/App_Plugins/Vendr/templates/email/BlendidOrderConfirmationEmail.cshtml#L176

    Hopefully these will give you some idea.

    Matt

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jan 11, 2022 @ 09:48
    Owain Williams
    0

    That's really helpful, thanks Matt. I'll check out the template and see what I can come up with.

    O.

  • George Logan 36 posts 168 karma points
    Jan 14, 2022 @ 13:32
    George Logan
    0

    Hi Owain,

    Can you let me know if you have any success?

    I have a client currently looking for similar.

    Thanks,

    George

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jan 14, 2022 @ 13:44
    Owain Williams
    0

    Ye, I did.

    I did something like this -

        if (line.OrderLine.UnitPrice.Value != line.OrderLine.UnitPrice.WithoutAdjustments)
                        {   
                            <p class="rrp">@line.OrderLine.UnitPrice.WithoutAdjustments.Formatted().WithoutTax</p>
                            <p>@line.OrderLine.UnitPrice.Value.Formatted().WithoutTax</p>
                        }
                        else
                        {
                            <p>@line.OrderLine.UnitPrice.Value.Formatted().WithoutTax</p>
                        }
    

    The other thing I had to make sure was in the back office the discount is applied to the unit price instead of the overall subtotal (which was originally setup).

    enter image description here

    So the second reward is what now allows me to show the discount per unit price and I removed the first reward.

    Hope that helps.

    O.

  • George Logan 36 posts 168 karma points
    Jan 14, 2022 @ 15:11
    George Logan
    0

    Excellent, cheers Owain! Looks like it does the trick.

  • Owain Williams 480 posts 1412 karma points MVP 6x c-trib
    Jan 14, 2022 @ 15:12
    Owain Williams
    0

    Great! Glad I could help :)

    O.

Please Sign in or register to post replies

Write your reply to:

Draft