Example #1
0
        public void HandleEvent(ValidatingCartEvent message)
        {
            // Default Order Totals restriction
            var roleIds = _workContext.OriginalCustomerIfImpersonated?.GetRoleIds() ?? message.Customer.GetRoleIds();

            // Minimum order totals validation
            var(isAboveMin, min) = _orderProcessingService.IsAboveOrderTotalMinimum(message.Cart, roleIds);
            if (!isAboveMin)
            {
                min = _currencyService.ConvertFromPrimaryStoreCurrency(min, _workContext.WorkingCurrency);
                message.Warnings.Add(string.Format(
                                         _localizationService.GetResource("Checkout.MinOrderSubtotalAmount"),
                                         _priceFormatter.FormatPrice(min, true, false))
                                     );

                return;
            }

            // Maximum order totals validation
            var(isBelowMax, max) = _orderProcessingService.IsBelowOrderTotalMaximum(message.Cart, roleIds);
            if (!isBelowMax)
            {
                max = _currencyService.ConvertFromPrimaryStoreCurrency(max, _workContext.WorkingCurrency);
                message.Warnings.Add(string.Format(
                                         _localizationService.GetResource("Checkout.MaxOrderSubtotalAmount"),
                                         _priceFormatter.FormatPrice(max, true, false))
                                     );
            }
        }
Example #2
0
        protected CheckoutConfirmModel PrepareConfirmOrderModel(IList <OrganizedShoppingCartItem> cart)
        {
            var model = new CheckoutConfirmModel();

            // Minimum order totals validation
            var customerRoleIds = _workContext.CurrentCustomer.GetRoleIds();

            var(isAboveMinimumOrderTotal, orderTotalMinimum) = _orderProcessingService.IsAboveOrderTotalMinimum(cart, customerRoleIds);
            if (!isAboveMinimumOrderTotal)
            {
                orderTotalMinimum = _currencyService.ConvertFromPrimaryStoreCurrency(
                    orderTotalMinimum,
                    _workContext.WorkingCurrency);

                var resource = _orderSettings.ApplyToSubtotal ? "Checkout.MinOrderSubtotalAmount" : "Checkout.MinOrderTotalAmount";
                model.OrderAmountWarning = string.Format(
                    _localizationService.GetResource(resource),
                    _priceFormatter.FormatPrice(orderTotalMinimum, true, false));
            }

            // Maximum order totals validation
            var(isBelowOrderTotalMaximum, orderTotalMaximum) = _orderProcessingService.IsBelowOrderTotalMaximum(cart, customerRoleIds);
            if (isAboveMinimumOrderTotal && !isBelowOrderTotalMaximum)
            {
                orderTotalMaximum = _currencyService.ConvertFromPrimaryStoreCurrency(
                    orderTotalMaximum,
                    _workContext.WorkingCurrency);

                var resource = _orderSettings.ApplyToSubtotal ? "Checkout.MaxOrderSubtotalAmount" : "Checkout.MaxOrderTotalAmount";
                model.OrderAmountWarning = string.Format(
                    _localizationService.GetResource(resource),
                    _priceFormatter.FormatPrice(orderTotalMaximum, true, false));
            }

            model.TermsOfServiceEnabled      = _orderSettings.TermsOfServiceEnabled;
            model.ShowEsdRevocationWaiverBox = _shoppingCartSettings.ShowEsdRevocationWaiverBox;
            model.BypassPaymentMethodInfo    = _paymentSettings.BypassPaymentMethodInfo;
            model.NewsLetterSubscription     = _shoppingCartSettings.NewsLetterSubscription;
            model.ThirdPartyEmailHandOver    = _shoppingCartSettings.ThirdPartyEmailHandOver;

            if (_shoppingCartSettings.ThirdPartyEmailHandOver != CheckoutThirdPartyEmailHandOver.None)
            {
                model.ThirdPartyEmailHandOverLabel = _shoppingCartSettings.GetLocalizedSetting(x => x.ThirdPartyEmailHandOverLabel, _workContext.WorkingLanguage, _storeContext.CurrentStore.Id, true, false);

                if (model.ThirdPartyEmailHandOverLabel.IsEmpty())
                {
                    model.ThirdPartyEmailHandOverLabel = T("Admin.Configuration.Settings.ShoppingCart.ThirdPartyEmailHandOverLabel.Default");
                }
            }

            return(model);
        }