Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 873 posts 2086 karma points
    Jul 01, 2011 @ 11:01
    Matt Taylor
    0

    .Net API and getting the price of a product for the current currency

    I've looked at the documentation page and can see that the Javascript and Razor APIs documented but have not seen the same for the .Net API.

    I'm wondering which assemblies I should be referencing and what methods are available.

    My current issue is that I have used the nodeFactory to get the node of a particular product within my .Net control and now I want to output the correctly formatted price according to the current currency.

    Thanks,

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 01, 2011 @ 11:16
    Rune Grønkjær
    0

    Hi Matt,

    All you need is you can find in the TeaCommerce.Data.dll.

    For examples on how to use the API you might want to read these blogposts:

    How to make a License webshop
    Tea Commerce dynamic VAT
    Tea Commerce. NET API electronic product example
    How to use the Tea Commerce events

    Hope that will help you. There's not much you cannot accomplish with the API, and if you find something you can't, feel free to write a new post here.

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 01, 2011 @ 11:52
    Matt Taylor
    0

    Thanks Rune,

    I've looked through those examples and browsed the TeaCommerce.Data class for its methods but I'm unable to find anything that will give me the price of a product in the current currency.

    I haven't actually added any order lines or anything, all I have is the node data for the product I am interested in.

    Maybe I'm just being thick.

    Thanks, Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 01, 2011 @ 11:58
    Rune Grønkjær
    0

    Ah, sorry about that. In here:

    TeaCommerce.Data.Tools.PriceHelper
    

    Theres a couple of very usefull methods there for price formatting. They are all public.

    If you need to do it in your xslt's theres a method for it in the Tea Commerce xslt library which is located here:

    TeaCommerce.Library
    

    The Tools namespace holds a few other very usefull classes. One of them is the XSLTHelper class which e.g. . have the InvokeXSLT functionality.

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 01, 2011 @ 12:31
    Matt Taylor
    0

    Ah, I see how the price of a pruduct is come by using the XSLT libary from this example in the product.xslt example package.

     <xsl:variable name="price" select="teacommerce:GetProperty($variant, concat('productPrice', $currentCurrency/@ISOCode))" />

    What I'm struggling to do is figure out how to do the same using the TeaCommerce.Data library because the methods do not seem to exist or do I really have to use TeaCommerce.Library methods and all the XPATH stuff within my .Net control?

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 01, 2011 @ 12:39
    Rune Grønkjær
    0

    The XSLT library only wraps around methods in the TeaCommerce.Data classes. Prices formatted with the methods in the PriceHelper class

    TeaCommerce.Data.Tools.PriceHelper.FormatPrice
    TeaCommerce.Data.Tools.PriceHelper.FormatPriceNoSymbolWithSpecificCulture TeaCommerce.Data.Tools.PriceHelper.FormatPriceWithSpecificCulture

    You can provide a culture or just use the current. They in turn wrap the methods in:

    TeaCommerce.Data.Tools.FormatHelper
    

    /Rune

  • Matt Taylor 873 posts 2086 karma points
    Jul 01, 2011 @ 12:41
    Matt Taylor
    0

    Ah, I think I need to step back a bit. How to I get the price to pass into one of those methods?

    Effectively what I'm trying to do is something as simple as this:

    //Get product node
    umbraco.NodeFactory.Node currentNode = new umbraco.NodeFactory.Node(1172);
    //Get price of that node
    String price = <some TeaCommerce method to get current price of the product node>;

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 01, 2011 @ 12:47
    Rune Grønkjær
    0

    Ok.

    Document doc = new Document( 1172 );
    string price = TeaCommerce.Data.Tools.PriceHelper.FormatPriceWithSpecificCulture( decimal.Parse( doc.getProperty( "productPriceUSD" ).Value.ToString() ), "en-US" );

     

  • Matt Taylor 873 posts 2086 karma points
    Jul 01, 2011 @ 13:48
    Matt Taylor
    0

    Thanks for your help Rune.

    Got there in the end with a mishmash of libraries so not as neat as I'd hoped but here's the code if helps someone else.

    Node productNode = new Node(1234);
    TeaCommerce.Data.Currency currentCurrency = TeaCommerce.Razor.TeaCommerce.GetCurrentCurrency();
    string price = TeaCommerce.Data.Tools.PriceHelper.FormatPriceWithSpecificCulture(decimal.Parse(productNode.GetProperty(currentCurrency.PricePropertyAlias).Value), currentCurrency.CultureName);

    Cheers,

    Matt

  • Rune Grønkjær 1372 posts 3103 karma points
    Jul 01, 2011 @ 13:54
    Rune Grønkjær
    0

    Actually you could do it with the Razor library only

    TeaCommerce.Razor.FormatPrice(string price)
    

    That would use the currentCurrency automatically.

    Sorry about that. First thought of it now. Better late than never :)

    /Rune

     

  • Matt Taylor 873 posts 2086 karma points
    Jul 02, 2011 @ 11:10
    Matt Taylor
    0

    Cool, now that's the kind of thing I was looking for. :)

    Cheers,

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft