Copied to clipboard

Flag this post as spam?

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


  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Nov 14, 2013 @ 14:25
    Bjarne Fyrstenborg
    0

    Using additional textfield for old price and compare with new price

    I have added an additional textfield for adding the old price of a product, e.g. oldPriceDKK and still have the existing productPriceDKK, which set the product price.

    Now I want to return a decimal, so I can compare the two prices and if the old price is greather than product price and a difference on more than 0, I want to do some stuff.

    What I have done so far is:

    decimal oldPrice = 0M;
    decimal number;
    if(Decimal.TryParse(TC.GetPropertyValue( storeId, product, "basePriceDKK" ), out number))
    {
        oldPrice = number;
    }
    
    
    //Price
    Price price = TC.GetPrice( storeId, product.Id.ToString() );
    Price basePrice = TC.FormatPrice( 1, oldPrice );
    

    Here both price and basePrice is displayed in same way as long I write the old price with comma as decimal separator. Where teh default price also handle dot as decimal seperator.

    The standard price seems to use the product id the get the price from the property which is set in the currency node in Tea Commerce section. But how can handle it in same way with additional price?

    Can I get a decimal from the standard price or can I compare the prices in the Price objects?

    /Bjarne

  • Anders Burla 2560 posts 8256 karma points
    Nov 14, 2013 @ 14:28
    Anders Burla
    0

    Just get the old price using TC.GetPropertyValue and then use Tc.FormatPrice

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Nov 14, 2013 @ 14:40
    Bjarne Fyrstenborg
    0

    Hej Anders

    That's also what I did :)
    I was wondering how the standard productPriceDKK handle noth comma and dot as decimal separator.

    E.g.
    Price DKK: 2316,00 --> output: 2.895,00 kr.
    Base price DKK:  2392,00 --> output: 2.990,00 kr.

    But with dot as decimal separator:
    Price DKK: 2316.00 --> output: 2.895,00 kr.
    Base price DKK:  2392.00 --> output: 299.000,00 kr.

    also from the Price object can I get the values to compare the prices?

    The price output is written like this: @price so I guess that a price object both incl. price and currency - is there a method or property the extract the price value?

  • Anders Burla 2560 posts 8256 karma points
    Nov 14, 2013 @ 14:44
    Anders Burla
    0

    The price object has a lot of properties. Like price.Value which is the raw price. price.Vat is the Vat. price.WithVat is price including VAT.

    Tea Commerce tries to handle both comman and dot. But it depends on what language/culture your website is running. Because . is normal a seperator for a thousand in american culture.

  • Bjarne Fyrstenborg 1285 posts 4039 karma points MVP 8x c-trib
    Nov 14, 2013 @ 14:56
    Bjarne Fyrstenborg
    0

    Okay, the documentation just says that it returns an price object, but not which method and properties it has.. :)

    But of course I could add the references to a Visual Studio project and explore, which method and properties it has.. 

    Yes, I have seen some examples before including the CultureInfo object to get the right decimal value related to the language/culture something like this: http://msdn.microsoft.com/en-us/library/ew0seb73(v=vs.110).aspx .. 

Please Sign in or register to post replies

Write your reply to:

Draft