4

I'm using Sitecore 9.0 Update 1 and XC9 Update 1 in a project for a European customer.

We created our own environment based on the OOTB Habitat-environment. In the config-file we set EUR to be the default currency. USD was always just added as an option.

In my "Currency Configuration" I use the currency set "Default", which has "EUR" assigned as default currency.

Also all prices, that are assigned to the sellable items (wether list prices or price cards / price card snapshots), use just EUR as currency.

But when I try to add a product to the cart, that does not have a USD-price assigned, I get the following error in the commerce engine log:

ERROR CtxMsg.Error.LineIsNotPurchasable: Text=Item 'My Product' is not purchasable.

But if I add a price with currency "USD", it works fine. I assume, I'm doing something wrong, sadly I wasn't able to figure out what it is.

I use the CartServiceProvider from the Sitecore.Commerce.Connect.Core.dll and use it's AddCartLines method.

Here is a simplified version of the code:

var currency = "EUR";
var cartLine = new CommerceCartLine(catalog, product.ProductId, null, product.Quantity);
var request = new AddCartLinesRequest(cart, new[] { cartLine })
{
    CurrencyCode = currency,
    Shop = new Shop { Name = Consts.ShopName }
};

_cartServiceProvider.AddCartLines(request);

UPDATE: I also noticed, that the cart always uses the list price to calculate the totals. That's a weird, because the price is calculated correctly based on the price card snapshots, when I use the PricingServiceProvider and it's GetProductPrices method. To assign price card snapshots to sellable items, we use tags. Maybe it's a problem when the cart tries to calculate the prices based on tags?

6
+50

OOTB Sitecore Commerce 9 uses USD currency as a default currency.

If you want to use different currency you need to do:

  1. Navigate to your Home item and check Control Panel Configuration in Storefront Settings section. There Sitecore store reference to Storefront Configuration for your Sitecore Commerce site.

  2. Navigate to /sitecore/Commerce/Commerce Control Panel/Storefront Settings/Storefronts and find under this item Storefront Configuration, which you are using for your site

  3. Navigate to /sitecore/Commerce/Commerce Control Panel/Storefront Settings/Storefronts/{your_storefront_configuration}/Currency Configuration and find Currency Set. All created/predefined Currency Sets you can find under /sitecore/Commerce/Commerce Control Panel/Shared Settings/Currency Settings/Currency Sets

  4. Navigate to your currency set and select EUR currency in Currencies field and set EUR currency in Default currency field

After that you need to patch commerceEngineConfiguration and replace defaultShopCurrency to:

<defaultShopCurrency>EUR</defaultShopCurrency>

Now all you price calculations will be in EUR currency

If you are not using SXA and you implemented your custom solution:

  1. You need to have reference on home item to Storefront Configuration, which your Storefront uses (or any other place in your site structure)
  2. Implement your own CartManager and for all requests like:

    • AddCartLinesRequest

    • AddPaymentInfoRequest

    • AddPromoCodeRequest

    • AddShippingInfoRequest

    • GetCartsRequest

    • MergeCartRequest

    • RemovePaymentInfoRequest

    • RemoveShippingInfoRequest

    • RemoveCartLinesRequest

    • RemovePartiesRequest

    • RemovePromoCodeRequest

    • UpdateCartLinesRequest

    • LoadCartByNameRequest

you need to set CurrencyCode property to EUR

Like:

var cartResult =
        CartServiceProvider.AddCartLines(new AddCartLinesRequest(cart, cartLineList) {CurrencyCode = "EUR"});

Unfortunately, GetCurrencyCode by shop, doesn't work properly (decompiled code):

namespace Sitecore.Commerce.XA.Foundation.Common.Providers
{
  public class RequestCurrencyProvider : IRequestCurrencyProvider
  {
    public string GetCurrencyCode(Shop shop)
    {
      return ServiceLocator.ServiceProvider.GetService<IStorefrontContext>().CurrentStorefront.SelectedCurrency;
    }
  }
}
  • Hi @AndreiPaliakou. Thank you for this great answer. As this is the best answer I got during the 7 days, of course I awarded you the bounty. But on the other hand, it did not fix my problem. As we cannot use SXA in the beforementioned project, we do not have the Sitecore.Commerce.XA binaries. But I implemented my own IRequestCurrencyProvider. Sadly, even that did not fix my problem. – n-develop Aug 28 '18 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.