Skip to content

Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.

Add new events for Grand.Web - ChangeCurrency/ChangeLanguage/ChangeStore/ChangeTaxType/ChangeTheme

KrzysztofPajak51a7e8c3c6a6
diff --git a/src/Web/Grand.Web/Controllers/CommonController.cs b/src/Web/Grand.Web/Controllers/CommonController.cs
index b3ec782bf..813f64cb0 100644
--- a/src/Web/Grand.Web/Controllers/CommonController.cs
+++ b/src/Web/Grand.Web/Controllers/CommonController.cs
@@ -171,6 +171,9 @@ namespace Grand.Web.Controllers
await _workContext.SetWorkingLanguage(language);
+ //notification
+ await _mediator.Publish(new ChangeLanguageEvent(_workContext.CurrentCustomer, language));
+
return Redirect(returnUrl);
}
@@ -222,8 +225,11 @@ namespace Grand.Web.Controllers
//clear gift card
await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");
+ //notification
+ await _mediator.Publish(new ChangeCurrencyEvent(_workContext.CurrentCustomer, currency));
+
//home page
- if (String.IsNullOrEmpty(returnUrl))
+ if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
//prevent open redirection attack
@@ -248,7 +254,12 @@ namespace Grand.Web.Controllers
{
var selectedstore = await storeService.GetStoreById(store);
if (selectedstore != null)
+ {
await _storeHelper.SetStoreCookie(store);
+
+ //notification
+ await _mediator.Publish(new ChangeStoreEvent(_workContext.CurrentCustomer, selectedstore));
+ }
}
}
var prevStore = await storeService.GetStoreById(currentstoreid);
@@ -263,7 +274,7 @@ namespace Grand.Web.Controllers
}
//home page
- if (String.IsNullOrEmpty(returnUrl))
+ if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
//prevent open redirection attack
@@ -280,8 +291,11 @@ namespace Grand.Web.Controllers
var taxDisplayType = (TaxDisplayType)Enum.ToObject(typeof(TaxDisplayType), customerTaxType);
await _workContext.SetTaxDisplayType(taxDisplayType);
+ //notification
+ await _mediator.Publish(new ChangeTaxTypeEvent(_workContext.CurrentCustomer, taxDisplayType));
+
//home page
- if (String.IsNullOrEmpty(returnUrl))
+ if (string.IsNullOrEmpty(returnUrl))
returnUrl = Url.RouteUrl("HomePage");
//prevent open redirection attack
@@ -291,6 +305,27 @@ namespace Grand.Web.Controllers
return Redirect(returnUrl);
}
+ public virtual async Task<IActionResult> SetStoreTheme(
+ [FromServices] IThemeContext themeContext, string themeName, string returnUrl = "")
+ {
+ await themeContext.SetWorkingTheme(themeName);
+
+ //notification
+ await _mediator.Publish(new ChangeThemeEvent(_workContext.CurrentCustomer, themeName));
+
+ //home page
+ if (string.IsNullOrEmpty(returnUrl))
+ returnUrl = Url.RouteUrl("HomePage");
+
+ //prevent open redirection attack
+ if (!Url.IsLocalUrl(returnUrl))
+ returnUrl = Url.RouteUrl("HomePage");
+
+ return Redirect(returnUrl);
+ }
+
+
+
//contact us page
//available even when a store is closed
[ClosedStore(true)]
@@ -390,23 +425,6 @@ namespace Grand.Web.Controllers
return View(model);
}
- public virtual async Task<IActionResult> SetStoreTheme(
- [FromServices] IThemeContext themeContext, string themeName, string returnUrl = "")
- {
- await themeContext.SetWorkingTheme(themeName);
-
- //home page
- if (string.IsNullOrEmpty(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
- //prevent open redirection attack
- if (!Url.IsLocalUrl(returnUrl))
- returnUrl = Url.RouteUrl("HomePage");
-
- return Redirect(returnUrl);
- }
-
-
[HttpPost]
[ClosedStore(true)]
[PublicStore(true)]
diff --git a/src/Web/Grand.Web/Events/ChangeCurrencyEvent.cs b/src/Web/Grand.Web/Events/ChangeCurrencyEvent.cs
new file mode 100644
index 000000000..0c27fd0e2
--- /dev/null
+++ b/src/Web/Grand.Web/Events/ChangeCurrencyEvent.cs
@@ -0,0 +1,18 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Directory;
+using MediatR;
+
+namespace Grand.Web.Events
+{
+ public class ChangeCurrencyEvent : INotification
+ {
+ public Customer Customer { get; private set; }
+ public Currency Currency { get; private set; }
+
+ public ChangeCurrencyEvent(Customer customer, Currency currency)
+ {
+ Customer = customer;
+ Currency = currency;
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/Events/ChangeLanguageEvent.cs b/src/Web/Grand.Web/Events/ChangeLanguageEvent.cs
new file mode 100644
index 000000000..f1004bd65
--- /dev/null
+++ b/src/Web/Grand.Web/Events/ChangeLanguageEvent.cs
@@ -0,0 +1,18 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Localization;
+using MediatR;
+
+namespace Grand.Web.Events
+{
+ public class ChangeLanguageEvent : INotification
+ {
+ public Customer Customer { get; private set; }
+ public Language Language { get; private set; }
+
+ public ChangeLanguageEvent(Customer customer, Language language)
+ {
+ Customer = customer;
+ Language = language;
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/Events/ChangeStoreEvent.cs b/src/Web/Grand.Web/Events/ChangeStoreEvent.cs
new file mode 100644
index 000000000..d3b19e904
--- /dev/null
+++ b/src/Web/Grand.Web/Events/ChangeStoreEvent.cs
@@ -0,0 +1,18 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Stores;
+using MediatR;
+
+namespace Grand.Web.Events
+{
+ public class ChangeStoreEvent : INotification
+ {
+ public Customer Customer { get; private set; }
+ public Store Store { get; private set; }
+
+ public ChangeStoreEvent(Customer customer, Store store)
+ {
+ Customer = customer;
+ Store = store;
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/Events/ChangeTaxTypeEvent.cs b/src/Web/Grand.Web/Events/ChangeTaxTypeEvent.cs
new file mode 100644
index 000000000..854a194fa
--- /dev/null
+++ b/src/Web/Grand.Web/Events/ChangeTaxTypeEvent.cs
@@ -0,0 +1,18 @@
+using Grand.Domain.Customers;
+using Grand.Domain.Tax;
+using MediatR;
+
+namespace Grand.Web.Events
+{
+ public class ChangeTaxTypeEvent : INotification
+ {
+ public Customer Customer { get; private set; }
+ public TaxDisplayType TaxDisplayType { get; private set; }
+
+ public ChangeTaxTypeEvent(Customer customer, TaxDisplayType taxDisplayType)
+ {
+ Customer = customer;
+ TaxDisplayType = taxDisplayType;
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/Events/ChangeThemeEvent.cs b/src/Web/Grand.Web/Events/ChangeThemeEvent.cs
new file mode 100644
index 000000000..6b872d344
--- /dev/null
+++ b/src/Web/Grand.Web/Events/ChangeThemeEvent.cs
@@ -0,0 +1,17 @@
+using Grand.Domain.Customers;
+using MediatR;
+
+namespace Grand.Web.Events
+{
+ public class ChangeThemeEvent : INotification
+ {
+ public Customer Customer { get; private set; }
+ public string ThemeName { get; private set; }
+
+ public ChangeThemeEvent(Customer customer, string themeName)
+ {
+ Customer = customer;
+ ThemeName = themeName;
+ }
+ }
+}