Is this really the version you are looking for? Kentico Xperience 11 API is no longer updated. Use the switcher in the header to choose your product version.
// Creates a new tax class object
TaxClassInfo newClass = new TaxClassInfo();
// Sets the tax class properties
newClass.TaxClassDisplayName = "New class";
newClass.TaxClassName = "NewClass";
newClass.TaxClassSiteID = SiteContext.CurrentSiteID;
// Saves the tax class to the database
TaxClassInfoProvider.SetTaxClassInfo(newClass);// Gets the tax class
TaxClassInfo updateClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
if (updateClass != null)
{
// Updates the tax class properties
updateClass.TaxClassDisplayName = updateClass.TaxClassDisplayName.ToLowerCSafe();
// Saves the changes to the database
TaxClassInfoProvider.SetTaxClassInfo(updateClass);
}// Gets all tax classes whose code name starts with 'NewClass'
var classes = TaxClassInfoProvider.GetTaxClasses().WhereStartsWith("TaxClassName", "NewClass");
// Loops through the tax classes
foreach (TaxClassInfo modifyClass in classes)
{
// Updates the tax class properties
modifyClass.TaxClassDisplayName = modifyClass.TaxClassDisplayName.ToLowerCSafe();
// Saves the changes to the database
TaxClassInfoProvider.SetTaxClassInfo(modifyClass);
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets a department
DepartmentInfo department = DepartmentInfoProvider.GetDepartmentInfo("NewDepartment", SiteContext.CurrentSiteName);
// Gets all products in the specified department
var products = SKUInfoProvider.GetSKUs().WhereEquals("SKUDepartmentID", department.DepartmentID);
// Gets a shipping option
ShippingOptionInfo shippingOption = ShippingOptionInfoProvider.GetShippingOptionInfo("NewOption", SiteContext.CurrentSiteName);
if (taxClass != null)
{
if (department != null)
{
// Assigns the tax class as the default class of the specified department
department.DepartmentDefaultTaxClassID = taxClass.TaxClassID;
DepartmentInfoProvider.SetDepartmentInfo(department);
}
// Assigns the tax class to the specified products
foreach (SKUInfo product in products)
{
product.SKUTaxClassID = taxClass.TaxClassID;
SKUInfoProvider.SetSKUInfo(product);
}
if (shippingOption != null)
{
// Assigns the tax class to the specified shipping option
shippingOption.ShippingOptionTaxClassID = taxClass.TaxClassID;
ShippingOptionInfoProvider.SetShippingOptionInfo(shippingOption);
}
}// Gets the tax class
TaxClassInfo deleteClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
if (deleteClass != null)
{
// Deletes the tax class
TaxClassInfoProvider.DeleteTaxClassInfo(deleteClass);
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");
if ((taxClass != null) && (country != null))
{
// Creates a new object representing the tax class-country relationship
TaxClassCountryInfo newTaxCountry = new TaxClassCountryInfo();
// Sets the tax value for the given country within the tax class
newTaxCountry.TaxClassID = taxClass.TaxClassID;
newTaxCountry.CountryID = country.CountryID;
newTaxCountry.TaxValue = 10;
// Saves the changes to the database
TaxClassCountryInfoProvider.SetTaxClassCountryInfo(newTaxCountry);
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");
if ((taxClass != null) && (country != null))
{
// Gets the object representing the tax class-country relationship
TaxClassCountryInfo updateTaxCountry = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(country.CountryID, taxClass.TaxClassID);
if (updateTaxCountry != null)
{
// Updates the tax value for the given country in the tax class
updateTaxCountry.TaxValue = 20;
// Saves the changes to the database
TaxClassCountryInfoProvider.SetTaxClassCountryInfo(updateTaxCountry);
}
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");
if ((taxClass != null) && (country != null))
{
// Gets the objects representing the relationships between the given country and the tax class
var classCountries = TaxClassCountryInfoProvider.GetTaxClassCountries()
.WhereEquals("TaxClassID", taxClass.TaxClassID)
.WhereEquals("CountryID", country.CountryID);
// Loops through the tax class-country relationships
foreach (TaxClassCountryInfo modifyClassCountry in classCountries)
{
// Updates the tax value for the country in the tax class
modifyClassCountry.TaxValue = 30;
// Saves the changes to the database
TaxClassCountryInfoProvider.SetTaxClassCountryInfo(modifyClassCountry);
}
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the country
CountryInfo country = CountryInfoProvider.GetCountryInfo("USA");
if ((taxClass != null) && (country != null))
{
// Gets the object representing the tax class-country relationship
TaxClassCountryInfo deleteTaxCountry = TaxClassCountryInfoProvider.GetTaxClassCountryInfo(country.CountryID, taxClass.TaxClassID);
if (deleteTaxCountry != null)
{
// Deletes the tax value for the country
TaxClassCountryInfoProvider.DeleteTaxClassCountryInfo(deleteTaxCountry);
}
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");
if ((taxClass != null) && (state != null))
{
// Creates a new object representing the tax class-state relationship
TaxClassStateInfo newTaxState = new TaxClassStateInfo();
// Sets the tax value for the given state within the tax class
newTaxState.TaxClassID = taxClass.TaxClassID;
newTaxState.StateID = state.StateID;
newTaxState.TaxValue = 10;
// Saves the changes to the database
TaxClassStateInfoProvider.SetTaxClassStateInfo(newTaxState);
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");
if ((taxClass != null) && (state != null))
{
// Gets the object representing the tax class-state relationship
TaxClassStateInfo updateTaxState = TaxClassStateInfoProvider.GetTaxClassStateInfo(taxClass.TaxClassID, state.StateID);
if (updateTaxState != null)
{
// Updates the tax value for the given state in the tax class
updateTaxState.TaxValue = 20;
// Saves the changes to the database
TaxClassStateInfoProvider.SetTaxClassStateInfo(updateTaxState);
}
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");
if ((taxClass != null) && (state != null))
{
// Gets the objects representing the relationships between the given state and the tax class
var classStates = TaxClassStateInfoProvider.GetTaxClassStates()
.WhereEquals("TaxClassID", taxClass.TaxClassID)
.WhereEquals("StateID", state.StateID);
// Loops through the tax class-state relationships
foreach (TaxClassStateInfo modifyClassState in classStates)
{
// Updates the tax value for the state in the tax class
modifyClassState.TaxValue = 30;
// Saves the changes to the database
TaxClassStateInfoProvider.SetTaxClassStateInfo(modifyClassState);
}
}// Gets the tax class
TaxClassInfo taxClass = TaxClassInfoProvider.GetTaxClassInfo("NewClass", SiteContext.CurrentSiteName);
// Gets the state
StateInfo state = StateInfoProvider.GetStateInfo("Alabama");
if ((taxClass != null) && (state != null))
{
// Gets the object representing the tax class-state relationship
TaxClassStateInfo deleteTaxState = TaxClassStateInfoProvider.GetTaxClassStateInfo(taxClass.TaxClassID, state.StateID);
if (deleteTaxState != null)
{
// Deletes the tax value for the state
TaxClassStateInfoProvider.DeleteTaxClassStateInfo(deleteTaxState);
}
}