Commerce Server General - problem with tax when changing address state

This is Interesting: Free IT Magazines  
Home > Archive > Commerce Server General > November 2006 > problem with tax when changing address state





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author problem with tax when changing address state
briguy

2006-11-06, 7:24 pm

Whenever I change the address state (say from California to New York)
on my shipping page, my the Tax amount in my cart doesn't change. I
actually have to either select a different address or create an
entirely new address. Has someone found a way to recalcate the tax
amount when the state changes on the shipping address DURING checkout?
It seems like the pipeline won't recalculate it since the same address
is being used (despite the state change).

Colin Bowern

2006-11-06, 7:24 pm

Hey Brian,

Is this CS2002? Are you using the StarterSite and/or sample tax components
in the pipeline?

Cheers,
Colin

--
The group is moving! Check out Commerce Server discussion forums on MSDN:
http://forums.microsoft.com/msdn/de...id=294&SiteID=1

For more on my experiences with Commerce Server:
http://colin.rockstarguys.com

"briguy" <brian@webmetro.com> wrote in message
news:1162842129.772003.239350@m7g2000cwm.googlegroups.com...
> Whenever I change the address state (say from California to New York)
> on my shipping page, my the Tax amount in my cart doesn't change. I
> actually have to either select a different address or create an
> entirely new address. Has someone found a way to recalcate the tax
> amount when the state changes on the shipping address DURING checkout?
> It seems like the pipeline won't recalculate it since the same address
> is being used (despite the state change).
>

briguy

2006-11-06, 7:24 pm

Yes, I am using CS2002 FP1 and I'm using the StaterSite as a basis for
my customized site (along with the SampleRegionalTax component in the
pipeline). I've modified the checkout allow the user to modify the
address selected on the checkout shipping page.

Colin Bowern

2006-11-06, 7:24 pm

Hey Brian,

