Create taxes

To create a tax, you must perform the following:

  1. Get the orders manager.
    Get an instance of the OrdersManager object.
  2. Create a new tax.
    To create a new tax class, call the CreateTax method of the manager.
  3. Set the properties of the Tax object.
    In this example the following properties are set:
    • Title
      Gets or sets the display name of the department.
    • TaxRate
      Gets or sets the default rate for the tax.
    • Country
      Gets or sets the country that the tax is associated with.Note that if the value of this property is "United States", you have to set the State property as well.

      NOTE: You can additionally narrow the location for the Tax by using the optional City, County, FromZip, and ToZip properties. Regarding the ZIP related properties, you can use either only the FromZip property for a single ZIP number (default behavior), or to use both of them for a range of ZIP numbers. To do the latter, you must set the UseZipRange property to true. All of these properties should be used only when the Country property is set to "United States".

    • AddressType
      Gets or sets the address type the tax is applied to. You can choose between AddressType.Shipping and AddresType.Billing.
    • ApplyTaxToShipping
      Indicates whether the tax is applied to the shipping.
  4. Specify rate values for each available tax class.
    To do this, perform the following:
    1. Create a List of TaxClassRate objects.
    2. Create the standard rate item.
      Create an instance of the TaxClassRate class. Set its Id property to Guid.Empty. Then set its Name property to “standardrate”. Set the Rate and the TaxExempt properties to the desired values. Finally add the standard rate item to the list.
    3. Create a TaxClassRate item for each available tax class.
      First, get all the available tax classes. Then iterate through them and create an instance of the TaxClassRate for each item. Set the Id and the Name properties of the TaxClassRate instance to the values of the Id and Title properties of the TaxClass instance. Add each of the TaxClassRate instances to the list.
    4. Serialize the List of TaxClassRate objects.
      To serialize the list, use the System.Web.Script.Serialization.JavaScriptSerializer class.
    5. Set the tax class rates.
      Set the serialized string to the TaxRates property of the Tax instance. You can access the tax class rates as a collection through the TaxRateCollection property of the Tax instance. Note that you can only modify the collection by modifying the string value of the TaxRates property. For more information, see For developers: Set the tax class rates.
  5. Save the changes.
    To save the changes, call the SaveChanges method of the orders manager.

Use the following code sample:

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?

Next article

Query taxes