示例#1
0
        /// <summary>
        /// Prepare billing address model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <param name="selectedCountryId">Selected country identifier</param>
        /// <param name="prePopulateNewAddressWithCustomerFields">Pre populate new address with customer fields</param>
        /// <param name="overrideAttributesXml">Override attributes xml</param>
        /// <returns>Billing address model</returns>
        public virtual CheckoutBillingAddressModel PrepareBillingAddressModel(IList <ShoppingCartItem> cart,
                                                                              int?selectedCountryId = null,
                                                                              bool prePopulateNewAddressWithCustomerFields = false,
                                                                              string overrideAttributesXml = "")
        {
            var model = new CheckoutBillingAddressModel
            {
                ShipToSameAddressAllowed = _shippingSettings.ShipToSameAddress && _shoppingCartService.ShoppingCartRequiresShipping(cart),
                //allow customers to enter (choose) a shipping address if "Disable Billing address step" setting is enabled
                ShipToSameAddress = !_orderSettings.DisableBillingAddressCheckoutStep
            };

            //existing addresses
            var addresses = _workContext.CurrentCustomer.Addresses
                            .Where(a => a.Country == null ||
                                   (//published
                                       a.Country.Published &&
                                       //allow billing
                                       a.Country.AllowsBilling &&
                                       //enabled for the current store
                                       _storeMappingService.Authorize(a.Country)))
                            .ToList();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings);

                if (_addressService.IsAddressValid(address))
                {
                    model.ExistingAddresses.Add(addressModel);
                }
                else
                {
                    model.InvalidExistingAddresses.Add(addressModel);
                }
            }

            //new address
            model.BillingNewAddress.CountryId = selectedCountryId;
            _addressModelFactory.PrepareAddressModel(model.BillingNewAddress,
                                                     address: null,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings,
                                                     loadCountries: () => _countryService.GetAllCountriesForBilling(_workContext.WorkingLanguage.Id),
                                                     prePopulateWithCustomerFields: prePopulateNewAddressWithCustomerFields,
                                                     customer: _workContext.CurrentCustomer,
                                                     overrideAttributesXml: overrideAttributesXml);

            model.BillingNewAddress.IsGuest = _workContext.CurrentCustomer.IsGuest();

            return(model);
        }
        public virtual IActionResult AddressAdd()
        {
            if (!_workContext.CurrentUser.IsRegistered())
            {
                return(Challenge());
            }

            var model = new UserAddressEditModel();

            _addressModelFactory.PrepareAddressModel(model.Address,
                                                     address: null,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings,
                                                     loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));

            return(View(model));
        }
        /// <summary>
        /// Prepare billing address model
        /// </summary>
        /// <param name="cart">Cart</param>
        /// <param name="selectedCountryId">Selected country identifier</param>
        /// <param name="prePopulateNewAddressWithCustomerFields">Pre populate new address with customer fields</param>
        /// <param name="overrideAttributesXml">Override attributes xml</param>
        /// <returns>Billing address model</returns>
        public virtual CheckoutBillingAddressModel PrepareBillingAddressModel(IList <ShoppingCartItem> cart,
                                                                              int?selectedCountryId = null,
                                                                              bool prePopulateNewAddressWithCustomerFields = false,
                                                                              string overrideAttributesXml = "")
        {
            var model = new CheckoutBillingAddressModel();

            model.ShipToSameAddressAllowed = _shippingSettings.ShipToSameAddress && cart.RequiresShipping();
            model.ShipToSameAddress        = true;

            //existing addresses
            var addresses = _workContext.CurrentCustomer.Addresses
                            .Where(a => a.Country == null ||
                                   (//published
                                       a.Country.Published &&
                                       //allow billing
                                       a.Country.AllowsBilling &&
                                       //enabled for the current store
                                       _storeMappingService.Authorize(a.Country)))
                            .ToList();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings);
                model.ExistingAddresses.Add(addressModel);
            }

            //new address
            model.NewAddress.CountryId = selectedCountryId;
            _addressModelFactory.PrepareAddressModel(model.NewAddress,
                                                     address: null,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings,
                                                     loadCountries: () => _countryService.GetAllCountriesForBilling(_workContext.WorkingLanguage.Id),
                                                     prePopulateWithCustomerFields: prePopulateNewAddressWithCustomerFields,
                                                     customer: _workContext.CurrentCustomer,
                                                     overrideAttributesXml: overrideAttributesXml);
            return(model);
        }