The SampleRegionalTax component is a COM object (as opposed to .NET COM
wrapped assembly) and as such it's a bit of a black box. You might need to
replace it with your own. The product group is likely to say the same
because it was meant only to be a sample (see
http://msdn2.microsoft.com/en-us/library/aa485754.aspx).

That being said I believe it is just the Site Server 3.0 component in a
nutshell. From the Site Server site there was a note that if the _tax_*
values are set that it will not do any work (see
http://msdn2.microsoft.com/en-us/library/aa485753.aspx).

If that doesn't work then you could probably write a new pipeline component
faster than trying to debug it. Here's a peek at an old tax component I
wrote as a starting point (note the OrderForm wrapper is a custom in-house
object which provides strongly typed access to the dictionary):

int ReturnValue = ComponentErrorLevel.Success;

Dictionary Context = null;
IMessageManager MessageManager = null;
OrderForm OrderFormObject = null;
try
{
// Retrieve the required collections. It is all required and will throw a
cast
// exception if it was not included in the order form.
Context = (Dictionary) pdispContext;
MessageManager = (IMessageManager) Context[ContextField.MessageManager];
OrderFormObject = new
OrderForm((Microsoft.CommerceServer.Interop.Orders.IOrderForm) pdispOrder);

// Retrieve the currency information. It is all required and will throw a
cast
// exception if it was not included in the order form.
string BillingCurrency = OrderFormObject.BillingCurrency;
int DecimalPlaces = OrderFormObject.BillingCurrencyDecimalPlaces;
decimal ExchangeRate = OrderFormObject.BillingCurrencyExchangeRate;

// Initialize order-level totals.
decimal OrderLevelTaxTotal_CA = decimal.Zero;
decimal OrderLevelTaxTotal_CA_ON = decimal.Zero;
decimal OrderLevelTaxTotal = decimal.Zero;

// Process Individual Line Items
for(int index = 0; index < OrderFormObject.Items.Count; index++)
{
Item Entry = OrderFormObject.Items[index];

decimal ItemLevelTaxTotal = decimal.Zero;

// Calculate Canadian Goods and Services Tax (CA)
decimal ItemLevelTaxTotal_CA = Currency.Round(DecimalPlaces,
CalculateTaxTotal(Context, OrderFormObject.Addresses[AddressKey.Billing],
OrderFormObject.Addresses[Entry.ShippingAddressId], Entry.TaxCanadaGst,
"CA", Entry.ExtendedPrice));

// Calculate Ontario Retail Services Tax (CA_ON)
decimal ItemLevelTaxTotal_CA_ON = Currency.Round(DecimalPlaces,
CalculateTaxTotal(Context, OrderFormObject.Addresses[AddressKey.Billing],
OrderFormObject.Addresses[Entry.ShippingAddressId], Entry.TaxOntarioRst,
"CA", "ON", Entry.ExtendedPrice));

// Sum up the line item taxes. Values should already be rounded to the
appropriate number of decimal places.
ItemLevelTaxTotal += ItemLevelTaxTotal_CA;
ItemLevelTaxTotal += ItemLevelTaxTotal_CA_ON;

// Commit values to the item entry
Entry.TaxTotalCanadaGst = ItemLevelTaxTotal_CA;
Entry.TaxTotalOntarioRst = ItemLevelTaxTotal_CA_ON;
Entry.TaxTotal = ItemLevelTaxTotal;

// Update order-level values.
OrderLevelTaxTotal_CA += ItemLevelTaxTotal_CA; OrderLevelTaxTota
l_CA_ON
+= ItemLevelTaxTotal_CA_ON;
OrderLevelTaxTotal += ItemLevelTaxTotal;

// Zero out the Tax Included as it is not calculated.
Entry.TaxIncluded = decimal.Zero;
}

// Process Individual Shipments
for(int index = 0; index < OrderFormObject.Shipments.Count; index++)
{
Shipment Entry = OrderFormObject.Shipments[index];
Address DeliveryAddress =
OrderFormObject.Addresses[Entry.ShippingAddressId];

decimal ShipmentLevelTaxTotal = decimal.Zero;

// GST if address is destined inside Canada
decimal ShipmentLevelTaxTotal_CA = Currency.Round(DecimalPlaces,
CalculateTaxTotal(Context, DeliveryAddress, "CA", Entry.ShippingTotal));

// RST if address is destined inside Ontario
decimal ShipmentLevelTaxTotal_CA_ON = Currency.Round(DecimalPlaces,
CalculateTaxTotal(Context, DeliveryAddress, "CA", "ON",
Entry.ShippingTotal));

// Sum up the line item taxes. Values should already be rounded to the
appropriate number of decimal places.
ShipmentLevelTaxTotal += ShipmentLevelTaxTotal_CA;
ShipmentLevelTaxTotal += ShipmentLevelTaxTotal_CA_ON;

// Commit values to the shipment entry
Entry.TaxTotalCanadaGst = ShipmentLevelTaxTotal_CA;
Entry.TaxTotalOntarioRst = ShipmentLevelTaxTotal_CA_ON;
Entry.TaxTotal = ShipmentLevelTaxTotal;

// Update order-level values.
OrderLevelTaxTotal_CA += ShipmentLevelTaxTotal_CA; OrderLevelTax
Total_CA_ON
+= ShipmentLevelTaxTotal_CA_ON;
OrderLevelTaxTotal += ShipmentLevelTaxTotal; // Zero out the Tax Included as it is not calculated.
Entry.TaxIncluded = decimal.Zero;
}

// Commit Order Level Totals
OrderFormObject.TaxTotalCanadaGst = OrderLevelTaxTotal_CA;
OrderFormObject.TaxTotalOntarioRst = OrderLevelTaxTotal_CA_ON;
OrderFormObject.TaxTotal = OrderLevelTaxTotal;
OrderFormObject.TaxIncluded = decimal.Zero;
}
catch(Exception ex)
{
ReturnValue = ComponentErrorLevel.Error;

// Write the exception to the event log.
AdminLib.AdminEventLogClass eventLog = new AdminLib.AdminEventLogClass();
eventLog.WriteErrorEvent(this.GetProgID(), ex.ToString());

// Write a generic error to the basket errors if the Message Manager and
Order Form
// are accessible.
if( (MessageManager != null) &&
(OrderFormObject != null) &&
(OrderFormObject.BasketErrors != null))
OrderFormObject.BasketErrors.Add(MessageManager.GetMessage(MessageKey.InternalSystemError,
MessageManager.defaultLanguage));
}

return ReturnValue;

Cheers,
Colin

"briguy" <brian@webmetro.com> wrote in message
news:1162844293.673236.264120@f16g2000cwb.googlegroups.com...
> Yes, I am using CS2002 FP1 and I'm using the StaterSite as a basis for
> my customized site (along with the SampleRegionalTax component in the
> pipeline). I've modified the checkout allow the user to modify the
> address selected on the checkout shipping page.
>

briguy

2006-11-06, 7:24 pm

Thanks Colin for your help! =)

If I don't time time to write my own component, would I be able to get
by with setting the TaxTotal field in the Cart to null and then
re-running the Total pipeline? Other than that, have you had an luck
with using the SimpleUSTax component instead of the SampleRegionalTax?

Brian

Colin Bowern

2006-11-06, 7:24 pm

Hi Brian,

Setting the _tax* fields to null and re-running the component would be my
first attempt. We never ended up using the out-of-the-box tax components
because we had scenarios to address where tax may or may not apply depending
on product types, etc...

Cheers!
Colin

"briguy" <brian@webmetro.com> wrote in message
news:1162852235.904092.155850@e3g2000cwe.googlegroups.com...
> Thanks Colin for your help! =)
>
> If I don't time time to write my own component, would I be able to get
> by with setting the TaxTotal field in the Cart to null and then
> re-running the Total pipeline? Other than that, have you had an luck
> with using the SimpleUSTax component instead of the SampleRegionalTax?
>
> Brian
>

