Developer forum

Forum » Development » Dynamicweb.eCommerce.Prices.PriceInfoCurrencyException: Attempt to aritmatic with two prices of different currency at Dynamicweb.eCommerce.Prices.PriceInfo.Add

Dynamicweb.eCommerce.Prices.PriceInfoCurrencyException: Attempt to aritmatic with two prices of different currency at Dynamicweb.eCommerce.Prices.PriceInfo.Add

Dmitrij Jazel
Reply

Hi Everybody,

Having problem with webshop that uses many currencies.

Site has one default currency - that is euro. But in API,  in the "PageLoaded" notification subscriber - currency is set to something else for users with some specific IPs.

Any ideas how can I avoid this error???

 

Here is full error message:

Dynamicweb.eCommerce.Prices.PriceInfoCurrencyException: Attempt to aritmatic with two prices of different currency at Dynamicweb.eCommerce.Prices.PriceInfo.Add(IPriceInfo info) at Dynamicweb.eCommerce.Prices.PriceInfo.Add(IPriceReferenceInfo info) at Dynamicweb.eCommerce.Orders.OrderLineCollection.get_Price() at Dynamicweb.eCommerce.Orders.Order.get_PriceBeforeFees() at Dynamicweb.eCommerce.Orders.ShippingCalculator.TryFindFeeFromMatrix(Order order, ShippingCalculationResult& calcRes) at Dynamicweb.eCommerce.Orders.ShippingCalculator.Calculate(Order order) at Dynamicweb.eCommerce.Orders.Order.GetShippingFeeInfo(PriceInfo& price, String& shippingFeeRuleName) at Dynamicweb.eCommerce.Orders.Order.SaveOrder(String IDStr, Boolean saveOldVersion) at Dynamicweb.eCommerce.Orders.Order.Save(String IDStr, Boolean saveOldVersion) at Dynamicweb.eCommerce.Cart.Frontend.GetOrder() at Dynamicweb.eCommerce.Cart.Frontend.GetContent()

 

 


Replies

 
Nicolai Pedersen
Reply

When does this happen? Doing what?

 
Dmitrij Jazel
Reply

This happens when users is oppening cart module.

Cart module does not gets rendered, but instead users gets error message.

 

Would be great to somehow avoid it,

 

Strange why this error appears, as user did not add anything to the cart, But appears as soon as atleast 1 product gets added to the cart.

 
Dmitrij Jazel
Reply

I understand if this error would popup, if you had an initiated product cart with euro products, and than you switched to danish krona. and than started adding to cart.

I can imagine that this error would be appropriate. But in this case we are with empty cart, on the same language, with correctly set currency.

Can't see the reason behind this error in this particular scenario.

 

I would gladly discard whatever was in the shopping cart, before it attempts to add something new (if that is the cuase of the issue) but again, not sure what exactly causes it.

 

/Dmitrij

 
Nicolai Pedersen
Reply

Can you screencast this?

 
Dmitrij Jazel
Reply

This is what happens when you add to cart:

http://screencast.com/t/bTe8s16N9

NOTE: I am using English VPN, you can do the same if you have english proxy settings set in your browser. Just google UK proxy IP

Or use a lightweight free addon for Chrome http://hola.org/ very.

 

That is why site automatically recognizes you as user from UK (based on IP), and presets currency as GBP. That is why I highlighted it in the video.

 

And this is what happens when I am trying to empty the cart:

http://screencast.com/t/bOnHC8d1g

 
Nicolai Pedersen
Reply

So you did something custom that does magic stuff when from other countries?

 
Dmitrij Jazel
Reply

Well, I would not say so. :-)

 

All that custom stuff is just Dynamicweb API, nothing else.

We are talking about one event (page load) and a one method call (change currency), that is called when neccesery.

 

I just wrote some C# according to specifications instructed by Lars.

I can send you the implementation so you can take a look.

 
Nicolai Pedersen
Reply

No thank you. I would add a debugger to you code and step into the stack. My guess is that you change currency at the wrong spot.

 
Dmitrij Jazel
Reply

I see, well I will try keeping this thing in mind.

 

But where else you would do it. I am not involving any additional methods or APi calls. All it has is Pageload event, and currency change method, that's it!

 

In the page load event, first

1) Check IP - get the country code from it. (json call via 3rd party service)

If neccesery - reddirect to correct country.

2) Check currency

Figure out what currency this country code should have.

If currency.current is not what it is should be - change the currency.

 

That is all it does.

 

But this error did not get any more solved, and we need to get it solved.

I have 2 thoughts regarding this:

1) This website uses DKK, SEK, USD and EUR as additional currencies that are beying set in the same way, From the same site.

Default site currency is EUR, but nor DKK, nor SEK, or USD have this issue, except for GBP.

So this makes me think there might be something wrong with the way DW cart renders GBP with the settings we have.

2) Maybe with help of OnBeforeCartRender API Event (or something like that) we could manipulate some args variables, so that we could avoid this error for GBP currency, or even prevent this error message from beying fired in the first place?  

 
Dmitrij Jazel
Reply

Anyone?

Code examples, suggestions, ideas are more than welcome.

 

/Dmitrij

 
Nicolai Pedersen
Reply

Cannot give you more information... Add a debugger and a watch on the currency/order objects and see what happens...

 
Dmitrij Jazel
Reply

Yes, good luck doing that on live environment.

Even if I could manage that, I would need to know where to set breakpoints.

Anything particular I need to look at?

 

All I am trying to do is figure out can cause this error. I am pretty sure this is not ordinary .NET exception, that is something DW generates.

That is why there probably is a condition, try/catch or some other part of the code that throws this error.

 
Nicolai Pedersen
Reply

Yes, it is a Dynamicweb exception because you have a context and an order of different currencies. €100 + £100 will give this exception.

You should add the debugger in your development environment and add a watch on the currency/order objects and see what happens... Set a breakpoint where you start changing the currency and step into the process and add those wathces...

 
Dmitrij Jazel
Reply

Hi Nicolai,

Aniway I can debug Price.PriceInfo.Add() method?

I attached a process to my code, and everything seems to go fine.

But the error happens at PriceInfo.vb:line 383.

 

You must be logged in to post in the forum