示例#4
0
        /// <summary>
        /// Prepare the user address list model
        /// </summary>
        /// <returns>User address list model</returns>
        public virtual UserAddressListModel PrepareUserAddressListModel()
        {
            var addresses = _workContext.CurrentUser.Addresses.ToList();

            var model = new UserAddressListModel();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings,
                                                         loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
                model.Addresses.Add(addressModel);
            }
            return(model);
        }
        public virtual CustomerAddressListModel PrepareCustomerAddressListModel()
        {
            var addresses = _workContext.CurrentCustomer.Addresses
                            //enabled for the current store
                            .Where(a => a.Country == null || _storeMappingService.Authorize(a.Country))
                            .ToList();

            var model = new CustomerAddressListModel();

            foreach (var address in addresses)
            {
                var addressModel = new AddressModel();
                _addressModelFactory.PrepareAddressModel(addressModel,
                                                         address: address,
                                                         excludeProperties: false,
                                                         addressSettings: _addressSettings,
                                                         loadCountries: () => _countryService.GetAllCountries(_workContext.WorkingLanguage.Id));
                model.Addresses.Add(addressModel);
            }
            return(model);
        }
        /// <summary>
        /// Prepare the order details model
        /// </summary>
        /// <param name="order">Order</param>
        /// <returns>Order details model</returns>
        public virtual OrderDetailsModel PrepareOrderDetailsModel(Order order)
        {
            if (order == null)
            {
                throw new ArgumentNullException(nameof(order));
            }
            var model = new OrderDetailsModel
            {
                Id                     = order.Id,
                CreatedOn              = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc),
                OrderStatus            = _localizationService.GetLocalizedEnum(order.OrderStatus),
                IsReOrderAllowed       = _orderSettings.IsReOrderAllowed,
                IsReturnRequestAllowed = _orderProcessingService.IsReturnRequestAllowed(order),
                PdfInvoiceDisabled     = _pdfSettings.DisablePdfInvoicesForPendingOrders && order.OrderStatus == OrderStatus.Pending,
                CustomOrderNumber      = order.CustomOrderNumber,

                //shipping info
                ShippingStatus = _localizationService.GetLocalizedEnum(order.ShippingStatus)
            };

            if (order.ShippingStatus != ShippingStatus.ShippingNotRequired)
            {
                model.IsShippable   = true;
                model.PickUpInStore = order.PickUpInStore;
                if (!order.PickUpInStore)
                {
                    _addressModelFactory.PrepareAddressModel(model.ShippingAddress,
                                                             address: order.ShippingAddress,
                                                             excludeProperties: false,
                                                             addressSettings: _addressSettings);
                }
                else
                if (order.PickupAddress != null)
                {
                    model.PickupAddress = new AddressModel
                    {
                        Address1      = order.PickupAddress.Address1,
                        City          = order.PickupAddress.City,
                        County        = order.PickupAddress.County,
                        CountryName   = order.PickupAddress.Country != null ? order.PickupAddress.Country.Name : string.Empty,
                        ZipPostalCode = order.PickupAddress.ZipPostalCode
                    }
                }
                ;
                model.ShippingMethod = order.ShippingMethod;

                //shipments (only already shipped)
                var shipments = order.Shipments.Where(x => x.ShippedDateUtc.HasValue).OrderBy(x => x.CreatedOnUtc).ToList();
                foreach (var shipment in shipments)
                {
                    var shipmentModel = new OrderDetailsModel.ShipmentBriefModel
                    {
                        Id             = shipment.Id,
                        TrackingNumber = shipment.TrackingNumber,
                    };
                    if (shipment.ShippedDateUtc.HasValue)
                    {
                        shipmentModel.ShippedDate = _dateTimeHelper.ConvertToUserTime(shipment.ShippedDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (shipment.DeliveryDateUtc.HasValue)
                    {
                        shipmentModel.DeliveryDate = _dateTimeHelper.ConvertToUserTime(shipment.DeliveryDateUtc.Value, DateTimeKind.Utc);
                    }
                    model.Shipments.Add(shipmentModel);
                }
            }

            //billing info
            _addressModelFactory.PrepareAddressModel(model.BillingAddress,
                                                     address: order.BillingAddress,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings);

            //VAT number
            model.VatNumber = order.VatNumber;

            //payment method
            var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName);

            model.PaymentMethod = paymentMethod != null?_localizationService.GetLocalizedFriendlyName(paymentMethod, _workContext.WorkingLanguage.Id) : order.PaymentMethodSystemName;

            model.PaymentMethodStatus     = _localizationService.GetLocalizedEnum(order.PaymentStatus);
            model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(order);
            //custom values
            model.CustomValues = _paymentService.DeserializeCustomValues(order);

            //order subtotal
            if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal)
            {
                //including tax

                //order subtotal
                var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate);
                model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                //discount (applied to order subtotal)
                var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate);
                if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
            }
            else
            {
                //excluding tax

                //order subtotal
                var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate);
                model.OrderSubtotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                //discount (applied to order subtotal)
                var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate);
                if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.OrderSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                //including tax

                //order shipping
                var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate);
                model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                //payment method additional fee
                var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate);
                if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
            }
            else
            {
                //excluding tax

                //order shipping
                var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate);
                model.OrderShipping = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                //payment method additional fee
                var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate);
                if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            //tax
            var displayTax      = true;
            var displayTaxRates = true;

            if (_taxSettings.HideTaxInOrderSummary && order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                displayTax      = false;
                displayTaxRates = false;
            }
            else
            {
                if (order.OrderTax == 0 && _taxSettings.HideZeroTax)
                {
                    displayTax      = false;
                    displayTaxRates = false;
                }
                else
                {
                    var taxRates = _orderService.ParseTaxRates(order, order.TaxRates);
                    displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Any();
                    displayTax      = !displayTaxRates;

                    var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate);
                    //TODO pass languageId to _priceFormatter.FormatPrice
                    model.Tax = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);

                    foreach (var tr in taxRates)
                    {
                        model.TaxRates.Add(new OrderDetailsModel.TaxRate
                        {
                            Rate = _priceFormatter.FormatTaxRate(tr.Key),
                            //TODO pass languageId to _priceFormatter.FormatPrice
                            Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, order.CurrencyRate), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage),
                        });
                    }
                }
            }
            model.DisplayTaxRates        = displayTaxRates;
            model.DisplayTax             = displayTax;
            model.DisplayTaxShippingInfo = _catalogSettings.DisplayTaxShippingInfoOrderDetailsPage;
            model.PricesIncludeTax       = order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax;

            //discount (applied to order total)
            var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate);

            if (orderDiscountInCustomerCurrency > decimal.Zero)
            {
                model.OrderTotalDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);
            }

            //gift cards
            foreach (var gcuh in order.GiftCardUsageHistory)
            {
                model.GiftCards.Add(new OrderDetailsModel.GiftCard
                {
                    CouponCode = gcuh.GiftCard.GiftCardCouponCode,
                    Amount     = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage),
                });
            }

            //reward points
            if (order.RedeemedRewardPointsEntry != null)
            {
                model.RedeemedRewardPoints       = -order.RedeemedRewardPointsEntry.Points;
                model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);
            }

            //total
            var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate);

            model.OrderTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, order.CustomerCurrencyCode, false, _workContext.WorkingLanguage);

            //checkout attributes
            model.CheckoutAttributeInfo = order.CheckoutAttributeDescription;

            //order notes
            foreach (var orderNote in order.OrderNotes
                     .Where(on => on.DisplayToCustomer)
                     .OrderByDescending(on => on.CreatedOnUtc)
                     .ToList())
            {
                model.OrderNotes.Add(new OrderDetailsModel.OrderNote
                {
                    Id          = orderNote.Id,
                    HasDownload = orderNote.DownloadId > 0,
                    Note        = _orderService.FormatOrderNoteText(orderNote),
                    CreatedOn   = _dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc)
                });
            }

            //purchased products
            model.ShowSku        = _catalogSettings.ShowSkuOnProductDetailsPage;
            model.ShowVendorName = _vendorSettings.ShowVendorOnOrderDetailsPage;

            var orderItems = order.OrderItems;

            var vendors = _vendorSettings.ShowVendorOnOrderDetailsPage ? _vendorService.GetVendorsByIds(orderItems.Select(item => item.Product.VendorId).ToArray()) : new List <Vendor>();

            foreach (var orderItem in orderItems)
            {
                var orderItemModel = new OrderDetailsModel.OrderItemModel
                {
                    Id            = orderItem.Id,
                    OrderItemGuid = orderItem.OrderItemGuid,
                    Sku           = _productService.FormatSku(orderItem.Product, orderItem.AttributesXml),
                    VendorName    = vendors.FirstOrDefault(v => v.Id == orderItem.Product.VendorId)?.Name ?? string.Empty,
                    ProductId     = orderItem.Product.Id,
                    ProductName   = _localizationService.GetLocalized(orderItem.Product, x => x.Name),
                    ProductSeName = _urlRecordService.GetSeName(orderItem.Product),
                    Quantity      = orderItem.Quantity,
                    AttributeInfo = orderItem.AttributeDescription,
                };
                //rental info
                if (orderItem.Product.IsRental)
                {
                    var rentalStartDate = orderItem.RentalStartDateUtc.HasValue
                        ? _productService.FormatRentalDate(orderItem.Product, orderItem.RentalStartDateUtc.Value) : "";
                    var rentalEndDate = orderItem.RentalEndDateUtc.HasValue
                        ? _productService.FormatRentalDate(orderItem.Product, orderItem.RentalEndDateUtc.Value) : "";
                    orderItemModel.RentalInfo = string.Format(_localizationService.GetResource("Order.Rental.FormattedDate"),
                                                              rentalStartDate, rentalEndDate);
                }
                model.Items.Add(orderItemModel);

                //unit price, subtotal
                if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceInclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);

                    var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceInclTax, order.CurrencyRate);
                    orderItemModel.SubTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
                else
                {
                    //excluding tax
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.UnitPriceExclTax, order.CurrencyRate);
                    orderItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);

                    var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(orderItem.PriceExclTax, order.CurrencyRate);
                    orderItemModel.SubTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, order.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }

                //downloadable products
                if (_downloadService.IsDownloadAllowed(orderItem))
                {
                    orderItemModel.DownloadId = orderItem.Product.DownloadId;
                }
                if (_downloadService.IsLicenseDownloadAllowed(orderItem))
                {
                    orderItemModel.LicenseId = orderItem.LicenseDownloadId.HasValue ? orderItem.LicenseDownloadId.Value : 0;
                }
            }

            return(model);
        }