briguy

2006-11-06, 7:24 pm

Thanks again! =)

I've been trying to reset the TaxTotal field in the OrderForm object of
the Cart object but it is read-only. Any tips?

Brian

Colin Bowern

2006-11-06, 7:24 pm

Access it using the indexer -

orderForm["_cy_tax_total"] = null;

Cheers,
Colin

"briguy" <brian@webmetro.com> wrote in message
news:1162854782.003859.305260@e3g2000cwe.googlegroups.com...
> Thanks again! =)
>
> I've been trying to reset the TaxTotal field in the OrderForm object of
> the Cart object but it is read-only. Any tips?
>
> Brian
>

briguy

2006-11-06, 7:24 pm

I used the following:

TransactionContext.Current.Cart.OrderForm["_cy_tax_total"] = null;

....but this field is already null. Am I looking at the wrong field?

Colin Bowern

2006-11-07, 1:22 am

Brian,

That looks right. The field is a temporary field (denoted by the "_"
prefix), so it will be null until you run the pipeline to do the
calculation.

Can you enable and look at the pipeline log to ensure that your original
assumption is correct that nothing is being set by the component? The
reason I ask is that I know that component is particular about the field
that is set (address["region_code"] and address["country_code"]). I'm
wondering if the right fields are being changed during the address update.
The pipelog will show you both the values read and written.

For information on getting access to the pipeline logs and dumping order
forms check out this paper if you haven't already:

Troubleshooting Commerce Server Pipelines
http://msdn2.microsoft.com/en-us/library/ms959842.aspx

Cheers,
Colin

"briguy" <brian@webmetro.com> wrote in message
news:1162857052.857881.239640@h54g2000cwb.googlegroups.com...
>I used the following:
>
> TransactionContext.Current.Cart.OrderForm["_cy_tax_total"] = null;
>
> ...but this field is already null. Am I looking at the wrong field?
>

briguy

2006-11-07, 1:22 am

Colin,

I found the problem before I got your last response. The RegionCode
field isn't set in the SetBasketDefaults() function in the StarterSite.
I modified the function to set to to userAddress.StateProvince and the
problem went away.

Thanks for your insight,
Brian

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com