Skip to content

Umbraco Commerce store setup docs #6848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 51 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
486aad5
Revert "Updated release notes for Umbraco UIBuilder versions 14.0.3 a…
acoumb Feb 5, 2025
f9ac4f2
Merge branch 'main' into main
acoumb Mar 10, 2025
5b7f022
Update summary
acoumb Mar 10, 2025
efb992d
Merge branch 'main' of https://github.com/acoumb/UmbracoDocs
adi-cojocariu7 Mar 10, 2025
771484a
Merge branch 'umbraco:main' into main
acoumb Mar 11, 2025
55c2988
Restore Umbraco Commerce setup store resources
acoumb Mar 11, 2025
1deb230
Updated summary
acoumb Mar 11, 2025
a1bda45
Update summary with Build a shopping cart tree
acoumb Mar 12, 2025
a403f72
Re structuring tutorials
mattbrailsford Mar 17, 2025
ea4ea14
Move specific tutorials to how to guides
mattbrailsford Mar 17, 2025
dfef280
Rename guide
mattbrailsford Mar 17, 2025
8df4d5f
Fix links
mattbrailsford Mar 17, 2025
972f397
Change header
mattbrailsford Mar 17, 2025
4a5e7e7
Update links
mattbrailsford Mar 17, 2025
381e59e
Wrong link
mattbrailsford Mar 17, 2025
d98d6c2
Update heading
mattbrailsford Mar 17, 2025
cf9e68d
Added descriptions
mattbrailsford Mar 17, 2025
15525a5
Updated description
mattbrailsford Mar 17, 2025
3dc5274
Move the built in property editor docs from the old "Getting started …
mattbrailsford Mar 18, 2025
0aef1fe
Updated the product bundles how too guide
mattbrailsford Mar 18, 2025
a55bb68
Updated member pricing how to guide
mattbrailsford Mar 18, 2025
f540a10
Updated implementing dynamic pricing
mattbrailsford Mar 18, 2025
33aea39
Updated the personalized products how to guide
mattbrailsford Mar 18, 2025
d1d9409
Currency switcher how to guide
mattbrailsford Mar 18, 2025
294d5f6
Added info box
mattbrailsford Mar 18, 2025
a880c8d
Use the same style across all headings
mattbrailsford Mar 18, 2025
fb29aa8
Implemented guide for creating a member portal
mattbrailsford Mar 18, 2025
b8c4a86
Fixed broken summary link
mattbrailsford Mar 18, 2025
53f6128
Force line break between images
mattbrailsford Mar 18, 2025
4a94ec6
Added messages
mattbrailsford Mar 18, 2025
e7db213
Changed to use "you" instead of "we"
sofietoft Mar 19, 2025
92907dd
Change from "we" to you"
sofietoft Mar 19, 2025
4b48c6f
Change from "we" to you"
sofietoft Mar 19, 2025
444d6f2
Update member-portal.md
sofietoft Mar 19, 2025
0d65513
Update personalized-products.md
sofietoft Mar 19, 2025
2070cda
Update product-bundles.md
sofietoft Mar 19, 2025
2afc681
Update cart.md
sofietoft Mar 19, 2025
c994be4
Update checkout.md
sofietoft Mar 19, 2025
143f60d
Update configure-store.md
sofietoft Mar 19, 2025
77dfb03
Update create-product.md
sofietoft Mar 19, 2025
4eb8def
Update create-store.md
sofietoft Mar 19, 2025
9ea568a
Update custom-cart.md
sofietoft Mar 19, 2025
21c1b97
Update custom-checkout.md
sofietoft Mar 19, 2025
0fbf8fe
Update installation.md
sofietoft Mar 19, 2025
27ebc19
Update overview.md
sofietoft Mar 19, 2025
749c228
Update permissions.md
sofietoft Mar 19, 2025
843ea88
Update dynamically-priced-products.md
sofietoft Mar 19, 2025
2b76b22
Update 15/umbraco-commerce/how-to-guides/member-portal.md
mattbrailsford Mar 19, 2025
d1150df
Add code file tags
mattbrailsford Mar 19, 2025
8afc47c
Remove any styles from code samples
mattbrailsford Mar 19, 2025
1a36973
Remove any styles from code samples
mattbrailsford Mar 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ indent_size = 4

