Copied to clipboard

Flag this post as spam?

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


  • Roger Withnell 128 posts 613 karma points
    Aug 15, 2015 @ 18:00
    Roger Withnell
    0

    Create a global property that can be updated by the content editor

    The product prices on my website are shown excluding VAT.

    I want the content editor to be able to set and update the VAT rate across the site.

    What is the best way to achieve this?

    Your help would be much appreciated.

    Thanking you in anticipation.

    Roger

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Aug 15, 2015 @ 21:29
    Marc Goodson
    100

    Hi Roger

    This depends where you are doing the VAT calculation and the structure of your site but in theory for global properties...

    You could create a property on the very top node of you Umbraco Content tree - usually your homepage document type (perhaps on a Site Settings tab) - if you called the property 'VATRate'; you could then read this value in a template View using:

    @Model.Content.GetPropertyValue("VATRate",true)
    

    (where true, means recurse up the content tree until you find a property called 'VATRate')

    or

    @Umbraco.Field("VATRate", recursive: true)
    

    will do the same.

    If your calculations are in a Macro you can create a parameter on the macro called VATRateParam and pass this in from the doc type property when you render your macro like so:

    @Umbraco.RenderMacro("AliasOfMacro", new {VATRateParam = "[$VATRate]"})
    

    the $ syntax here means recurse up the tree until you find the VATRate property, you would then access this value in your macro via:

    var vatRate = Model.MacroParameters.GetValue("VATRateParam")
    

    if that helps ?

    You might want to Cache the retrieved value for a period of time to prevent the work associated in accessing it from happening on each calculation; and also consider storing the rate at which VAT was calculated against each order - ie so historical orders or orders in progress don't have their VAT changed after the purchaser has committed to buy when the rate is changed globally...

  • Mike Chambers 635 posts 1252 karma points c-trib
    Aug 16, 2015 @ 09:27
    Mike Chambers
    0

    To continue on the global theme I'd also go with keeping historical vat rates global.. A global key value pair list of datetime and vat rate (then look up against invoice date for historical).. You might also have different types of products attracting different vat rates just to complicate things ☺

Please Sign in or register to post replies

Write your reply to:

Draft