国际和国内税 类
International and national tax classes
我正在尝试实现以下场景,但不确定如何配置商店的税收 类,因为有人试图实现以下目标:
- 如果在 Y 国则征收 23% 的税。
- 如果未提供国家 Y 和税号,则为零税,否则为 23% 税。
我尝试创建 2 个单独的税 类:
- 正常,Y 国为 23%。
- 国际,所有国家/地区为 23%,如果提供税号则为零税。
但是我如何确保 International 不适用于 Y 国?它似乎不允许您从列表中删除国家/地区。
在 Kentico 中处理复杂的税收逻辑将需要一些自定义开发(至少在 v7 中是这样,我相信就税收计算而言,v8 并没有太大变化)。如果您将观看 this webinar,则有一节讨论自定义 TaxClassInfoProvider。它还包括一些代码示例,您可以下载这些代码示例以帮助您入门。
这是修改税收计算过程的一种方法。它基于网络研讨会 link 上面的示例文件之一:
public class CustomTaxClassInfoProvider : TaxClassInfoProvider
{
#region Properties
private ShoppingCartInfo Cart
{
get
{
return ECommerceContext.CurrentShoppingCart;
}
}
private string CustomerZipCode
{
get
{
AddressInfo customerAddress = AddressInfoProvider.GetAddressInfo(Cart.ShoppingCartShippingAddressID);
if(customerAddress != null)
return customerAddress.AddressZip;
return null;
}
}
#endregion
/// <summary>
/// Returns DataSet with all the taxes which should be applied to the shopping cart items.
/// </summary>
/// <param name="cart">Shopping cart</param>
protected override DataSet GetTaxesInternal(ShoppingCartInfo cart)
{
DataSet taxDataSet = new DataSet();
// Create an empty taxes table
DataTable table = GetNewTaxesTable();
List<TaxRow> taxRows = new List<TaxRow>();
foreach (ShoppingCartItemInfo item in cart.CartItems)
{
TaxRow row = new TaxRow();
row.SKUID = item.SKU.SKUID;
row.SKUGUID = item.SKU.SKUGUID;
taxRows.Add(row);
}
foreach (TaxRow row in taxRows)
{
double rate = 0;
string name = "";
// Add conditions for different tax rates here
// --------------------------------------------
// For Example
if (cart.Customer.CustomerCountryID == countryYouWantToExclude)
{
rate = yourTaxRate;
name = "Name for the tax";
}
else
{
rate = 0;
name = "";
}
row.TaxRate = rate;
row.TaxName = name;
}
BuildTaxTable(ref table, taxRows);
// Return our dataset with the taxes
taxDataSet.Tables.Add(table);
return taxDataSet;
}
private void BuildTaxTable(ref DataTable table, List<TaxRow> taxRows)
{
foreach (TaxRow row in taxRows)
{
AddTaxRow(table, row.SKUID, row.TaxName, row.TaxRate);
}
}
private DataTable GetNewTaxesTable()
{
DataTable table = new DataTable();
// Add required columns
table.Columns.Add("SKUID", typeof(int));
table.Columns.Add("TaxClassDisplayName", typeof(string));
table.Columns.Add("TaxValue", typeof(double));
return table;
}
private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue, bool taxIsFlat, bool taxIsGlobal, bool zeroTaxIfIDSupplied)
{
DataRow row = taxTable.NewRow();
// Set required columns
row["SKUID"] = skuId;
row["TaxClassDisplayName"] = taxName;
row["TaxValue"] = taxValue;
// Set optional columns
//row["TaxIsFlat"] = taxIsFlat;
//row["TaxIsGlobal"] = taxIsGlobal;
//row["TaxClassZeroIfIDSupplied"] = taxIsGlobal;
taxTable.Rows.Add(row);
}
private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue)
{
AddTaxRow(taxTable, skuId, taxName, taxValue, false, false, false);
}
}
/// <summary>
/// Represents a DataRow to be inserted into the tax calculation data table
/// </summary>
public class TaxRow
{
public int SKUID { get; set; }
public Guid SKUGUID { get; set; }
public string TaxName { get; set; }
public double TaxRate { get; set; }
public TaxRow()
{
}
}
然后您需要设置 CMSModuleLoader class,这也是上面 link 中的示例文件之一:
/// <summary>
/// Sample e-commerce module class. Partial class ensures correct registration.
/// </summary>
[SampleECommerceModuleLoader]
public partial class CMSModuleLoader
{
#region "Macro methods loader attribute"
/// <summary>
/// Module registration
/// </summary>
private class SampleECommerceModuleLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Constructor
/// </summary>
public SampleECommerceModuleLoaderAttribute()
{
// Require E-commerce module to load properly
RequiredModules = new string[] { ModuleEntry.ECOMMERCE };
}
/// <summary>
/// Initializes the module
/// </summary>
public override void Init()
{
TaxClassInfoProvider.ProviderObject = new CustomTaxClassInfoProvider();
}
}
#endregion
}
将这些文件添加到 AppCode 中的任何位置,您就可以开始了。如果您有任何问题,请告诉我。
我正在尝试实现以下场景,但不确定如何配置商店的税收 类,因为有人试图实现以下目标:
- 如果在 Y 国则征收 23% 的税。
- 如果未提供国家 Y 和税号,则为零税,否则为 23% 税。
我尝试创建 2 个单独的税 类:
- 正常,Y 国为 23%。
- 国际,所有国家/地区为 23%,如果提供税号则为零税。
但是我如何确保 International 不适用于 Y 国?它似乎不允许您从列表中删除国家/地区。
在 Kentico 中处理复杂的税收逻辑将需要一些自定义开发(至少在 v7 中是这样,我相信就税收计算而言,v8 并没有太大变化)。如果您将观看 this webinar,则有一节讨论自定义 TaxClassInfoProvider。它还包括一些代码示例,您可以下载这些代码示例以帮助您入门。
这是修改税收计算过程的一种方法。它基于网络研讨会 link 上面的示例文件之一:
public class CustomTaxClassInfoProvider : TaxClassInfoProvider
{
#region Properties
private ShoppingCartInfo Cart
{
get
{
return ECommerceContext.CurrentShoppingCart;
}
}
private string CustomerZipCode
{
get
{
AddressInfo customerAddress = AddressInfoProvider.GetAddressInfo(Cart.ShoppingCartShippingAddressID);
if(customerAddress != null)
return customerAddress.AddressZip;
return null;
}
}
#endregion
/// <summary>
/// Returns DataSet with all the taxes which should be applied to the shopping cart items.
/// </summary>
/// <param name="cart">Shopping cart</param>
protected override DataSet GetTaxesInternal(ShoppingCartInfo cart)
{
DataSet taxDataSet = new DataSet();
// Create an empty taxes table
DataTable table = GetNewTaxesTable();
List<TaxRow> taxRows = new List<TaxRow>();
foreach (ShoppingCartItemInfo item in cart.CartItems)
{
TaxRow row = new TaxRow();
row.SKUID = item.SKU.SKUID;
row.SKUGUID = item.SKU.SKUGUID;
taxRows.Add(row);
}
foreach (TaxRow row in taxRows)
{
double rate = 0;
string name = "";
// Add conditions for different tax rates here
// --------------------------------------------
// For Example
if (cart.Customer.CustomerCountryID == countryYouWantToExclude)
{
rate = yourTaxRate;
name = "Name for the tax";
}
else
{
rate = 0;
name = "";
}
row.TaxRate = rate;
row.TaxName = name;
}
BuildTaxTable(ref table, taxRows);
// Return our dataset with the taxes
taxDataSet.Tables.Add(table);
return taxDataSet;
}
private void BuildTaxTable(ref DataTable table, List<TaxRow> taxRows)
{
foreach (TaxRow row in taxRows)
{
AddTaxRow(table, row.SKUID, row.TaxName, row.TaxRate);
}
}
private DataTable GetNewTaxesTable()
{
DataTable table = new DataTable();
// Add required columns
table.Columns.Add("SKUID", typeof(int));
table.Columns.Add("TaxClassDisplayName", typeof(string));
table.Columns.Add("TaxValue", typeof(double));
return table;
}
private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue, bool taxIsFlat, bool taxIsGlobal, bool zeroTaxIfIDSupplied)
{
DataRow row = taxTable.NewRow();
// Set required columns
row["SKUID"] = skuId;
row["TaxClassDisplayName"] = taxName;
row["TaxValue"] = taxValue;
// Set optional columns
//row["TaxIsFlat"] = taxIsFlat;
//row["TaxIsGlobal"] = taxIsGlobal;
//row["TaxClassZeroIfIDSupplied"] = taxIsGlobal;
taxTable.Rows.Add(row);
}
private void AddTaxRow(DataTable taxTable, int skuId, string taxName, double taxValue)
{
AddTaxRow(taxTable, skuId, taxName, taxValue, false, false, false);
}
}
/// <summary>
/// Represents a DataRow to be inserted into the tax calculation data table
/// </summary>
public class TaxRow
{
public int SKUID { get; set; }
public Guid SKUGUID { get; set; }
public string TaxName { get; set; }
public double TaxRate { get; set; }
public TaxRow()
{
}
}
然后您需要设置 CMSModuleLoader class,这也是上面 link 中的示例文件之一:
/// <summary>
/// Sample e-commerce module class. Partial class ensures correct registration.
/// </summary>
[SampleECommerceModuleLoader]
public partial class CMSModuleLoader
{
#region "Macro methods loader attribute"
/// <summary>
/// Module registration
/// </summary>
private class SampleECommerceModuleLoaderAttribute : CMSLoaderAttribute
{
/// <summary>
/// Constructor
/// </summary>
public SampleECommerceModuleLoaderAttribute()
{
// Require E-commerce module to load properly
RequiredModules = new string[] { ModuleEntry.ECOMMERCE };
}
/// <summary>
/// Initializes the module
/// </summary>
public override void Init()
{
TaxClassInfoProvider.ProviderObject = new CustomTaxClassInfoProvider();
}
}
#endregion
}
将这些文件添加到 AppCode 中的任何位置,您就可以开始了。如果您有任何问题,请告诉我。