Tax classes


List of examples:

Tax classes

Creating a new tax class



// 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
TaxClassInfo.Provider.Set(newClass);

> Back to list of examples

Updating a tax class



// Gets the tax class
TaxClassInfo updateClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);
if (updateClass != null)
{
    // Updates the tax class properties
    updateClass.TaxClassDisplayName = updateClass.TaxClassDisplayName.ToLowerCSafe();

    // Saves the changes to the database
    TaxClassInfo.Provider.Set(updateClass);
}

> Back to list of examples

Updating multiple tax classes



// Gets all tax classes whose code name starts with 'NewClass'
var classes = TaxClassInfo.Provider.Get().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
    TaxClassInfo.Provider.Set(modifyClass);
}

> Back to list of examples

Assigning tax classes to products and shipping options



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets a department
DepartmentInfo department = DepartmentInfo.Provider.Get("NewDepartment", SiteContext.CurrentSiteID);

// Gets all products in the specified department
var products = SKUInfo.Provider.Get().WhereEquals("SKUDepartmentID", department.DepartmentID);

// Gets a shipping option
ShippingOptionInfo shippingOption = ShippingOptionInfo.Provider.Get("NewOption", SiteContext.CurrentSiteID);

if (taxClass != null)
{
    if (department != null)
    {
        // Assigns the tax class as the default class of the specified department
        department.DepartmentDefaultTaxClassID = taxClass.TaxClassID;
        DepartmentInfo.Provider.Set(department);
    }

    // Assigns the tax class to the specified products
    foreach (SKUInfo product in products)
    {
        product.SKUTaxClassID = taxClass.TaxClassID;
        SKUInfo.Provider.Set(product);
    }

    if (shippingOption != null)
    {
        // Assigns the tax class to the specified shipping option
        shippingOption.ShippingOptionTaxClassID = taxClass.TaxClassID;
        ShippingOptionInfo.Provider.Set(shippingOption);
    }
}

> Back to list of examples

Deleting a tax class



// Gets the tax class
TaxClassInfo deleteClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

if (deleteClass != null)
{
    // Deletes the tax class
    TaxClassInfo.Provider.Delete(deleteClass);
}

> Back to list of examples

Tax values for countries

Setting a country tax value for a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the country
CountryInfo country = CountryInfo.Provider.Get("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
    TaxClassCountryInfo.Provider.Set(newTaxCountry);
}

> Back to list of examples

Updating a country tax value of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the country
CountryInfo country = CountryInfo.Provider.Get("USA");

if ((taxClass != null) && (country != null))
{
    // Gets the object representing the tax class-country relationship
    TaxClassCountryInfo updateTaxCountry = TaxClassCountryInfo.Provider.Get(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
        TaxClassCountryInfo.Provider.Set(updateTaxCountry);
    }
}

> Back to list of examples

Updating multiple country tax values of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the country
CountryInfo country = CountryInfo.Provider.Get("USA");

if ((taxClass != null) && (country != null))
{                   
    // Gets the objects representing the relationships between the given country and the tax class
    var classCountries = TaxClassCountryInfo.Provider.Get()
                                                    .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
        TaxClassCountryInfo.Provider.Set(modifyClassCountry);
    }
}

> Back to list of examples

Deleting a country tax value of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the country
CountryInfo country = CountryInfo.Provider.Get("USA");

if ((taxClass != null) && (country != null))
{
    // Gets the object representing the tax class-country relationship
    TaxClassCountryInfo deleteTaxCountry = TaxClassCountryInfo.Provider.Get(country.CountryID, taxClass.TaxClassID);
    if (deleteTaxCountry != null)
    {
        // Deletes the tax value for the country
        TaxClassCountryInfo.Provider.Delete(deleteTaxCountry);
    }
}

> Back to list of examples

Tax values for states

Setting a state tax value for a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the state
StateInfo state = StateInfo.Provider.Get("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
    TaxClassStateInfo.Provider.Set(newTaxState);
}

> Back to list of examples

Updating a state tax value of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the state
StateInfo state = StateInfo.Provider.Get("Alabama");

if ((taxClass != null) && (state != null))
{                   
    // Gets the object representing the tax class-state relationship
    TaxClassStateInfo updateTaxState = TaxClassStateInfo.Provider.Get(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
        TaxClassStateInfo.Provider.Set(updateTaxState);
    }
}

> Back to list of examples

Updating multiple state tax values of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the state
StateInfo state = StateInfo.Provider.Get("Alabama");

if ((taxClass != null) && (state != null))
{                   
    // Gets the objects representing the relationships between the given state and the tax class
    var classStates = TaxClassStateInfo.Provider.Get()
                                                .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
        TaxClassStateInfo.Provider.Set(modifyClassState);
    }
}

> Back to list of examples

Deleting a state tax value of a tax class



// Gets the tax class
TaxClassInfo taxClass = TaxClassInfo.Provider.Get("NewClass", SiteContext.CurrentSiteID);

// Gets the state
StateInfo state = StateInfo.Provider.Get("Alabama");

if ((taxClass != null) && (state != null))
{
    // Gets the object representing the tax class-state relationship
    TaxClassStateInfo deleteTaxState = TaxClassStateInfo.Provider.Get(taxClass.TaxClassID, state.StateID);
    if (deleteTaxState != null)
    {
        // Deletes the tax value for the state
        TaxClassStateInfo.Provider.Delete(deleteTaxState);
    }
}

> Back to list of examples