Skip to content

Commit

Permalink
Multiple currencies support, endpoint for currency change
Browse files Browse the repository at this point in the history
  • Loading branch information
martinfbluesoftcz committed Apr 19, 2024
1 parent 8ba8108 commit eea7f47
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 72 deletions.
11 changes: 9 additions & 2 deletions examples/DancingGoat-K13Ecommerce/Controllers/TestController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using Kentico.Xperience.K13Ecommerce.StoreApi;
using Kentico.Xperience.K13Ecommerce.ShoppingCart;
using Kentico.Xperience.K13Ecommerce.StoreApi;

using Microsoft.AspNetCore.Mvc;

namespace DancingGoat.Controllers;
#if DEBUG
[Route("[controller]/[action]")]
public class TestController(IKenticoStoreApiClient storeApiClient) : Controller
public class TestController(IKenticoStoreApiClient storeApiClient, IShoppingService shoppingService) : Controller
{
public async Task<IActionResult> TestProducts()
{
Expand All @@ -18,5 +19,11 @@ public async Task<IActionResult> TestCart()
var cart = await storeApiClient.GetCurrentCartContentAsync();
return Ok(cart);
}

public async Task<IActionResult> TestSetCurrency(string currencyCode)
{
await shoppingService.SetCurrency(currencyCode);
return await TestCart();
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Kentico.Xperience.K13Ecommerce.ShoppingCart;

/// <summary>
/// Provides interface for integration with shopping cart K13 (communicate via store api)
/// Provides interface for integration with shopping cart on K13 (communicates via store api)
/// </summary>
public interface IShoppingService
{
Expand Down Expand Up @@ -160,4 +160,12 @@ public interface IShoppingService
/// </summary>
/// <returns></returns>
Task<ICollection<KShoppingCartItemValidationError>> ValidateShoppingCartItems();


/// <summary>
/// Set currency to cart when currency is different than previous
/// </summary>
/// <param name="currencyCode"></param>
/// <returns></returns>
Task SetCurrency(string currencyCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ public async Task<ICollection<KShoppingCartItemValidationError>> ValidateShoppin
(await ProcessAction(async () => await storeApiClient.ValidateCartItemsAsync(ShoppingCartGuid))).Value!;


public async Task SetCurrency(string currencyCode) => await ProcessAction(
async () => await storeApiClient.SetCurrencyAsync(ShoppingCartGuid, currencyCode));


protected virtual async Task<TResponse> ProcessAction<TResponse>(Func<Task<TResponse>> func,
bool cartMustBeStored = false, bool clearCaches = true)
where TResponse : IShoppingCartIdentifier
Expand Down
Loading

0 comments on commit eea7f47

Please sign in to comment.