# Trim trailing whitespace, limited support.
# https://github.com/editorconfig/editorconfig/wiki/Property-research:-Trim-trailing-spaces
trim_trailing_whitespace = true
trim_trailing_whitespace = false

[*.{cs,vb}]
dotnet_style_predefined_type_for_locals_parameters_members = true:error
Expand Down
34 changes: 24 additions & 10 deletions 15/umbraco-commerce/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,36 @@
* [Migrate Umbraco Commerce Checkout](upgrading/migrate-from-vendr-to-umbraco-commerce/migrate-umbraco-commerce-checkout.md)
* [Migrate custom Payment Providers](upgrading/migrate-from-vendr-to-umbraco-commerce/migrate-custom-payment-providers.md)

## Tutorials

* [Overview](tutorials/overview.md)
* [Build a Store in Umbraco using Umbraco Commerce](tutorials/build-a-store/overview.md)
* [Installation](tutorials/build-a-store/installation.md)
* [Creating a Store](tutorials/build-a-store/create-store.md)
* [Configuring your Store](tutorials/build-a-store/configure-store.md)
* [Creating your first Product](tutorials/build-a-store/create-product.md)
* [Implementing a Shopping Cart](tutorials/build-a-store/cart.md)
* [Using the Umbraco.Commerce.Cart Drop-in Shopping Cart](https://docs.umbraco.com/umbraco-commerce-packages/cart/cart)
* [Creating a Custom Shopping Cart](tutorials/build-a-store/custom-cart.md)
* [Implementing a Checkout Flow](tutorials/build-a-store/checkout.md)
* [Using the Umbraco.Commerce.Checkout Drop-in Checkout Flow](https://docs.umbraco.com/umbraco-commerce-packages/checkout/checkout)
* [Creating a Custom Checkout Flow](tutorials/build-a-store/custom-checkout.md)
* [Configuring Store Access Permissions](tutorials/build-a-store/permissions.md)

## How-To Guides

* [Overview](how-to-guides/overview.md)
* [Configure SQLite support](how-to-guides/configure-sqlite-support.md)
* [Limit Order Line Quantity](how-to-guides/limit-orderline-quantity.md)
* [Use an Alternative Database for Umbraco Commerce Tables](how-to-guides/use-an-alternative-database-for-umbraco-commerce-tables.md)
* [Add item to Cart](how-to-guides/add-item.md)
* [Update Cart](how-to-guides/update-cart.md)
* [Delete item from Cart](how-to-guides/delete-item.md)
* [Customizing Templates](how-to-guides/customizing-templates.md)
* [Configuring Store Cleanup](how-to-guides/configuring-cart-cleanup.md)
* [Configuring Cart Cleanup](how-to-guides/configuring-cart-cleanup.md)
* [Limit Order Line Quantity](how-to-guides/limit-orderline-quantity.md)
* [Implementing Product Bundles](how-to-guides/product-bundles.md)
* [Implementing Member Based Pricing](how-to-guides/member-based-pricing.md)
* [Implementing Dynamically Priced Products](how-to-guides/dynamically-priced-products.md)
* [Implementing Personalized Products](how-to-guides/personalized-products.md)
* [Implementing a Currency Switcher](how-to-guides/currency-switching.md)
* [Building a Members Portal](how-to-guides/member-portal.md)

## Key Concepts

Expand Down Expand Up @@ -108,8 +127,3 @@
* [Management API](reference/management-api/README.md)
* [Go behind the scenes](reference/go-behind-the-scenes.md)
* [Telemetry](reference/telemetry.md)

## Tutorials

* [Overview](tutorials/overview.md)
* [Getting started with Umbraco Commerce: The Backoffice](tutorials/getting-started-with-commerce.md)
199 changes: 0 additions & 199 deletions 15/umbraco-commerce/how-to-guides/add-item.md

This file was deleted.

137 changes: 137 additions & 0 deletions 15/umbraco-commerce/how-to-guides/currency-switching.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
description: Learn how to implement a currency switcher in Umbraco Commerce.
---

# Implementing a Currency Switcher

In a globalized world, it is essential to provide users with the ability to switch between different currencies. This feature is especially important for e-commerce websites that cater to customers from different countries.

In this guide, you can learn how to implement a currency switcher in Umbraco Commerce.

{% hint style="info" %}
In this guide, it is assumed that each country has a single currency. If your store supports multiple currencies per country, you must adjust the implementation accordingly.
{% endhint %}

## Configure Countries and Currencies

1. Define the countries and currencies you want to support, in the Umbraco backoffice.

![Countries](images/localization/store-countries.png)

![Currencies](images/localization/store-currencies.png)

2. Navigate to the Content section.
3. Populate the product prices for each currency.

![Product Prices](images/localization/product-prices.png)

## Create a Currency Switcher Component

A partial view is used on the frontend to allow users to toggle between existing currencies.

![Currency Switcher](images/localization/country-switch.png)

This is done by using the following implementation:

````csharp
@using Umbraco.Commerce.Core.Api;
@using Umbraco.Commerce.SwiftShop.Extensions;
@inject IUmbracoCommerceApi UmbracoCommerceApi
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage

@{
var store = Model.GetStore();
var countries = await UmbracoCommerceApi.GetCountriesAsync(store.Id);
var currencies = await UmbracoCommerceApi.GetCurrenciesAsync(store.Id);
var currentCountry = await UmbracoCommerceApi.GetDefaultShippingCountryAsync(store.Id);
}

@if (countries.Count() > 1)
{
@using (Html.BeginUmbracoForm("ChangeCountry", "Culture", FormMethod.Post, new { @name = "changeCountryForm" }))
{
@Html.DropDownList("countryIsoCode", countries.Select(x
=> new SelectListItem(currencies.First(y => y.Id == x.DefaultCurrencyId!.Value).Code, x.Code, x.Code == currentCountry.Code)),
new
{
@class = "form-select form-select-sm",
@onchange = "document.forms['changeCountryForm'].submit()"
})
}
}
````

## Handle Switching Currencies

Switching the culture is handled by a Surface controller.

Create a new Surface controller called `CultureSurfaceController` and add the following code:

````csharp
public class CultureSurfaceController : SurfaceController
{
private readonly IUmbracoCommerceApi _commerceApi;

public CultureSurfaceController(
IUmbracoContextAccessor umbracoContextAccessor,
IUmbracoDatabaseFactory databaseFactory,
ServiceContext services,
AppCaches appCaches,
IProfilingLogger profilingLogger,
IPublishedUrlProvider publishedUrlProvider,
IUmbracoCommerceApi commerceApi)
: base(umbracoContextAccessor, databaseFactory, services, appCaches, profilingLogger, publishedUrlProvider)
{
_commerceApi = commerceApi;
}

[HttpPost]
public async Task<IActionResult> ChangeCountry(ChangeCountryDto changeCountryDto)
{
var store = CurrentPage.GetStore();
var country = await _commerceApi.GetCountryAsync(store.Id, changeCountryDto.CountryIsoCode);
var currency = await _commerceApi.GetCurrencyAsync(country.DefaultCurrencyId.Value);

await _commerceApi.SetDefaultPaymentCountryAsync(store.Id, country);
await _commerceApi.SetDefaultShippingCountryAsync(store.Id, country);
await _commerceApi.SetDefaultCurrencyAsync(store.Id, currency);

var currentOrder = await _commerceApi.GetCurrentOrderAsync(store.Id);
if (currentOrder != null)
{
await _commerceApi.Uow.ExecuteAsync(async uow =>
{
var writableOrder = await currentOrder.AsWritableAsync(uow)
.ClearPaymentCountryRegionAsync()
.ClearShippingCountryRegionAsync()
.SetCurrencyAsync(currency.Id);

await _commerceApi.SaveOrderAsync(writableOrder);

uow.Complete();
});
}

return RedirectToCurrentUmbracoPage();
}
}
````

The `ChangeCountryDto` class binds the country ISO code from the form.

````csharp
public class ChangeCountryDto
{
public string CountryIsoCode { get; set; }
}
````

## Result

With the currency switcher implemented, users can switch between countries/currencies on your website.

The changes are reflected on the product details pages.

![product-gb](images/localization/product-gb.png)

![product-dk](images/localization/product-dk.png)
Loading
Loading