Copied to clipboard

Flag this post as spam?

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


  • MB 273 posts 936 karma points
    Apr 28, 2019 @ 13:49
    MB
    0

    Using discount price on product

    Hey lads!

    I have a working shop where I would like to use the "discounted" price. However, I can't seem to get that working.

    Here's an example: https://roldskovcykelshop.dk/olie-pleje-energi/pleje-vedligeholdelse/muc-off-dry-lube-120-ml/

    The way I have made it is pretty simple:

        var price = CurrentPage.GetPropertyValue("price");
        var discountedPrice = CurrentPage.GetPropertyValue("foerPris");
    
        if (CurrentPage.HasValue("foerPris"))
    {
            <div class="price">
                <span class="price_from">@priceFrom</span> @String.Format("{0:n}", discountedPrice) DKK
            </div>
    }
    

    I'm wondering how I can trigger the shop to use the discounted price?

    // Mike

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 28, 2019 @ 16:19
    Matt Brailsford
    1

    Hey Mike,

    What you'd want to do is flip your property usage. Rather than having a discounted price, have a "Pre Discount Price" and always store the price you want to charge in the price field.

    In your code you can then say, if there is a Pre Discount Price, assume the product is on sale and the price in the price field has been discounted, but if the Pre Discount Price field is empty, then the item isn't discounted and you can show your regular, non discount UI.

    Hope that helps

    Matt

  • MB 273 posts 936 karma points
    Apr 29, 2019 @ 18:06
    MB
    0

    Hi Matt,

    So if I understand you correctly. I cannot have two properties in my backend for each product:

    Price (actual prize): 400

    Discount price: (This is the new price if I enter something in here) 300

    And in my code check if the Discount Price exists, then tell TeaCommerce to use that Discount Price as the actual price?

    I understand your explanation as it HAS to be the price-property that TeaCommerce use?

    I'm not sure if this makes any sense.

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Apr 29, 2019 @ 18:29
    Matt Brailsford
    100

    Hey Mike,

    You can have 2 properties, but not the two you are wanting. Like I say, rather than Price and Discounted Price, you'd instead have Price which holds the current price you want to charge (so if you don't have a discount, it is the un-discounted price, but if you do have a discount, it's the discounted price) and something like Discounted From Price which can hold some value for what the price of the product was before discount.

    In your front end code then you can check to see if Discounted From Price has a value and if it does, you know it's discounted so you can do similar view logic.

    A common output would be to show the pre-discount price with a strikethrough which would have code something like:

    var price = CurrentPage.GetPropertyValue("price");
    var discountedFromPrice = CurrentPage.GetPropertyValue("discountedFromPrice");
    
    <div class="price">
        @if (CurrentPage.HasValue("discountedFromPrice"))
        {
            <span class="strikethrough">@String.Format("{0:n}", discountedFromPrice) DKK</span>
        }
        <span>@String.Format("{0:n}", price) DKK</span>
    </div>
    

    By doing it this way, the price that TC will charge is always in the price field regardless so TC will know what to charge.

  • MB 273 posts 936 karma points
    Apr 30, 2019 @ 16:52
    MB
    0

    Matt.... I just realized that I was struck by a brainfart. I flipped the logic around and wanted TC to use the discounted price INSTEAD of the Price attribute.... Your example makes perfect sense and it's actually what I already use.

    What basically confused me was the UI which was flipped around which resulted in the opposite result I wanted.

    Thank you Matt, for your everlasting patience.

    // Mike

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    May 01, 2019 @ 06:43
    Matt Brailsford
    1

    Hey Mike,

    You are more than welcome. I'm glad you were able to get things working 👍

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft