Export (0) Print
Expand All
Expand Minimize

SampleRegionalTax

Commerce Server 2002

Use this component for calculating taxes in pipelines using the multiple shipment features of Commerce Server 2002.

Ee783686.note(en-US,CS.20).gif Note

  • The SampleRegionalTax component is not a complete solution to tax calculation. It is provided as an example of a tax component that takes full advantage of the multiple shipment features of Commerce Server 2002. Microsoft strongly recommends that you purchase a third-party tax component.

Intended use: Order Processing pipeline, Tax stage.

Configuration Values

None.

Values Read

The SampleRegionalTax component reads the following values from the indicated dictionaries.

KeyDictionaryDescription
shipmentsOrderA SimpleList object of shipments.
item._cy_oadjust_adjustedpriceOrderThe total price of all the items, after all the discounts have been applied.
RegionalTaxCacheContextA reference to a dictionary containing tax information.

In addition, the SampleRegionalTax component reads the following keys from the Addresses dictionary in the OrderForm object.

KeyDescription
addresses.country_codeThe ship to country/region for the address ID retrieved for the shipment.
addresses.region_codeOptional. The ship to region for the address ID retrieved for the shipment.

Values Written

The SampleRegionalTax component writes the following values to the Order dictionary.

KeyDescription
item._cy_tax_totalThe total tax for the item.
item._cy_tax_includedThe total tax for the item included in the cost. You must set this key to zero (0).
shipment._cy_tax_totalThe total tax for the shipment.
shipment._cy_tax_includedThe total tax for the shipment included in the cost. You must set this key to zero (0).
_cy_tax_totalThe total tax for the order.
_cy_tax_includedThe total tax for the order included in the cost. You must set this key to zero (0).

Remarks

The SampleRegionalTax component computes tax for the Commerce Server 2002 shipping architecture that handles multiple shipments. For more information about how Commerce Server processes shipments, see Multiple-shipment Shipping Architecture.

For each shipment in the order, the component first gets the tax rate from the database using the CacheManager object and stores it in the SampleRegionalTaxCache component.

The SampleRegionalTax component then goes through each item in the shipment and calculates its tax based on the rate retrieved from the tax rate table. Rates are retrieved based on the country/region codes in the dictionary of addresses in the Order dictionary. For more information about the dictionary of addresses, see Multiple-shipment Shipping Architecture.

As it goes through the items and shipments in the order, the SampleRegionalTax component accumulates totals for the items, shipments, and, finally, for the entire order.

The tax rate data stored in the SampleRegionalTaxCache component is a snapshot of the RegionalTax database table. The RegionalTax table contains three columns.

ColumnData TypeDescription
country_codeString, 255 characters.The country code.
region_codeString, 255 characters.The region code.
rateFloat, 8 bytes.The tax rate.

You may include a wildcard entry (@) for a region code. This will match regions that would not otherwise match. If no entry is found in the RegionalTax table, the rate is zero (0).

Using a pipeline containing the SampleRegionalTax component is very similar to using a Content Selection pipeline. First, you configure the CacheManager object to use the SampleRegionalTaxCache loader in the Application_OnStart section of the Global.asa file. Then, in the Active Server Pages (ASP) page, you add an entry for the CacheManager object to the Context dictionary and invoke the pipeline.

Setup code in the Application_OnStart method:

    ' Create a Dictionary to hold configuration information.
    Set dConfig = CreateObject("Commerce.Dictionary")

    ' Add configuration information to the dictionary. SampleRegtionalTax
    ' only uses a connection string.
    dConfig("ConnectionString") = "DSN=adsamples;UID=username;PWD=******"

    ' Create a CacheManager object.
    Set CacheManager = Server.CreateObject("Commerce.CacheManager")

    ' Set the ProgID of the Loader component for the
    ' "SampleRegionalTaxCache" cache.
    CacheManager.LoaderProgId("SampleRegionalTaxCache") = _
                    "Commerce.SampleRegionalTaxCache"

    ' Set the Loader component config Dictionary for the cache.
    Set CacheManager.LoaderConfig("SampleRegionalTaxCache") = dConfig

    '
    ' Other CacheManager configuration code would appear here.
    '

    ' Store a reference to the CacheManager in the Application object.
    Set Application("CacheManager") = CacheManager

Code to run the pipeline containing the SampleRegionalTax component:

    ' Place a reference to the CacheManager in the context dictionary.
    Set dContext = Server.CreateObject("Commerce.Dictionary")
    dContext.CacheManager = Application("CacheManager")

    '
    ' Set other values and create the Order dictionary (dOrder) here.
    '

    ' Load and run the pipeline containing the tax component.
    Set pPooledPipe = Server.CreateObject("Commerce.PooledPipeline")
    pPooledPipe.LoadPipe("OrderAndTax.pcf")
    iErrVal = pPooledPipe.Execute(0, dOrder, dContext, 1)

Code to query the SampleRegionalTax cache for a specific tax rate:

     ' Initialize the TaxRates dictionary as Dictionary object.
   ' Retrieve the tax rate for a specific country_code and region_code.
   Dim TaxRates As CDictionary
   Set TaxRates = _
objContext("CacheManager").GetCache("SampleRegionalTaxCache").Cache_("US")("WA")

See Also

Multiple-shipment Shipping Architecture

CacheManager Object

PooledPipeline Object

PooledTxPipeline Object

Copyright © 2005 Microsoft Corporation.
All rights reserved.
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft