I am building a solution where the user must have the ability to change the language and currency to the preferred country. I have created the price groups and language layers in ucommerce and typed the differenct prices on the products.
Before i go any futher I have some questions to be sure that I don't break anything in the marketing foundation, because we are going to make som campaignes later with voucher and so on.
1. What is best practice to change currency? Can I change the overall culture/currency for det solution or do I have to play around with different price groups depending af which currency choise the user have made etc..
2. A campaign has a relation to a Catalog, but in my case I have a catalog with multiple currencies so how do uCommerce handle if I have a currency specific campaign "Free shipping for orders over 400€" but the user have selected a different currency, lets say DKK?
I wonder, is the best solution in my case to have a new catalog for each currency? Then i can set the default pricegroup and I can run campaigns..
I use to make a multi catalog setup - to allow for differences in the product sortiment in the different "region" or countries (a request that is very hard to fulfil otherwise).
In that case it really easy to change the country with URls og a umbraco node for each site.
But if for some reason you need to enable multi currencies for the same country, im not really sure what the optimal approach would be.
If you want the same catalog structure across all currencies you can override the IPricingService in which you have an opportunity to return a different currency than the one requested.
public class MyPricingService : IPricingService { public Money GetProductPrice(Product product, PriceGroup priceGroup) { string customerCurrencySelection = "EUR"; // Get this from a cookie or somewhere else var price = product.PriceGroupPrices.Single(x => x.PriceGroup.Name == customerCurrencySelection); return new Money(price.Price.GetValueOrDefault(), price.PriceGroup.Currency); } }
When you're done with the implementation remember to register it in Custom.config.
I get an exception "Cannot add two instances with different currencies." when I try the code. I test it on the standard razor demo store see the image for details
You need to override ITaxService as well. uCommerce is trying to add the results from price and tax service and one is saying one currency and the other a second. Their rules need to match to make it work properly.
I will dig into the scenario and see if we can make it simpler going forward.
Now I have made an ITaxService override but I get different exception: the exception occurs when calling CatalogLibrary.CalculatePrice(p); EUR is set on the uCommerce catalog an I override it with DKK in IPricingService and in ITaxService
{System.InvalidOperationException: Items cannot be added with different currency DKK from billing currency EUR of order.
Could the problem be that CalculatePrice calls PriceCalculation that takes the PriceGroup from the catalog? In that way my override has no influence on that part of the system
@Kim: Did you manage to solve this? I've been through the same steps as you, and - not surprisingly - I'm now getting the same error: "Items cannot be added with different currency...".
Thanks for your swift reply - although I was really hoping for a workaround for the single catalog approach :/
Having to maintain separate catalogs for the sole purpose of displaying different currencies for otherwise identical products just seems like a huge overhead. Is this really the "official" stance?
Also, it confuses me that all the Price Groups you create seem to show up on all products - what might be the point of this if a catalog can only handle a single price group? Am I totally misunderstanding something?
If you dont what to write a lot of code and components to override the "standard" ucommerce, I think its the best/quickest solution. Your right it don't make a lot of sense, but I think the version 4 will handle it better as I heard.
To be sure I whould advice you to ask someone from uCommerce.
When you change currency make sure to also do it on the order itself by overriding the BillingCurrency property. This will fix the issue. Also keep in mind that if you have items in your cart when switching currency you'll have to handle the scenario.
I have also ran into some troubles when using different currencies/price groups. My project has 6 different price groups across three currencies.
I can switch between price groups in the same currencies using some code I pulled from a number of posts like this one to make up my own personal IPriceService.
However I am now having the cross currency issues, when I switch currencies, it gives me the error:
Exception: System.InvalidOperationException: Cannot add two instances with different currencies.
at UCommerce.Money.op_Addition(Money first, Money second).
Am I correct in assuming that I would be duplicating the same code structure I used for my IPricingService override to override the ITaxService?
Further to that, is there any other services I will need to override to switch between currencies after the Tax one?
I have pasted my code for my current IPricingService for you to confirm whether or not the this is the same setup I would need for my ITaxService. It can also help anyone who is struggling with changing currencies as I have found very little in the way of full examples out there.
My PriceGroups are made up of "GBP - CUSTOMER", "GBP - TRADER", "EUR - CUSTOMER", "EUR - TRADER", "USD - CUSTOMER" and "USD - TRADER". Trader and Customer are MemberGroups in my admin.
public class CustomPricingService : IPricingService
{
private readonly IPricingService _base;
public CustomPricingService()
{
_base = new PricingService();
}
public Money GetProductPrice(UCommerce.EntitiesV2.Product product, UCommerce.EntitiesV2.PriceGroup group)
{
try
{
// The price group name I want to get from the cookie/member type
string priceGroupName = "GBP - CUSTOMER";
// Get the currency from the CurrentCurrency cookie
string currentCurrency = Utilities.GetCookie("CurrentCurrency", "GBP");
// Get the default member group name
string memberGroupName = "CUSTOMER";
// Check to see if the member is logged in and override the memberGroupName if they are a trader type member
if (Member.IsLoggedOn())
{
// Find out what member type we have
Member currentMember = Member.GetCurrentMember();
// Get the Trader Role
MemberGroup traderRole = MemberGroup.GetByName("Trader");
// Determine if we use the trader role otherwise the default is used
if (traderRole.HasMember(currentMember.Id))
{
memberGroupName = "TRADER";
}
}
// Create the new price group name based on the member group and the currency
if (!string.IsNullOrWhiteSpace(memberGroupName) && !string.IsNullOrWhiteSpace(currentCurrency))
{
priceGroupName = string.Format("{0} - {1}", currentCurrency.ToUpper(), memberGroupName.ToUpper());
}
// Get the parent product, not the variants
var parentProduct = UCommerce.EntitiesV2.Product.All().Where(x => x.Sku == product.Sku && x.ParentProduct == null).FirstOrDefault();
// Get the price group if we have one
if (parentProduct.PriceGroupPrices.Count > 0)
{
// Only where the price group name matches
var pg = parentProduct.PriceGroupPrices.Where(x => x.PriceGroup.Name.Equals(priceGroupName)).FirstOrDefault();
if (pg != null)
{
return _base.GetProductPrice(parentProduct, pg.PriceGroup);
}
}
// If we reached here then something went wrong so just pass back the default price
return _base.GetProductPrice(product, group);
}
catch
{
// All else fails just pass back the default price
return _base.GetProductPrice(product, group);
}
}
}
I have managed to now get the store to change the PriceGroup using the ChangePriceGroup() function. However I would point out, the cart macroscript on the Demo Store from uCommerce uses the code
var currency = SiteContext.Current.CatalogContext.CurrentCatalog.PriceGroup.Currency;
Which returns the default price group instead of the changed one. The prices in the checkout page are correct but it was loading the incorrect currency symbol. The code I used to get the updated PriceGroup was
var currency = SiteContext.Current.CatalogContext.CurrentPriceGroup.Currency;
This seemed to be the correct PriceGroup. I couldn't find the code you mentioned above to get the PriceGroup, I am assuming that has changed since the last update to the one I am using now.
In any case I now have the currency change working well. Thanks for the help.
uCommerce - Change currency
I am building a solution where the user must have the ability to change the language and currency to the preferred country. I have created the price groups and language layers in ucommerce and typed the differenct prices on the products.
Before i go any futher I have some questions to be sure that I don't break anything in the marketing foundation, because we are going to make som campaignes later with voucher and so on.
1. What is best practice to change currency? Can I change the overall culture/currency for det solution or do I have to play around with different price groups depending af which currency choise the user have made etc..
2. A campaign has a relation to a Catalog, but in my case I have a catalog with multiple currencies so how do uCommerce handle if I have a currency specific campaign "Free shipping for orders over 400€" but the user have selected a different currency, lets say DKK?
I wonder, is the best solution in my case to have a new catalog for each currency? Then i can set the default pricegroup and I can run campaigns..
I use to make a multi catalog setup - to allow for differences in the product sortiment in the different "region" or countries (a request that is very hard to fulfil otherwise).
In that case it really easy to change the country with URls og a umbraco node for each site.
But if for some reason you need to enable multi currencies for the same country, im not really sure what the optimal approach would be.
Hi Nicolaj, the multi catalog solution could maybe be the right solution, but I think I will give it at wait and have some more suggestions..
If you want the same catalog structure across all currencies you can override the IPricingService in which you have an opportunity to return a different currency than the one requested.
When you're done with the implementation remember to register it in Custom.config.
Is it really that simple, thanks I give it a try
I get an exception "Cannot add two instances with different currencies." when I try the code. I test it on the standard razor demo store see the image for details
Hi Kim,
You need to override ITaxService as well. uCommerce is trying to add the results from price and tax service and one is saying one currency and the other a second. Their rules need to match to make it work properly.
I will dig into the scenario and see if we can make it simpler going forward.
Sorry about the inconvenience.
HI Søren,
Now I have made an ITaxService override but I get different exception: the exception occurs when calling CatalogLibrary.CalculatePrice(p); EUR is set on the uCommerce catalog an I override it with DKK in IPricingService and in ITaxService
{System.InvalidOperationException: Items cannot be added with different currency DKK from billing currency EUR of order.
at UCommerce.EntitiesV2.PurchaseOrder.CreateOrderLine(PriceGroup priceGroup, Product product, Int32 quantity, Decimal unitPrice, Decimal unitTax)
at UCommerce.EntitiesV2.PurchaseOrder.AddProduct(PriceGroup priceGroup, Product product, Int32 quantity, Decimal unitPrice, Decimal unitTax, Boolean addToExistingLine)
at UCommerce.EntitiesV2.PurchaseOrder.AddProduct(PriceGroup priceGroup, Product product, Int32 quantity, Boolean addToExistingLine)
at UCommerce.EntitiesV2.PurchaseOrder.AddProduct(PriceGroup priceGroup, Product product, Int32 quantity)
at UCommerce.Api.PriceCalculation.GetDiscount(IDiscountService discountService, ProductCatalog catalog, Product product)
at UCommerce.Api.PriceCalculation..ctor(IDiscountService discountService, IPricingService pricingService, ITaxService taxService, Product product, ProductCatalog catalog)
at UCommerce.Api.PriceCalculation..ctor(Product product, ProductCatalog catalog)
at UCommerce.Api.CatalogLibrary.CalculatePrice(Product product, ProductCatalog catalog)
at ASP._Page_macroScripts_uCommerce_HomepageCatalog_cshtml.Execute() in d:\umbraco\xxxxxx\build\macroScripts\uCommerce\HomepageCatalog.cshtml:line 26}
Could the problem be that CalculatePrice calls PriceCalculation that takes the PriceGroup from the catalog? In that way my override has no influence on that part of the system
@Kim: Did you manage to solve this? I've been through the same steps as you, and - not surprisingly - I'm now getting the same error: "Items cannot be added with different currency...".
I have no idea where to go from here. Any ideas?
Yes we found a solution, if you have an multi currency solution you need to have a catalog for each currency.
Thanks for your swift reply - although I was really hoping for a workaround for the single catalog approach :/
Having to maintain separate catalogs for the sole purpose of displaying different currencies for otherwise identical products just seems like a huge overhead. Is this really the "official" stance?
Also, it confuses me that all the Price Groups you create seem to show up on all products - what might be the point of this if a catalog can only handle a single price group? Am I totally misunderstanding something?
If you dont what to write a lot of code and components to override the "standard" ucommerce, I think its the best/quickest solution. Your right it don't make a lot of sense, but I think the version 4 will handle it better as I heard.
To be sure I whould advice you to ask someone from uCommerce.
Hi Medjeti,
When you change currency make sure to also do it on the order itself by overriding the BillingCurrency property. This will fix the issue. Also keep in mind that if you have items in your cart when switching currency you'll have to handle the scenario.
Hi Soren
I have also ran into some troubles when using different currencies/price groups. My project has 6 different price groups across three currencies.
I can switch between price groups in the same currencies using some code I pulled from a number of posts like this one to make up my own personal IPriceService.
However I am now having the cross currency issues, when I switch currencies, it gives me the error:
Exception: System.InvalidOperationException: Cannot add two instances with different currencies. at UCommerce.Money.op_Addition(Money first, Money second).
Am I correct in assuming that I would be duplicating the same code structure I used for my IPricingService override to override the ITaxService?
Further to that, is there any other services I will need to override to switch between currencies after the Tax one?
I have pasted my code for my current IPricingService for you to confirm whether or not the this is the same setup I would need for my ITaxService. It can also help anyone who is struggling with changing currencies as I have found very little in the way of full examples out there.
My PriceGroups are made up of "GBP - CUSTOMER", "GBP - TRADER", "EUR - CUSTOMER", "EUR - TRADER", "USD - CUSTOMER" and "USD - TRADER". Trader and Customer are MemberGroups in my admin.
Hi Jamie,
Which version of uCommerce are you on?
uCommerce 4 introduces the ability to attach multiple price groups to a single catalog and an API to easily switch out price groups:
uCommerce persists the selection for individual customers across requests automatically.
It's using price context on catalog to do it:
Which is where you want to override in 4 and above.
Hope this helps.
Hi Soren
I have just noticed this on the documentation when searching for price group help, I am now changing my code to test this as we speak.
Thanks
Jamie
Hi Soren
I have managed to now get the store to change the PriceGroup using the ChangePriceGroup() function. However I would point out, the cart macroscript on the Demo Store from uCommerce uses the code
Which returns the default price group instead of the changed one. The prices in the checkout page are correct but it was loading the incorrect currency symbol. The code I used to get the updated PriceGroup was
This seemed to be the correct PriceGroup. I couldn't find the code you mentioned above to get the PriceGroup, I am assuming that has changed since the last update to the one I am using now.
In any case I now have the currency change working well. Thanks for the help.
Jamie
is working on a reply...