Copied to clipboard

Flag this post as spam?

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


  • MBE 186 posts 727 karma points
    23 days ago
    MBE
    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 2114 posts 10380 karma points MVP 5x c-trib
    23 days ago
    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

  • MBE 186 posts 727 karma points
    22 days ago
    MBE
    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 2114 posts 10380 karma points MVP 5x c-trib
    22 days ago
    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.

  • MBE 186 posts 727 karma points
    21 days ago
    MBE
    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 2114 posts 10380 karma points MVP 5x c-trib
    21 days ago
    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