示例#7
0
        /// <summary>
        /// Prepare the subscription details model
        /// </summary>
        /// <param name="subscription">Subscription</param>
        /// <returns>Subscription details model</returns>
        public virtual SubscriptionDetailsModel PrepareSubscriptionDetailsModel(Subscription subscription)
        {
            if (subscription == null)
            {
                throw new ArgumentNullException("subscription");
            }
            var model = new SubscriptionDetailsModel();

            model.Id                       = subscription.Id;
            model.CreatedOn                = _dateTimeHelper.ConvertToUserTime(subscription.CreatedOnUtc, DateTimeKind.Utc);
            model.SubscriptionStatus       = subscription.SubscriptionStatus.GetLocalizedEnum(_localizationService, _workContext);
            model.IsReSubscriptionAllowed  = _subscriptionSettings.IsReSubscriptionAllowed;
            model.IsReturnRequestAllowed   = _subscriptionProcessingService.IsReturnRequestAllowed(subscription);
            model.PdfInvoiceDisabled       = _pdfSettings.DisablePdfInvoicesForPendingSubscriptions && subscription.SubscriptionStatus == SubscriptionStatus.Pending;
            model.CustomSubscriptionNumber = subscription.CustomSubscriptionNumber;



            //billing info
            _addressModelFactory.PrepareAddressModel(model.BillingAddress,
                                                     address: subscription.BillingAddress,
                                                     excludeProperties: false,
                                                     addressSettings: _addressSettings);

            //VAT number
            model.VatNumber = subscription.VatNumber;

            //payment method
            var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(subscription.PaymentMethodSystemName);

            model.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, _workContext.WorkingLanguage.Id) : subscription.PaymentMethodSystemName;

            model.PaymentMethodStatus     = subscription.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
            model.CanRePostProcessPayment = _paymentService.CanRePostProcessPayment(subscription);
            //custom values
            model.CustomValues = subscription.DeserializeCustomValues();

            //subscription subtotal
            if (subscription.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromSubscriptionSubtotal)
            {
                //including tax

                //subscription subtotal
                var subscriptionSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionSubtotalInclTax, subscription.CurrencyRate);
                model.SubscriptionSubtotal = _priceFormatter.FormatPrice(subscriptionSubtotalInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                //discount (applied to subscription subtotal)
                var subscriptionSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionSubTotalDiscountInclTax, subscription.CurrencyRate);
                if (subscriptionSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.SubscriptionSubTotalDiscount = _priceFormatter.FormatPrice(-subscriptionSubTotalDiscountInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
            }
            else
            {
                //excluding tax

                //subscription subtotal
                var subscriptionSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionSubtotalExclTax, subscription.CurrencyRate);
                model.SubscriptionSubtotal = _priceFormatter.FormatPrice(subscriptionSubtotalExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                //discount (applied to subscription subtotal)
                var subscriptionSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionSubTotalDiscountExclTax, subscription.CurrencyRate);
                if (subscriptionSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.SubscriptionSubTotalDiscount = _priceFormatter.FormatPrice(-subscriptionSubTotalDiscountExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            if (subscription.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                //including tax

                //subscription shipping
                var subscriptionShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionShippingInclTax, subscription.CurrencyRate);
                model.SubscriptionShipping = _priceFormatter.FormatShippingPrice(subscriptionShippingInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                //payment method additional fee
                var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.PaymentMethodAdditionalFeeInclTax, subscription.CurrencyRate);
                if (paymentMethodAdditionalFeeInclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
            }
            else
            {
                //excluding tax

                //subscription shipping
                var subscriptionShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionShippingExclTax, subscription.CurrencyRate);
                model.SubscriptionShipping = _priceFormatter.FormatShippingPrice(subscriptionShippingExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                //payment method additional fee
                var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.PaymentMethodAdditionalFeeExclTax, subscription.CurrencyRate);
                if (paymentMethodAdditionalFeeExclTaxInCustomerCurrency > decimal.Zero)
                {
                    model.PaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }
            }

            //tax
            bool displayTax      = true;
            bool displayTaxRates = true;

            if (_taxSettings.HideTaxInSubscriptionSummary && subscription.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
            {
                displayTax      = false;
                displayTaxRates = false;
            }
            else
            {
                if (subscription.SubscriptionTax == 0 && _taxSettings.HideZeroTax)
                {
                    displayTax      = false;
                    displayTaxRates = false;
                }
                else
                {
                    displayTaxRates = _taxSettings.DisplayTaxRates && subscription.TaxRatesDictionary.Any();
                    displayTax      = !displayTaxRates;

                    var subscriptionTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionTax, subscription.CurrencyRate);
                    //TODO pass languageId to _priceFormatter.FormatPrice
                    model.Tax = _priceFormatter.FormatPrice(subscriptionTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage);

                    foreach (var tr in subscription.TaxRatesDictionary)
                    {
                        model.TaxRates.Add(new SubscriptionDetailsModel.TaxRate
                        {
                            Rate = _priceFormatter.FormatTaxRate(tr.Key),
                            //TODO pass languageId to _priceFormatter.FormatPrice
                            Value = _priceFormatter.FormatPrice(_currencyService.ConvertCurrency(tr.Value, subscription.CurrencyRate), true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage),
                        });
                    }
                }
            }
            model.DisplayTaxRates        = displayTaxRates;
            model.DisplayTax             = displayTax;
            model.DisplayTaxShippingInfo = _catalogSettings.DisplayTaxShippingInfoSubscriptionDetailsPage;
            model.PricesIncludeTax       = subscription.CustomerTaxDisplayType == TaxDisplayType.IncludingTax;

            //discount (applied to subscription total)
            var subscriptionDiscountInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionDiscount, subscription.CurrencyRate);

            if (subscriptionDiscountInCustomerCurrency > decimal.Zero)
            {
                model.SubscriptionTotalDiscount = _priceFormatter.FormatPrice(-subscriptionDiscountInCustomerCurrency, true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage);
            }



            //reward points
            if (subscription.RedeemedRewardPointsEntry != null)
            {
                model.RedeemedRewardPoints       = -subscription.RedeemedRewardPointsEntry.Points;
                model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(subscription.RedeemedRewardPointsEntry.UsedAmount, subscription.CurrencyRate)), true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage);
            }

            //total
            var subscriptionTotalInCustomerCurrency = _currencyService.ConvertCurrency(subscription.SubscriptionTotal, subscription.CurrencyRate);

            model.SubscriptionTotal = _priceFormatter.FormatPrice(subscriptionTotalInCustomerCurrency, true, subscription.CustomerCurrencyCode, false, _workContext.WorkingLanguage);

            //checkout attributes
            model.CheckoutAttributeInfo = subscription.CheckoutAttributeDescription;

            //subscription notes
            foreach (var subscriptionNote in subscription.SubscriptionNotes
                     .Where(on => on.DisplayToCustomer)
                     .OrderByDescending(on => on.CreatedOnUtc)
                     .ToList())
            {
                model.SubscriptionNotes.Add(new SubscriptionDetailsModel.SubscriptionNote
                {
                    Id          = subscriptionNote.Id,
                    HasDownload = subscriptionNote.DownloadId > 0,
                    Note        = subscriptionNote.FormatSubscriptionNoteText(),
                    CreatedOn   = _dateTimeHelper.ConvertToUserTime(subscriptionNote.CreatedOnUtc, DateTimeKind.Utc)
                });
            }


            //purchased articles
            model.ShowSku = _catalogSettings.ShowSkuOnArticleDetailsPage;
            var subscriptionItems = subscription.SubscriptionItems;

            foreach (var subscriptionItem in subscriptionItems)
            {
                var subscriptionItemModel = new SubscriptionDetailsModel.SubscriptionItemModel
                {
                    Id = subscriptionItem.Id,
                    SubscriptionItemGuid = subscriptionItem.SubscriptionItemGuid,
                    Sku           = subscriptionItem.Article.FormatSku(subscriptionItem.AttributesXml, _articleAttributeParser),
                    ArticleId     = subscriptionItem.Article.Id,
                    ArticleName   = subscriptionItem.Article.GetLocalized(x => x.Name),
                    ArticleSeName = subscriptionItem.Article.GetSeName(),
                    Quantity      = subscriptionItem.Quantity,
                    AttributeInfo = subscriptionItem.AttributeDescription,
                };
                //rental info
                if (subscriptionItem.Article.IsRental)
                {
                    var rentalStartDate = subscriptionItem.RentalStartDateUtc.HasValue ? subscriptionItem.Article.FormatRentalDate(subscriptionItem.RentalStartDateUtc.Value) : "";
                    var rentalEndDate   = subscriptionItem.RentalEndDateUtc.HasValue ? subscriptionItem.Article.FormatRentalDate(subscriptionItem.RentalEndDateUtc.Value) : "";
                    subscriptionItemModel.RentalInfo = string.Format(_localizationService.GetResource("Subscription.Rental.FormattedDate"),
                                                                     rentalStartDate, rentalEndDate);
                }
                model.Items.Add(subscriptionItemModel);

                //unit price, subtotal
                if (subscription.CustomerTaxDisplayType == TaxDisplayType.IncludingTax)
                {
                    //including tax
                    var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscriptionItem.UnitPriceInclTax, subscription.CurrencyRate);
                    subscriptionItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);

                    var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscriptionItem.PriceInclTax, subscription.CurrencyRate);
                    subscriptionItemModel.SubTotal = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, true);
                }
                else
                {
                    //excluding tax
                    var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscriptionItem.UnitPriceExclTax, subscription.CurrencyRate);
                    subscriptionItemModel.UnitPrice = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);

                    var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(subscriptionItem.PriceExclTax, subscription.CurrencyRate);
                    subscriptionItemModel.SubTotal = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, subscription.CustomerCurrencyCode, _workContext.WorkingLanguage, false);
                }


                if (_downloadService.IsLicenseDownloadAllowed(subscriptionItem))
                {
                    subscriptionItemModel.LicenseId = subscriptionItem.LicenseDownloadId.HasValue ? subscriptionItem.LicenseDownloadId.Value : 0;
                }
            }

            return(model);
        }