Developer forum

Forum » Integration » Attempt to aritmatic with two prices of different currency - Again

Attempt to aritmatic with two prices of different currency - Again

Kenneth Radoor
Reply

Hi.

I have a project with liveintegration til NAV. 

We are using v 1.0.0.6 of  the sample code provided by DW, and have made a few minor changes to the code to request to NAV, to get and set the right data.

The site have 2 languages and 3 currencies

I should be posible on either language to switch between the different currencies.

As long as the Cart is empty it works as expected, but when ever there is anything in the cart the application throws an exeption:

[PriceInfoCurrencyException: Attempt to aritmatic with two prices of different currency]
   Dynamicweb.Ecommerce.Prices.PriceInfo.Add(IPriceInfo info) +708
   Dynamicweb.Ecommerce.Prices.PriceInfo.Add(IPriceReferenceInfo info) +21
   Dynamicweb.Ecommerce.Orders.OrderLineCollection.get_Price() +241
   Dynamicweb.Ecommerce.Orders.Order.GetPriceBeforeFees(Boolean negativePriceControl) +41
   Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrderDetails(Template template, Order order, Boolean extendedProperties, OrderTemplateExtenderContext orderContext) +4730
   Dynamicweb.Ecommerce.Frontend.Renderer.RenderOrder(Order order, Template template, Boolean extendedProperties, Int32 stepNumber, OrderTemplateExtenderContext orderContext) +70
   Dynamicweb.Ecommerce.Frontend.Cart.CartPageTemplateExtender.ExtendTemplate(Template template) +175
   Dynamicweb.Frontend.Renderer.RenderPageTemplateExtenders(Template Template) +639
   Dynamicweb.Frontend.Renderer.RenderPage(Template template, PageViewModel pageViewModel) +2904
   Dynamicweb.Frontend.PageView.SetPageTemplateValues() +143
   Dynamicweb.Frontend.PageView.Output() +777
   Dynamicweb.Frontend.DynamicwebHttpHandler.ProcessRequest(HttpContext context) +141
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +813
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +73

The exeption is thrown somewhere after the Page.Loaded notification, as i can debug until then.

I force the exeption to happen by inserting the CurrencyCode=XXX in the querystring

If i inspect the Dynamicweb.Ecommerce.Common.Context.Currency it is set to the right Currency eg. DKK, EUR or GBP.

None of the other code in the live-integration project is no excecuted so i cant do anything, like clearing cached prices and setting the currency for the order or orderlines. 

It seems like there is something earlier in the pipeline where the cart is calculated. Is there a notification i can use to clear the calculation ?

the site is http://rocopenhagen.staging.dynamicweb-cms.com/ DW version 9.4.18.

Locally i have a DW version 9.5.6 giving the same exeption.

Any help would be much appriciated.

Thanks

//Kenneth 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Kenneth,
there were several bugs like that one and they were fixed in the recent Dynamicweb 9 versions.
Could you try to upgrade to the last Dynamicweb 9.7.* version and also download the last Live integration 1.0.0.20 and see if this issue is solved?
Sorry for the inconvenience.
Best regards, Dmitrij

 
Kenneth Radoor
Reply

Hi

Upgrading the solution to 9.7.* kind of resolved the problem, but only patially.

the "Attempt to aritmatic with two prices of different currency" exeption have gone away and thats fine.

there is still an issue with the cart being recalculated, when ever the currency is changed by the user in the frontend.

We need the cart to be updated via LiveIntegration, and it isn't becourse there is no Notification saying that the currency has changed.

That would be a nice feature to have eg. "Dynamicweb.Ecommerce.Notifications.Ecommerce.Cart.AfterCurrencyIsChanged"

I have made a hack in the "Dynamicweb.Notifications.Standard.Page.Loaded" event.

if (HttpContext.Current != null && HttpContext.Current.Session != null && HttpContext.Current.Session["Custom.Context.Currency.Code"] != null)
            {
                if (HttpContext.Current.Session["Custom.Context.Currency.Code"].ToString().ToLower() != Dynamicweb.Ecommerce.Common.Context.Currency.Code.ToLower())
                {

                    if (
                        (string.IsNullOrEmpty(Helpers.GetConfigValue(Constants.WebServiceConfiguration.Path, Constants.WebServiceConfiguration.Shop)) ||
                        Helpers.GetConfigValue(Constants.WebServiceConfiguration.Path, Constants.WebServiceConfiguration.Shop) == (String)Dynamicweb.Frontend.PageView.Current().Area.EcomShopId) &&
                        UrlHandler.Instance.IsWebServiceUrlFound()
                        )
                    {
                        if (Dynamicweb.Ecommerce.Common.Context.Cart.IsCart) { 
                            OrderHandler.UpdateOrder(Dynamicweb.Ecommerce.Common.Context.Cart);
                        }
                    }

                    HttpContext.Current.Session["Custom.Context.Currency.Code"] = Dynamicweb.Ecommerce.Common.Context.Currency.Code;
                }
            }
            else
            {
                HttpContext.Current.Session["Custom.Context.Currency.Code"] = Dynamicweb.Ecommerce.Common.Context.Currency.Code;
            }

And it seems to work even in DW version 9.5.6

The live integration code gets called and there is no exeptions

If there is a better way to do it, please let me know

//Kenneth

 

You must be logged in to post in the forum