1

我正在尝试实现以下场景,但不确定如何配置商店的税级,因为任何人都试图实现以下目标:

  • 如果在 Y 国,则需缴纳 23% 的税。
  • 如果未提供国家 Y 和税号,则零税,否则 23% 税。

我试图创建 2 个单独的税类:

  • 正常,Y 国为 23%。
  • 国际,所有国家/地区 23%,如果提供税号,则零税。

但是,我如何确保 International 不适用于 Y 国?它似乎不允许您从列表中删除国家/地区。

4

1 回答 1

1

在 Kentico 中处理复杂的税务逻辑需要一些自定义开发(至少在 v7 中,我相信 v8 就税务计算而言没有太大变化)。如果您将观看此网络研讨会,其中有一节讨论了自定义 TaxClassInfoProviders。它还包括一些代码示例,您可以下载这些示例以帮助您入门。

这是修改税收计算过程的一种方法。它基于上面链接的网络研讨会中的示例文件之一:

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 类,这也是上面链接中的示例文件之一:

/// <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 中的任何位置添加这些文件,您应该一切顺利。如果您有任何问题,请告诉我。

于 2015-12-11T19:47:34.327 回答