Developer forum

Forum » Development » Weird error in the Cart

Weird error in the Cart

Martin Nielsen
Reply

Hi DW,

 

I'm seeing a weird error the cart on one of our custom solutions.

I'm not sure exactly what triggers the error, and it doesn't happen everytime. I can recreate it though.

 

This is the error i get:

Logging 'Exception':
Type: System.Data.SqlClient.SqlException
Message: The incoming tabular data stream (TDS) remote procedure call (RPC) protocol stream is incorrect. Parameter 8 ("@p6"): The supplied value is not a valid instance of data type float. Check the source data for invalid values. An example of an invalid value is data of numeric type with scale greater than precision.
StackTrace:    at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount)
   at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping)
   at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable)
   at System.Data.Common.DbDataAdapter.Update(DataSet dataSet)
   at Dynamicweb.eCommerce.Orders.Order.SaveOrder(String IDStr, Boolean saveOldVersion)
   at Dynamicweb.eCommerce.Orders.Order.Save(String IDStr, Boolean saveOldVersion)
   at Dynamicweb.eCommerce.Products.Taxes.TaxSettingCollection.AddTaxesToOrder(Order order, Boolean addTaxesToCompleteOrder, Boolean SaveOrder)
   at Dynamicweb.eCommerce.Cart.Frontend.GetContent()

And i have more than one item in my cart, and i use a discount that gives 100%, (Order total amount is 0)

 

I cannot quite determine if this is an error in my customcode or something in DW.

 

Have you seen it before?

 

// Martin

 

 


Replies

 
Martin Nielsen
Reply

When this occurs my cart is cleared, and the cart module isn't rendered, or renders a blank string.

The error is then found in the EcomHandler log.

 

 
Martin Nielsen
Reply

Okay. So i hunted down what caused the error, and it's my code the changing the VAT.

 

A few months ago, with Jeppe's assistance, i managed to make some logic that sets the VAT to 0 on selected countries, and this seems to be the cause of the above error. Here's the thread about the VAT logic:

http://developer.dynamicweb-cms.com/forum/development/how-do-i-change-the-vat-on-an-order.aspx

 

I would really appreciate if someone could look at this issue even if it's pretty custom :-)

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Martin,

 

This issue is caused by the PriceBeforeFees value becoming less than 0 because the discount line is calculated before your notification subscriber is invoked, which leads to the discount line containing VAT while the product lines do not. This causes VATPercent of PriceBeforeFees to become minus infinity (-1#INF) and .NET sees that value as a valid double; Sql Server, however, does not.

 

The easiest workaround is to turn off the Differentiate on VAT groups setting in Management Center -> eCommerce -> Advanced configuration -> Sales discounts. This will cause the discount lines to be calculated based on the PriceInfo of the product lines and the correct VAT is then used.

 

We'll have a discussion internally about adding a code fix to prevent this scenario but there are a lot of price calculations hooked into this, so we need to make sure we don't break anything :)

 

Are you still on 8.2.1.11? If so, you might want to consider migrating to at least 8.2.3.X, preferrably 8.3, as any potential fix won't be added to any older branch than 8.2.3.X.

 

Hope this helps :)

 

- Jeppe

 

 

 
Martin Nielsen
Reply

Hi Jeppe,

 

Thank you for looking into this.

 

If i disable "Differentiate on VAT groups" i run into another issue that i described in this thread last week: http://developer.dynamicweb-cms.com/forum/development/difference-in-orderlines-accross-2-solutions.aspx

 

Are there any other tricks that could fix this?

 

If not, i'll just have to rewrite my Discount logic, since completing orders is more important :-)

 

 

And yes, we're still on 8.2.1.11, and probably should upgrade soon :-)

 

 

// Matin

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Just so I'm completely clear on what you're trying to achieve.

 

You want

- to set VAT to 0% for all product lines for certain countries

- a 100% order discount for all countries

 

What about fees? Are they discounted as well, and if not, do they have a VAT that is different from the product lines?

 

The problem is, that you want to control the VAT but cannot do it all the time.

A possible solution would be to not use the Discount functionality in eCom and add your own Order Discount line when you know the VAT. That way you control the VAT of the discount.

 

If you do not need to have different VAT on product lines and fees, then the best solution is to implement a VatProvider. I've taken your code and added it in the context of a VatProvider here, so you should be able to copy/paste directly. Code is sent to you via email.

 

- Jeppe

 

 

You must be logged in to post in the forum