Developer forum

Forum » Integration » Currency based on user IP

Currency based on user IP

Søren Jakobsen
Reply

Hi Community,

I'm working on a solution where we try to guess the user currency based on their IP address - for not logged in users. I'm able to set the currency and specific BC user in live-integration based on the IP and BC returns the correct price and currency. See ex. below

8/27/2021 12:49:55 PM: DebugInfo: Request GetProductsInfo sent: '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><GetEcomData ExternalUserId="1066" AccessUserCustomerNumber="1066"><tables><Products type="filter"><Product><ProductId>000-200</ProductId><ProductVariantId></ProductVariantId><ProductNumber>000-200</ProductNumber><ProductIdentifier>000-200..ENU</ProductIdentifier><CurrencyCode>EUR</CurrencyCode><Quantity>1</Quantity></Product></Products></tables></GetEcomData>'.
8/27/2021 12:49:55 PM: DebugInfo: Response GetProductsInfo received: '<?xml version="1.0" encoding="utf-8"?><tables version="1.2.0.11_NAV7.1.37563"><table tableName="EcomProducts"><item table="EcomProducts"><column columnName="ProductId"><![CDATA[000-200]]></column><column columnName="ProductVariantId"><![CDATA[]]></column><column columnName="ProductIdentifier"><![CDATA[000-200..ENU]]></column><column columnName="ProductNumber"><![CDATA[000-200]]></column><column columnName="ProductName"><![CDATA[Test af PIM - ÆNDRET]]></column><column columnName="ProductPrice"><![CDATA[1,000]]></column><column columnName="ProductStock"><![CDATA[0]]></column><column columnName="ProductCurrencyCode"><![CDATA[EUR]]></column></item></table></tables>'.

The correct price (incl .VAT) will be displayed at frontend but the currency is wrong. How and where do I change/set the currency for users not logged in?

It's a DW 9.10.13 with rapido 3.4.3

 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Soren,
you can change that by subscibing to the Dynamicweb live integration extensibility api.
The events are:
Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.ProductInfo.OnBeforeGenerateProductInfoXml
Dynamicweb.Ecommerce.DynamicwebLiveIntegration.Notifications.ProductInfo.OnAfterGenerateProductInfoXml
In the OnBeforeGenerateProductInfoXml event you need to change the current context currency:
var currentCurrency = Common.Context.Currency;
Common.Context.Currency = yourCurrency;

and then restore back it in the OnAfterGenerateProductInfoXml if needed:
Common.Context.Currency = currentCurrency

Then the ERP request will generate the request based on the currency set in the Common.Context.Currency.

BR, Dmitrij

Votes for this answer: 1
 
Søren Jakobsen
Reply

Thanks, just what I needed

 

You must be logged in to post in the forum