Example #1
0
        public virtual async Task <IActionResult> SetCurrency(
            [FromServices] ICurrencyService currencyService,
            string customerCurrency, string returnUrl = "")
        {
            var currency = await currencyService.GetCurrencyById(customerCurrency);

            if (currency != null)
            {
                await _workContext.SetWorkingCurrency(currency);
            }

            //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));
        }
Example #2
0
        /// <summary>
        /// Invoke middleware actions
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns>Task</returns>
        public async Task InvokeAsync(HttpContext context, IWorkContext workContext)
        {
            //set current customer
            var customer = await workContext.SetCurrentCustomer();

            var vendor = await workContext.SetCurrentVendor(customer);

            var language = await workContext.SetWorkingLanguage(customer);

            var currency = await workContext.SetWorkingCurrency(customer);

            var taxtype = await workContext.SetTaxDisplayType(customer);

            //set culture in admin area
            if (context.Request.Path.Value.StartsWith("/admin", StringComparison.InvariantCultureIgnoreCase))
            {
                var culture = new CultureInfo("en-US");
                CultureInfo.CurrentCulture   = culture;
                CultureInfo.CurrentUICulture = culture;
            }
            else
            {
                //set culture for customer
                if (!string.IsNullOrEmpty(language?.LanguageCulture))
                {
                    var culture = new CultureInfo(language.LanguageCulture);
                    CultureInfo.CurrentCulture   = culture;
                    CultureInfo.CurrentUICulture = culture;
                }
            }

            //call the next middleware in the request pipeline
            await _next(context);
        }
Example #3
0
        public virtual async Task <IActionResult> SetCurrency(
            [FromServices] ICurrencyService currencyService,
            [FromServices] IUserFieldService userFieldService,
            string customerCurrency, string returnUrl = "")
        {
            var currency = await currencyService.GetCurrencyById(customerCurrency);

            if (currency != null)
            {
                await _workContext.SetWorkingCurrency(currency);
            }

            //clear coupon code
            await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.DiscountCoupons, "");

            //clear gift card
            await userFieldService.SaveField(_workContext.CurrentCustomer, SystemCustomerFieldNames.GiftVoucherCoupons, "");

            //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));
        }
        /// <summary>
        /// Invoke middleware actions
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <returns>Task</returns>
        public async Task InvokeAsync(HttpContext context, IWorkContext workContext)
        {
            //set current customer
            var customer = await workContext.SetCurrentCustomer();

            var vendor = await workContext.SetCurrentVendor(customer);

            var language = await workContext.SetWorkingLanguage(customer);

            var currency = await workContext.SetWorkingCurrency(customer);

            var taxtype = await workContext.SetTaxDisplayType(customer);

            //call the next middleware in the request pipeline
            await _next(context);
        }