//address /// <summary> /// Prepare address model /// </summary> /// <param name="model">Model</param> /// <param name="address">Address</param> /// <param name="excludeProperties">A value indicating whether to exclude properties</param> /// <param name="loadCountries">A function to load countries (used to prepare a select list). null to don't prepare the list.</param> /// <param name="prePopulateWithCustomerFields">A value indicating whether to pre-populate an address with customer fields entered during registration. It's used only when "address" parameter is set to "null"</param> /// <param name="customer">Customer record which will be used to pre-populate address. Used only when "prePopulateWithCustomerFields" is "true".</param> public virtual void PrepareModel(AddressModel model, Address address, bool excludeProperties, Func <IList <Country> > loadCountries = null, bool prePopulateWithCustomerFields = false, Customer customer = null, string overrideAttributesXml = "") { //prepare address model PrepareAddressModel(model, address, excludeProperties, loadCountries, prePopulateWithCustomerFields, customer, _addressSettings); //customer attribute services PrepareCustomAddressAttributes(model, address, overrideAttributesXml); if (address != null) { model.FormattedCustomAddressAttributes = _addressAttributeFormatter.FormatAttributes(address.CustomAttributes); } }
public async Task <AddressModel> Handle(GetAddressModel request, CancellationToken cancellationToken) { var model = request.Model ?? new AddressModel(); //prepare address model await PrepareAddressModel(model, request.Address, request.ExcludeProperties, request.LoadCountries, request.PrePopulateWithCustomerFields, request.Customer, request.Language, request.Store); //customer attribute services await PrepareCustomAddressAttributes(model, request.Address, request.Language, request.OverrideAttributesXml); if (request.Address != null) { model.FormattedCustomAddressAttributes = await _addressAttributeFormatter.FormatAttributes(request.Address.CustomAttributes); } return(model); }
public async Task <LiquidOrder> Handle(GetOrderTokensCommand request, CancellationToken cancellationToken) { var language = await _languageService.GetLanguageById(request.Order.CustomerLanguageId); var currency = await _currencyService.GetCurrencyByCode(request.Order.CustomerCurrencyCode); var liquidOrder = new LiquidOrder(request.Order, request.Customer, language, currency, request.Store, request.OrderNote, request.Vendor); foreach (var item in request.Order.OrderItems.Where(x => x.VendorId == request.Vendor?.Id || request.Vendor == null)) { var product = await _productService.GetProductById(item.ProductId); Vendor vendorItem = string.IsNullOrEmpty(item.VendorId) ? null : await _vendorService.GetVendorById(item.VendorId); var liqitem = new LiquidOrderItem(item, product, request.Order, language, currency, request.Store, vendorItem); #region Download liqitem.IsDownloadAllowed = _downloadService.IsDownloadAllowed(request.Order, item, product); liqitem.IsLicenseDownloadAllowed = _downloadService.IsLicenseDownloadAllowed(request.Order, item, product); #endregion #region Unit price string unitPriceStr; if (request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax unitPriceStr = _priceFormatter.FormatPrice(item.UnitPriceInclTax, true, currency, language, true); } else { //excluding tax unitPriceStr = _priceFormatter.FormatPrice(item.UnitPriceExclTax, true, currency, language, false); } liqitem.UnitPrice = unitPriceStr; #endregion #region total price string priceStr; if (request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax priceStr = _priceFormatter.FormatPrice(item.PriceInclTax, true, currency, language, true); } else { //excluding tax priceStr = _priceFormatter.FormatPrice(item.PriceExclTax, true, currency, language, false); } liqitem.TotalPrice = priceStr; #endregion string sku = ""; if (product != null) { sku = product.FormatSku(item.AttributesXml, _productAttributeParser); } liqitem.ProductSku = WebUtility.HtmlEncode(sku); liqitem.ShowSkuOnProductDetailsPage = _catalogSettings.ShowSkuOnProductDetailsPage; liqitem.ProductOldPrice = _priceFormatter.FormatPrice(product.OldPrice, true, currency, language, true); liquidOrder.OrderItems.Add(liqitem); } liquidOrder.BillingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(request.Order.BillingAddress?.CustomAttributes); liquidOrder.BillingCountry = request.Order.BillingAddress != null && !string.IsNullOrEmpty(request.Order.BillingAddress.CountryId) ? (await _countryService.GetCountryById(request.Order.BillingAddress.CountryId))?.GetLocalized(x => x.Name, request.Order.CustomerLanguageId) : ""; liquidOrder.BillingStateProvince = !string.IsNullOrEmpty(request.Order.BillingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(request.Order.BillingAddress.StateProvinceId))?.GetLocalized(x => x.Name, request.Order.CustomerLanguageId) : ""; liquidOrder.ShippingCountry = request.Order.ShippingAddress != null && !string.IsNullOrEmpty(request.Order.ShippingAddress.CountryId) ? (await _countryService.GetCountryById(request.Order.ShippingAddress.CountryId))?.GetLocalized(x => x.Name, request.Order.CustomerLanguageId) : ""; liquidOrder.ShippingStateProvince = request.Order.ShippingAddress != null && !string.IsNullOrEmpty(request.Order.ShippingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(request.Order.ShippingAddress.StateProvinceId)).GetLocalized(x => x.Name, request.Order.CustomerLanguageId) : ""; liquidOrder.ShippingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(request.Order.ShippingAddress != null?request.Order.ShippingAddress.CustomAttributes : ""); var paymentMethod = _paymentService.LoadPaymentMethodBySystemName(request.Order.PaymentMethodSystemName); liquidOrder.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, language.Id) : request.Order.PaymentMethodSystemName; liquidOrder.AmountRefunded = _priceFormatter.FormatPrice(request.RefundedAmount, true, currency, language, false); Dictionary <string, string> dict = new Dictionary <string, string>(); foreach (var item in request.Order.OrderTaxes) { string taxRate = string.Format(_localizationService.GetResource("Messages.Order.TaxRateLine"), _priceFormatter.FormatTaxRate(item.Percent)); string taxValue = _priceFormatter.FormatPrice(item.Amount, true, currency, language, false); dict.Add(taxRate, taxValue); } liquidOrder.TaxRates = dict; Dictionary <string, string> cards = new Dictionary <string, string>(); var gcuhC = await _giftCardService.GetAllGiftCardUsageHistory(request.Order.Id); foreach (var gcuh in gcuhC) { var giftCard = await _giftCardService.GetGiftCardById(gcuh.GiftCardId); string giftCardText = string.Format(_localizationService.GetResource("Messages.Order.GiftCardInfo", language.Id), WebUtility.HtmlEncode(giftCard.GiftCardCouponCode)); string giftCardAmount = _priceFormatter.FormatPrice(-gcuh.UsedValue, true, currency, language, false); cards.Add(giftCardText, giftCardAmount); } liquidOrder.GiftCards = cards; if (request.Order.RedeemedRewardPointsEntry != null) { liquidOrder.RPTitle = string.Format(_localizationService.GetResource("Messages.Order.RewardPoints", language.Id), -request.Order.RedeemedRewardPointsEntry?.Points); liquidOrder.RPAmount = _priceFormatter.FormatPrice(-request.Order.RedeemedRewardPointsEntry.UsedAmount, true, currency, language, false); } void CalculateSubTotals() { string _cusSubTotal; bool _displaySubTotalDiscount; string _cusSubTotalDiscount; string _cusShipTotal; string _cusPaymentMethodAdditionalFee; bool _displayTax; string _cusTaxTotal; bool _displayTaxRates; bool _displayDiscount; string _cusDiscount; string _cusTotal; _displaySubTotalDiscount = false; _cusSubTotalDiscount = string.Empty; if (request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal) { //including tax //subtotal _cusSubTotal = _priceFormatter.FormatPrice(request.Order.OrderSubtotalInclTax, true, currency, language, true); //discount (applied to order subtotal) if (request.Order.OrderSubTotalDiscountInclTax > decimal.Zero) { _cusSubTotalDiscount = _priceFormatter.FormatPrice(-request.Order.OrderSubTotalDiscountInclTax, true, currency, language, true); _displaySubTotalDiscount = true; } } else { //exсluding tax //subtotal _cusSubTotal = _priceFormatter.FormatPrice(request.Order.OrderSubtotalExclTax, true, currency, language, false); //discount (applied to order subtotal) if (request.Order.OrderSubTotalDiscountExclTax > decimal.Zero) { _cusSubTotalDiscount = _priceFormatter.FormatPrice(-request.Order.OrderSubTotalDiscountExclTax, true, currency, language, false); _displaySubTotalDiscount = true; } } //shipping, payment method fee _cusTaxTotal = string.Empty; _cusDiscount = string.Empty; if (request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax //shipping _cusShipTotal = _priceFormatter.FormatShippingPrice(request.Order.OrderShippingInclTax, true, currency, language, true); //payment method additional fee _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(request.Order.PaymentMethodAdditionalFeeInclTax, true, currency, language, true); } else { //excluding tax //shipping _cusShipTotal = _priceFormatter.FormatShippingPrice(request.Order.OrderShippingExclTax, true, currency, language, false); //payment method additional fee _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(request.Order.PaymentMethodAdditionalFeeExclTax, true, currency, language, false); } //shipping bool displayShipping = request.Order.ShippingStatus != ShippingStatus.ShippingNotRequired; //payment method fee bool displayPaymentMethodFee = request.Order.PaymentMethodAdditionalFeeExclTax > decimal.Zero; //tax _displayTax = true; _displayTaxRates = true; if (_taxSettings.HideTaxInOrderSummary && request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { _displayTax = false; _displayTaxRates = false; } else { if (request.Order.OrderTax == 0 && _taxSettings.HideZeroTax) { _displayTax = false; _displayTaxRates = false; } else { _displayTaxRates = _taxSettings.DisplayTaxRates && request.Order.OrderTaxes.Any(); _displayTax = !_displayTaxRates; string taxStr = _priceFormatter.FormatPrice(request.Order.OrderTax, true, currency, language, request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); _cusTaxTotal = taxStr; } } //discount _displayDiscount = false; if (request.Order.OrderDiscount > decimal.Zero) { _cusDiscount = _priceFormatter.FormatPrice(-request.Order.OrderDiscount, true, currency, language, request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); _displayDiscount = true; } //total _cusTotal = _priceFormatter.FormatPrice(request.Order.OrderTotal, true, currency, language, request.Order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); liquidOrder.SubTotal = _cusSubTotal; liquidOrder.DisplaySubTotalDiscount = _displaySubTotalDiscount; liquidOrder.SubTotalDiscount = _cusSubTotalDiscount; liquidOrder.Shipping = _cusShipTotal; liquidOrder.Discount = _cusDiscount; liquidOrder.PaymentMethodAdditionalFee = _cusPaymentMethodAdditionalFee; liquidOrder.Tax = _cusTaxTotal; liquidOrder.Total = _cusTotal; liquidOrder.DisplayTax = _displayTax; liquidOrder.DisplayDiscount = _displayDiscount; liquidOrder.DisplayTaxRates = _displayTaxRates; } CalculateSubTotals(); return(liquidOrder); }
//address /// <summary> /// Prepare address model /// </summary> /// <param name="model">Model</param> /// <param name="address">Address</param> /// <param name="excludeProperties">A value indicating whether to exclude properties</param> /// <param name="addressSettings">Address settings</param> /// <param name="localizationService">Localization service (used to prepare a select list)</param> /// <param name="stateProvinceService">State service (used to prepare a select list). null to don't prepare the list.</param> /// <param name="addressAttributeService">Address attribute service. null to don't prepare the list.</param> /// <param name="addressAttributeParser">Address attribute parser. null to don't prepare the list.</param> /// <param name="addressAttributeFormatter">Address attribute formatter. null to don't prepare the formatted custom attributes.</param> /// <param name="loadCountries">A function to load countries (used to prepare a select list). null to don't prepare the list.</param> /// <param name="prePopulateWithCustomerFields">A value indicating whether to pre-populate an address with customer fields entered during registration. It's used only when "address" parameter is set to "null"</param> /// <param name="customer">Customer record which will be used to pre-populate address. Used only when "prePopulateWithCustomerFields" is "true".</param> /// <param name="overrideAttributesXml">When specified we do not use attributes of an address; if null, then already saved ones are used</param> public static void PrepareModel(this AddressModel model, Address address, bool excludeProperties, AddressSettings addressSettings, ILocalizationService localizationService = null, IStateProvinceService stateProvinceService = null, IAddressAttributeService addressAttributeService = null, IAddressAttributeParser addressAttributeParser = null, IAddressAttributeFormatter addressAttributeFormatter = null, Func <IList <Country> > loadCountries = null, bool prePopulateWithCustomerFields = false, Customer customer = null, string overrideAttributesXml = "") { if (model == null) { throw new ArgumentNullException("model"); } if (addressSettings == null) { throw new ArgumentNullException("addressSettings"); } if (!excludeProperties && address != null) { model.Id = address.Id; model.FirstName = address.FirstName; model.LastName = address.LastName; model.Email = address.Email; model.Company = address.Company; model.CountryId = address.CountryId; model.CountryName = address.Country != null ? address.Country.GetLocalized(x => x.Name) : null; model.StateProvinceId = address.StateProvinceId; model.StateProvinceName = address.StateProvince != null ? address.StateProvince.GetLocalized(x => x.Name) : null; model.City = address.City; model.Address1 = address.Address1; model.Address2 = address.Address2; model.ZipPostalCode = address.ZipPostalCode; model.PhoneNumber = address.PhoneNumber; model.FaxNumber = address.FaxNumber; } if (address == null && prePopulateWithCustomerFields) { if (customer == null) { throw new Exception("Customer cannot be null when prepopulating an address"); } model.Email = customer.Email; model.FirstName = customer.GetAttribute <string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute <string>(SystemCustomerAttributeNames.LastName); model.Company = customer.GetAttribute <string>(SystemCustomerAttributeNames.Company); model.Address1 = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress); model.Address2 = customer.GetAttribute <string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute <string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute <string>(SystemCustomerAttributeNames.City); //ignore country and state for prepopulation. it can cause some issues when posting pack with errors, etc //model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); //model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.PhoneNumber = customer.GetAttribute <string>(SystemCustomerAttributeNames.Phone); model.FaxNumber = customer.GetAttribute <string>(SystemCustomerAttributeNames.Fax); } //countries and states if (addressSettings.CountryEnabled && loadCountries != null) { if (localizationService == null) { throw new ArgumentNullException("localizationService"); } model.AvailableCountries.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in loadCountries()) { model.AvailableCountries.Add(new SelectListItem { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (addressSettings.StateProvinceEnabled) { //states if (stateProvinceService == null) { throw new ArgumentNullException("stateProvinceService"); } var languageId = EngineContext.Current.Resolve <IWorkContext>().WorkingLanguage.Id; var states = stateProvinceService .GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0, languageId) .ToList(); if (states.Any()) { model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } //form fields model.CompanyEnabled = addressSettings.CompanyEnabled; model.CompanyRequired = addressSettings.CompanyRequired; model.StreetAddressEnabled = addressSettings.StreetAddressEnabled; model.StreetAddressRequired = addressSettings.StreetAddressRequired; model.StreetAddress2Enabled = addressSettings.StreetAddress2Enabled; model.StreetAddress2Required = addressSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = addressSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = addressSettings.ZipPostalCodeRequired; model.CityEnabled = addressSettings.CityEnabled; model.CityRequired = addressSettings.CityRequired; model.CountryEnabled = addressSettings.CountryEnabled; model.StateProvinceEnabled = addressSettings.StateProvinceEnabled; model.PhoneEnabled = addressSettings.PhoneEnabled; model.PhoneRequired = addressSettings.PhoneRequired; model.FaxEnabled = addressSettings.FaxEnabled; model.FaxRequired = addressSettings.FaxRequired; //customer attribute services if (addressAttributeService != null && addressAttributeParser != null) { PrepareCustomAddressAttributes(model, address, addressAttributeService, addressAttributeParser, overrideAttributesXml); } if (addressAttributeFormatter != null && address != null) { model.FormattedCustomAddressAttributes = addressAttributeFormatter.FormatAttributes(address.CustomAttributes); } }
//address /// <summary> /// Prepare address model /// </summary> /// <param name="model">Model</param> /// <param name="address">Address</param> /// <param name="excludeProperties">A value indicating whether to exclude properties</param> /// <param name="addressSettings">Address settings</param> /// <param name="localizationService">Localization service (used to prepare a select list)</param> /// <param name="stateProvinceService">State service (used to prepare a select list). null to don't prepare the list.</param> /// <param name="addressAttributeService">Address attribute service. null to don't prepare the list.</param> /// <param name="addressAttributeParser">Address attribute parser. null to don't prepare the list.</param> /// <param name="addressAttributeFormatter">Address attribute formatter. null to don't prepare the formatted custom attributes.</param> /// <param name="loadCountries">A function to load countries (used to prepare a select list). null to don't prepare the list.</param> /// <param name="prePopulateWithCustomerFields">A value indicating whether to pre-populate an address with customer fields entered during registration. It's used only when "address" parameter is set to "null"</param> /// <param name="customer">Customer record which will be used to pre-populate address. Used only when "prePopulateWithCustomerFields" is "true".</param> /// <param name="overrideAttributesXml">When specified we do not use attributes of an address; if null, then already saved ones are used</param> public static void PrepareModel(this AddressModel model, Address address, bool excludeProperties, AddressSettings addressSettings, ILocalizationService localizationService = null, IStateProvinceService stateProvinceService = null, IAddressAttributeService addressAttributeService = null, IAddressAttributeParser addressAttributeParser = null, IAddressAttributeFormatter addressAttributeFormatter = null, Func<IList<Country>> loadCountries = null, bool prePopulateWithCustomerFields = false, Customer customer = null, string overrideAttributesXml = "") { if (model == null) throw new ArgumentNullException("model"); if (addressSettings == null) throw new ArgumentNullException("addressSettings"); if (!excludeProperties && address != null) { model.Id = address.Id; model.FirstName = address.FirstName; model.LastName = address.LastName; model.Email = address.Email; model.Company = address.Company; model.CountryId = address.CountryId; model.CountryName = address.Country != null ? address.Country.GetLocalized(x => x.Name) : null; model.StateProvinceId = address.StateProvinceId; model.StateProvinceName = address.StateProvince != null ? address.StateProvince.GetLocalized(x => x.Name) : null; model.City = address.City; model.Address1 = address.Address1; model.Address2 = address.Address2; model.ZipPostalCode = address.ZipPostalCode; model.PhoneNumber = address.PhoneNumber; model.FaxNumber = address.FaxNumber; } if (address == null && prePopulateWithCustomerFields) { if (customer == null) throw new Exception("Customer cannot be null when prepopulating an address"); model.Email = customer.Email; model.FirstName = customer.GetAttribute<string>(SystemCustomerAttributeNames.FirstName); model.LastName = customer.GetAttribute<string>(SystemCustomerAttributeNames.LastName); model.Company = customer.GetAttribute<string>(SystemCustomerAttributeNames.Company); model.Address1 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress); model.Address2 = customer.GetAttribute<string>(SystemCustomerAttributeNames.StreetAddress2); model.ZipPostalCode = customer.GetAttribute<string>(SystemCustomerAttributeNames.ZipPostalCode); model.City = customer.GetAttribute<string>(SystemCustomerAttributeNames.City); //ignore country and state for prepopulation. it can cause some issues when posting pack with errors, etc //model.CountryId = customer.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); //model.StateProvinceId = customer.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.PhoneNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Phone); model.FaxNumber = customer.GetAttribute<string>(SystemCustomerAttributeNames.Fax); } //countries and states if (addressSettings.CountryEnabled && loadCountries != null) { if (localizationService == null) throw new ArgumentNullException("localizationService"); model.AvailableCountries.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectCountry"), Value = "0" }); foreach (var c in loadCountries()) { model.AvailableCountries.Add(new SelectListItem { Text = c.GetLocalized(x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (addressSettings.StateProvinceEnabled) { //states if (stateProvinceService == null) throw new ArgumentNullException("stateProvinceService"); var languageId = EngineContext.Current.Resolve<IWorkContext>().WorkingLanguage.Id; var states = stateProvinceService .GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0, languageId) .ToList(); if (states.Count > 0) { model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = s.GetLocalized(x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { bool anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } //form fields model.CompanyEnabled = addressSettings.CompanyEnabled; model.CompanyRequired = addressSettings.CompanyRequired; model.StreetAddressEnabled = addressSettings.StreetAddressEnabled; model.StreetAddressRequired = addressSettings.StreetAddressRequired; model.StreetAddress2Enabled = addressSettings.StreetAddress2Enabled; model.StreetAddress2Required = addressSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = addressSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = addressSettings.ZipPostalCodeRequired; model.CityEnabled = addressSettings.CityEnabled; model.CityRequired = addressSettings.CityRequired; model.CountryEnabled = addressSettings.CountryEnabled; model.StateProvinceEnabled = addressSettings.StateProvinceEnabled; model.PhoneEnabled = addressSettings.PhoneEnabled; model.PhoneRequired = addressSettings.PhoneRequired; model.FaxEnabled = addressSettings.FaxEnabled; model.FaxRequired = addressSettings.FaxRequired; //customer attribute services if (addressAttributeService != null && addressAttributeParser != null) { PrepareCustomAddressAttributes(model, address, addressAttributeService, addressAttributeParser, overrideAttributesXml); } if (addressAttributeFormatter != null && address != null) { model.FormattedCustomAddressAttributes = addressAttributeFormatter.FormatAttributes(address.CustomAttributes); } }
/// <summary> /// Prepare address model /// </summary> /// <param name="model">Address model</param> /// <param name="address">Address entity</param> /// <param name="excludeProperties">Whether to exclude populating of model properties from the entity</param> /// <param name="addressSettings">Address settings</param> /// <param name="loadCountries">Countries loading function; pass null if countries do not need to load</param> /// <param name="prePopulateWithCustomerFields">Whether to populate model properties with the customer fields (used with the customer entity)</param> /// <param name="customer">Customer entity; required if prePopulateWithCustomerFields is true</param> /// <param name="overrideAttributesXml">Overridden address attributes in XML format; pass null to use CustomAttributes of the address entity</param> public virtual void PrepareAddressModel(AddressModel model, Address address, bool excludeProperties, AddressSettings addressSettings, Func <IList <Country> > loadCountries = null, bool prePopulateWithCustomerFields = false, Customer customer = null, string overrideAttributesXml = "") { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (addressSettings == null) { throw new ArgumentNullException(nameof(addressSettings)); } if (!excludeProperties && address != null) { model.Id = address.Id; model.FirstName = address.FirstName; model.LastName = address.LastName; model.Email = address.Email; model.Company = address.Company; model.CountryId = address.CountryId; model.CountryName = _countryService.GetCountryByAddress(address) is Country country?_localizationService.GetLocalized(country, x => x.Name) : null; model.StateProvinceId = address.StateProvinceId; model.StateProvinceName = _stateProvinceService.GetStateProvinceByAddress(address) is StateProvince stateProvince?_localizationService.GetLocalized(stateProvince, x => x.Name) : null; model.County = address.County; model.City = address.City; model.Address1 = address.Address1; model.Address2 = address.Address2; model.ZipPostalCode = address.ZipPostalCode; model.PhoneNumber = address.PhoneNumber; model.FaxNumber = address.FaxNumber; } if (address == null && prePopulateWithCustomerFields) { if (customer == null) { throw new Exception("Customer cannot be null when prepopulating an address"); } model.Email = customer.Email; model.FirstName = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FirstNameAttribute); model.LastName = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.LastNameAttribute); model.Company = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CompanyAttribute); model.Address1 = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.StreetAddressAttribute); model.Address2 = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.StreetAddress2Attribute); model.ZipPostalCode = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.ZipPostalCodeAttribute); model.City = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CityAttribute); model.County = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.CountyAttribute); //TODO: ignore country and state for prepopulation. it can cause some issues when posting pack with errors, etc //model.CountryId = _genericAttributeService.GetAttribute<int>(SystemCustomerAttributeNames.CountryId); //model.StateProvinceId = _genericAttributeService.GetAttribute<int>(SystemCustomerAttributeNames.StateProvinceId); model.PhoneNumber = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.PhoneAttribute); model.FaxNumber = _genericAttributeService.GetAttribute <string>(customer, NopCustomerDefaults.FaxAttribute); } //countries and states if (addressSettings.CountryEnabled && loadCountries != null) { var countries = loadCountries(); if (_addressSettings.PreselectCountryIfOnlyOne && countries.Count == 1) { model.CountryId = countries[0].Id; } else { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectCountry"), Value = "0" }); } foreach (var c in countries) { model.AvailableCountries.Add(new SelectListItem { Text = _localizationService.GetLocalized(c, x => x.Name), Value = c.Id.ToString(), Selected = c.Id == model.CountryId }); } if (addressSettings.StateProvinceEnabled) { var languageId = EngineContext.Current.Resolve <IWorkContext>().WorkingLanguage.Id; var states = _stateProvinceService .GetStateProvincesByCountryId(model.CountryId.HasValue ? model.CountryId.Value : 0, languageId) .ToList(); if (states.Any()) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource("Address.SelectState"), Value = "0" }); foreach (var s in states) { model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetLocalized(s, x => x.Name), Value = s.Id.ToString(), Selected = (s.Id == model.StateProvinceId) }); } } else { var anyCountrySelected = model.AvailableCountries.Any(x => x.Selected); model.AvailableStates.Add(new SelectListItem { Text = _localizationService.GetResource(anyCountrySelected ? "Address.OtherNonUS" : "Address.SelectState"), Value = "0" }); } } } //form fields model.CompanyEnabled = addressSettings.CompanyEnabled; model.CompanyRequired = addressSettings.CompanyRequired; model.StreetAddressEnabled = addressSettings.StreetAddressEnabled; model.StreetAddressRequired = addressSettings.StreetAddressRequired; model.StreetAddress2Enabled = addressSettings.StreetAddress2Enabled; model.StreetAddress2Required = addressSettings.StreetAddress2Required; model.ZipPostalCodeEnabled = addressSettings.ZipPostalCodeEnabled; model.ZipPostalCodeRequired = addressSettings.ZipPostalCodeRequired; model.CityEnabled = addressSettings.CityEnabled; model.CityRequired = addressSettings.CityRequired; model.CountyEnabled = addressSettings.CountyEnabled; model.CountyRequired = addressSettings.CountyRequired; model.CountryEnabled = addressSettings.CountryEnabled; model.StateProvinceEnabled = addressSettings.StateProvinceEnabled; model.PhoneEnabled = addressSettings.PhoneEnabled; model.PhoneRequired = addressSettings.PhoneRequired; model.FaxEnabled = addressSettings.FaxEnabled; model.FaxRequired = addressSettings.FaxRequired; //customer attribute services if (_addressAttributeService != null && _addressAttributeParser != null) { PrepareCustomAddressAttributes(model, address, overrideAttributesXml); } if (_addressAttributeFormatter != null && address != null) { model.FormattedCustomAddressAttributes = _addressAttributeFormatter.FormatAttributes(address.CustomAttributes); } }
/// <summary> /// Print packaging slips to PDF /// </summary> /// <param name="stream">Stream</param> /// <param name="shipments">Shipments</param> /// <param name="languageId">Language identifier; 0 to use a language used when placing an order</param> public virtual void PrintPackagingSlipsToPdf(Stream stream, IList <Shipment> shipments, int languageId = 0) { if (stream == null) { throw new ArgumentNullException("stream"); } if (shipments == null) { throw new ArgumentNullException("shipments"); } var lang = _languageService.GetLanguageById(languageId); if (lang == null) { throw new ArgumentException(string.Format("Cannot load language. ID={0}", languageId)); } var pageSize = PageSize.A4; if (_pdfSettings.LetterPageSizeEnabled) { pageSize = PageSize.LETTER; } var doc = new Document(pageSize); PdfWriter.GetInstance(doc, stream); doc.Open(); //fonts var titleFont = GetFont(); titleFont.SetStyle(Font.BOLD); titleFont.Color = BaseColor.BLACK; var font = GetFont(); var attributesFont = GetFont(); attributesFont.SetStyle(Font.ITALIC); int shipmentCount = shipments.Count; int shipmentNum = 0; foreach (var shipment in shipments) { var order = shipment.Order; if (languageId == 0) { lang = _languageService.GetLanguageById(order.CustomerLanguageId); if (lang == null || !lang.Published) { lang = _workContext.WorkingLanguage; } } var addressTable = new PdfPTable(1); if (lang.Rtl) { addressTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } addressTable.DefaultCell.Border = Rectangle.NO_BORDER; addressTable.WidthPercentage = 100f; addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Shipment", lang.Id), shipment.Id), titleFont)); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Order", lang.Id), order.Id), titleFont)); if (!order.PickUpInStore) { if (order.ShippingAddress == null) { throw new NopException(string.Format("Shipping is required, but address is not available. Order ID = {0}", order.Id)); } if (_addressSettings.CompanyEnabled && !String.IsNullOrEmpty(order.ShippingAddress.Company)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Company", lang.Id), order.ShippingAddress.Company), font)); } addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Name", lang.Id), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName), font)); if (_addressSettings.PhoneEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Phone", lang.Id), order.ShippingAddress.PhoneNumber), font)); } if (_addressSettings.StreetAddressEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address", lang.Id), order.ShippingAddress.Address1), font)); } if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.ShippingAddress.Address2)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address2", lang.Id), order.ShippingAddress.Address2), font)); } if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled) { addressTable.AddCell(new Paragraph(String.Format("{0}, {1} {2}", order.ShippingAddress.City, order.ShippingAddress.StateProvince != null ? order.ShippingAddress.StateProvince.GetLocalized(x => x.Name, lang.Id) : "", order.ShippingAddress.ZipPostalCode), font)); } if (_addressSettings.CountryEnabled && order.ShippingAddress.Country != null) { addressTable.AddCell(new Paragraph(String.Format("{0}", order.ShippingAddress.Country != null ? order.ShippingAddress.Country.GetLocalized(x => x.Name, lang.Id) : ""), font)); } //custom attributes var customShippingAddressAttributes = _addressAttributeFormatter.FormatAttributes(order.ShippingAddress.CustomAttributes); if (!String.IsNullOrEmpty(customShippingAddressAttributes)) { addressTable.AddCell(new Paragraph(HtmlHelper.ConvertHtmlToPlainText(customShippingAddressAttributes, true, true), font)); } } addressTable.AddCell(new Paragraph(" ")); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.ShippingMethod", lang.Id), order.ShippingMethod), font)); addressTable.AddCell(new Paragraph(" ")); doc.Add(addressTable); var productsTable = new PdfPTable(3); productsTable.WidthPercentage = 100f; if (lang.Rtl) { productsTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; productsTable.SetWidths(new[] { 20, 20, 60 }); } else { productsTable.SetWidths(new[] { 60, 20, 20 }); } //product name var cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.ProductName", lang.Id), font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //SKU cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.SKU", lang.Id), font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //qty cell = new PdfPCell(new Phrase(_localizationService.GetResource("PDFPackagingSlip.QTY", lang.Id), font)); cell.BackgroundColor = BaseColor.LIGHT_GRAY; cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); foreach (var si in shipment.ShipmentItems) { var productAttribTable = new PdfPTable(1); if (lang.Rtl) { productAttribTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } productAttribTable.DefaultCell.Border = Rectangle.NO_BORDER; //product name var orderItem = _orderService.GetOrderItemById(si.OrderItemId); if (orderItem == null) { continue; } var p = orderItem.Product; string name = p.GetLocalized(x => x.Name, lang.Id); productAttribTable.AddCell(new Paragraph(name, font)); //attributes if (!String.IsNullOrEmpty(orderItem.AttributeDescription)) { var attributesParagraph = new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderItem.AttributeDescription, true, true), attributesFont); productAttribTable.AddCell(attributesParagraph); } //rental info if (orderItem.Product.IsRental) { var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalStartDateUtc.Value) : ""; var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalEndDateUtc.Value) : ""; var rentalInfo = string.Format(_localizationService.GetResource("Order.Rental.FormattedDate"), rentalStartDate, rentalEndDate); var rentalInfoParagraph = new Paragraph(rentalInfo, attributesFont); productAttribTable.AddCell(rentalInfoParagraph); } productsTable.AddCell(productAttribTable); //SKU var sku = p.FormatSku(orderItem.AttributesXml, _productAttributeParser); cell = new PdfPCell(new Phrase(sku ?? String.Empty, font)); cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); //qty cell = new PdfPCell(new Phrase(si.Quantity.ToString(), font)); cell.HorizontalAlignment = Element.ALIGN_CENTER; productsTable.AddCell(cell); } doc.Add(productsTable); shipmentNum++; if (shipmentNum < shipmentCount) { doc.NewPage(); } } doc.Close(); }
/// <summary> /// Prepare HTML string address /// </summary> /// <param name="model">Address model</param> /// <param name="address">Address</param> protected virtual void PrepareModelAddressHtml(AddressModel model, Address address) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var addressHtmlSb = new StringBuilder("<div>"); if (_addressSettings.CompanyEnabled && !string.IsNullOrEmpty(model.Company)) { addressHtmlSb.AppendFormat("{0}<br />", WebUtility.HtmlEncode(model.Company)); } if (_addressSettings.StreetAddressEnabled && !string.IsNullOrEmpty(model.Address1)) { addressHtmlSb.AppendFormat("{0}<br />", WebUtility.HtmlEncode(model.Address1)); } if (_addressSettings.StreetAddress2Enabled && !string.IsNullOrEmpty(model.Address2)) { addressHtmlSb.AppendFormat("{0}<br />", WebUtility.HtmlEncode(model.Address2)); } if (_addressSettings.CityEnabled && !string.IsNullOrEmpty(model.City)) { addressHtmlSb.AppendFormat("{0},", WebUtility.HtmlEncode(model.City)); } if (_addressSettings.CountyEnabled && !string.IsNullOrEmpty(model.County)) { addressHtmlSb.AppendFormat("{0},", WebUtility.HtmlEncode(model.County)); } if (_addressSettings.StateProvinceEnabled && !string.IsNullOrEmpty(model.StateProvinceName)) { addressHtmlSb.AppendFormat("{0},", WebUtility.HtmlEncode(model.StateProvinceName)); } if (_addressSettings.ZipPostalCodeEnabled && !string.IsNullOrEmpty(model.ZipPostalCode)) { addressHtmlSb.AppendFormat("{0}<br />", WebUtility.HtmlEncode(model.ZipPostalCode)); } if (_addressSettings.CountryEnabled && !string.IsNullOrEmpty(model.CountryName)) { addressHtmlSb.AppendFormat("{0}", WebUtility.HtmlEncode(model.CountryName)); } var customAttributesFormatted = _addressAttributeFormatter.FormatAttributes(address?.CustomAttributes); if (!string.IsNullOrEmpty(customAttributesFormatted)) { //already encoded addressHtmlSb.AppendFormat("<br />{0}", customAttributesFormatted); } addressHtmlSb.Append("</div>"); model.AddressHtml = addressHtmlSb.ToString(); }
public async Task AddOrderTokens(LiquidObject liquidObject, Order order, Customer customer, Store store, OrderNote orderNote = null, string vendorId = "", decimal refundedAmount = 0) { var language = await _languageService.GetLanguageById(order.CustomerLanguageId); var currency = await _currencyService.GetCurrencyByCode(order.CustomerCurrencyCode); var productService = _serviceProvider.GetRequiredService <IProductService>(); var downloadService = _serviceProvider.GetRequiredService <IDownloadService>(); var liquidOrder = new LiquidOrder(order, customer, language, currency, store, orderNote, vendorId); foreach (var item in order.OrderItems) { var product = await productService.GetProductById(item.ProductId); var liqitem = new LiquidOrderItem(item, product, order, language, currency, store); #region Download liqitem.IsDownloadAllowed = await downloadService.IsDownloadAllowed(item); liqitem.IsLicenseDownloadAllowed = await downloadService.IsLicenseDownloadAllowed(item); #endregion #region Unit price string unitPriceStr; if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax var unitPriceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.UnitPriceInclTax, order.CurrencyRate); unitPriceStr = _priceFormatter.FormatPrice(unitPriceInclTaxInCustomerCurrency, true, currency, language, true); } else { //excluding tax var unitPriceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.UnitPriceExclTax, order.CurrencyRate); unitPriceStr = _priceFormatter.FormatPrice(unitPriceExclTaxInCustomerCurrency, true, currency, language, false); } liqitem.UnitPrice = unitPriceStr; #endregion #region total price string priceStr; if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax var priceInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.PriceInclTax, order.CurrencyRate); priceStr = _priceFormatter.FormatPrice(priceInclTaxInCustomerCurrency, true, currency, language, true); } else { //excluding tax var priceExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(item.PriceExclTax, order.CurrencyRate); priceStr = _priceFormatter.FormatPrice(priceExclTaxInCustomerCurrency, true, currency, language, false); } liqitem.TotalPrice = priceStr; #endregion string sku = ""; if (product != null) { sku = product.FormatSku(item.AttributesXml, _productAttributeParser); } liqitem.ProductSku = WebUtility.HtmlEncode(sku); liqitem.ShowSkuOnProductDetailsPage = _catalogSettings.ShowSkuOnProductDetailsPage; liqitem.ProductOldPrice = _priceFormatter.FormatPrice(product.OldPrice, true, currency, language, true); liquidOrder.OrderItems.Add(liqitem); } liquidOrder.BillingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(order.BillingAddress?.CustomAttributes); liquidOrder.BillingCountry = order.BillingAddress != null && !string.IsNullOrEmpty(order.BillingAddress.CountryId) ? (await _countryService.GetCountryById(order.BillingAddress.CountryId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : ""; liquidOrder.BillingStateProvince = !string.IsNullOrEmpty(order.BillingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(order.BillingAddress.StateProvinceId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : ""; liquidOrder.ShippingCountry = order.ShippingAddress != null && !string.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _countryService.GetCountryById(order.ShippingAddress.CountryId))?.GetLocalized(x => x.Name, order.CustomerLanguageId) : ""; liquidOrder.ShippingStateProvince = order.ShippingAddress != null && !string.IsNullOrEmpty(order.ShippingAddress.StateProvinceId) ? (await _stateProvinceService.GetStateProvinceById(order.ShippingAddress.StateProvinceId)).GetLocalized(x => x.Name, order.CustomerLanguageId) : ""; liquidOrder.ShippingCustomAttributes = await _addressAttributeFormatter.FormatAttributes(order.ShippingAddress != null?order.ShippingAddress.CustomAttributes : ""); var paymentMethod = _serviceProvider.GetRequiredService <IPaymentService>().LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); liquidOrder.PaymentMethod = paymentMethod != null?paymentMethod.GetLocalizedFriendlyName(_localizationService, language.Id) : order.PaymentMethodSystemName; liquidOrder.AmountRefunded = _priceFormatter.FormatPrice(refundedAmount, true, currency, language, false); Dictionary <string, string> dict = new Dictionary <string, string>(); foreach (var item in order.TaxRatesDictionary) { string taxRate = string.Format(_localizationService.GetResource("Messages.Order.TaxRateLine"), _priceFormatter.FormatTaxRate(item.Key)); string taxValue = _priceFormatter.FormatPrice(item.Value, true, currency, language, false); dict.Add(taxRate, taxValue); } liquidOrder.TaxRates = dict; Dictionary <string, string> cards = new Dictionary <string, string>(); var servicegiftCard = _serviceProvider.GetRequiredService <IGiftCardService>(); var gcuhC = await servicegiftCard.GetAllGiftCardUsageHistory(order.Id); foreach (var gcuh in gcuhC) { var giftCard = await servicegiftCard.GetGiftCardById(gcuh.GiftCardId); string giftCardText = string.Format(_localizationService.GetResource("Messages.Order.GiftCardInfo", language.Id), WebUtility.HtmlEncode(giftCard.GiftCardCouponCode)); string giftCardAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(gcuh.UsedValue, order.CurrencyRate)), true, currency, language, false); cards.Add(giftCardText, giftCardAmount); } liquidOrder.GiftCards = cards; if (order.RedeemedRewardPointsEntry != null) { liquidOrder.RPTitle = string.Format(_localizationService.GetResource("Messages.Order.RewardPoints", language.Id), -order.RedeemedRewardPointsEntry?.Points); liquidOrder.RPAmount = _priceFormatter.FormatPrice(-(_currencyService.ConvertCurrency(order.RedeemedRewardPointsEntry.UsedAmount, order.CurrencyRate)), true, currency, language, false); } void CalculateSubTotals() { string _cusSubTotal; bool _displaySubTotalDiscount; string _cusSubTotalDiscount; string _cusShipTotal; string _cusPaymentMethodAdditionalFee; bool _displayTax; string _cusTaxTotal; bool _displayTaxRates; bool _displayDiscount; string _cusDiscount; string _cusTotal; _displaySubTotalDiscount = false; _cusSubTotalDiscount = string.Empty; if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax && !_taxSettings.ForceTaxExclusionFromOrderSubtotal) { //including tax //subtotal var orderSubtotalInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalInclTax, order.CurrencyRate); _cusSubTotal = _priceFormatter.FormatPrice(orderSubtotalInclTaxInCustomerCurrency, true, currency, language, true); //discount (applied to order subtotal) var orderSubTotalDiscountInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountInclTax, order.CurrencyRate); if (orderSubTotalDiscountInclTaxInCustomerCurrency > decimal.Zero) { _cusSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountInclTaxInCustomerCurrency, true, currency, language, true); _displaySubTotalDiscount = true; } } else { //exсluding tax //subtotal var orderSubtotalExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubtotalExclTax, order.CurrencyRate); _cusSubTotal = _priceFormatter.FormatPrice(orderSubtotalExclTaxInCustomerCurrency, true, currency, language, false); //discount (applied to order subtotal) var orderSubTotalDiscountExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderSubTotalDiscountExclTax, order.CurrencyRate); if (orderSubTotalDiscountExclTaxInCustomerCurrency > decimal.Zero) { _cusSubTotalDiscount = _priceFormatter.FormatPrice(-orderSubTotalDiscountExclTaxInCustomerCurrency, true, currency, language, false); _displaySubTotalDiscount = true; } } //shipping, payment method fee _cusTaxTotal = string.Empty; _cusDiscount = string.Empty; if (order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax) { //including tax //shipping var orderShippingInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingInclTax, order.CurrencyRate); _cusShipTotal = _priceFormatter.FormatShippingPrice(orderShippingInclTaxInCustomerCurrency, true, currency, language, true); //payment method additional fee var paymentMethodAdditionalFeeInclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeInclTax, order.CurrencyRate); _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeInclTaxInCustomerCurrency, true, currency, language, true); } else { //excluding tax //shipping var orderShippingExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderShippingExclTax, order.CurrencyRate); _cusShipTotal = _priceFormatter.FormatShippingPrice(orderShippingExclTaxInCustomerCurrency, true, currency, language, false); //payment method additional fee var paymentMethodAdditionalFeeExclTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.PaymentMethodAdditionalFeeExclTax, order.CurrencyRate); _cusPaymentMethodAdditionalFee = _priceFormatter.FormatPaymentMethodAdditionalFee(paymentMethodAdditionalFeeExclTaxInCustomerCurrency, true, currency, language, false); } //shipping bool displayShipping = order.ShippingStatus != ShippingStatus.ShippingNotRequired; //payment method fee bool displayPaymentMethodFee = order.PaymentMethodAdditionalFeeExclTax > decimal.Zero; //tax _displayTax = true; _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 = new SortedDictionary <decimal, decimal>(); foreach (var tr in order.TaxRatesDictionary) { _taxRates.Add(tr.Key, _currencyService.ConvertCurrency(tr.Value, order.CurrencyRate)); } _displayTaxRates = _taxSettings.DisplayTaxRates && _taxRates.Any(); _displayTax = !_displayTaxRates; var orderTaxInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTax, order.CurrencyRate); string taxStr = _priceFormatter.FormatPrice(orderTaxInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); _cusTaxTotal = taxStr; } } //discount _displayDiscount = false; if (order.OrderDiscount > decimal.Zero) { var orderDiscountInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderDiscount, order.CurrencyRate); _cusDiscount = _priceFormatter.FormatPrice(-orderDiscountInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); _displayDiscount = true; } //total var orderTotalInCustomerCurrency = _currencyService.ConvertCurrency(order.OrderTotal, order.CurrencyRate); _cusTotal = _priceFormatter.FormatPrice(orderTotalInCustomerCurrency, true, currency, language, order.CustomerTaxDisplayType == TaxDisplayType.IncludingTax, false); liquidOrder.SubTotal = _cusSubTotal; liquidOrder.DisplaySubTotalDiscount = _displaySubTotalDiscount; liquidOrder.SubTotalDiscount = _cusSubTotalDiscount; liquidOrder.Shipping = _cusShipTotal; liquidOrder.Tax = _cusTaxTotal; liquidOrder.Total = _cusTotal; liquidOrder.DisplayDiscount = _displayDiscount; liquidOrder.DisplayTaxRates = _displayTaxRates; } CalculateSubTotals(); liquidObject.Order = liquidOrder; await _mediator.EntityTokensAdded(order, liquidOrder, liquidObject); }
protected virtual void PrepareOrderDetailsModel(OrderModel model, Nop.Core.Domain.Orders.Order order) { if (order == null) throw new ArgumentNullException("order"); if (model == null) throw new ArgumentNullException("model"); model.Id = order.Id; model.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext); model.OrderStatusId = order.OrderStatusId; model.OrderGuid = order.OrderGuid; model.CustomOrderNumber = order.CustomOrderNumber; var store = _storeService.GetStoreById(order.StoreId); model.StoreName = store != null ? store.Name : "Unknown"; model.CustomerId = order.CustomerId; var customer = order.Customer; model.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); model.CustomerIp = order.CustomerIp; model.VatNumber = order.VatNumber; model.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc); model.AllowCustomersToSelectTaxDisplayType = _taxSettings.AllowCustomersToSelectTaxDisplayType; model.TaxDisplayType = _taxSettings.TaxDisplayType; var affiliate = _affiliateService.GetAffiliateById(order.AffiliateId); if (affiliate != null) { model.AffiliateId = affiliate.Id; model.AffiliateName = affiliate.GetFullName(); } //a vendor should have access only to his products model.IsLoggedInAsVendor = _workContext.CurrentVendor != null; //custom values model.CustomValues = order.DeserializeCustomValues(); #region Order totals var primaryStoreCurrency = _currencyService.GetCurrencyById(_currencySettings.PrimaryStoreCurrencyId); if (primaryStoreCurrency == null) throw new Exception("Cannot load primary store currency"); //subtotal model.OrderSubtotalInclTax = _priceFormatter.FormatPrice(order.OrderSubtotalInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.OrderSubtotalExclTax = _priceFormatter.FormatPrice(order.OrderSubtotalExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); model.OrderSubtotalInclTaxValue = order.OrderSubtotalInclTax; model.OrderSubtotalExclTaxValue = order.OrderSubtotalExclTax; //discount (applied to order subtotal) string orderSubtotalDiscountInclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); string orderSubtotalDiscountExclTaxStr = _priceFormatter.FormatPrice(order.OrderSubTotalDiscountExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); if (order.OrderSubTotalDiscountInclTax > decimal.Zero) model.OrderSubTotalDiscountInclTax = orderSubtotalDiscountInclTaxStr; if (order.OrderSubTotalDiscountExclTax > decimal.Zero) model.OrderSubTotalDiscountExclTax = orderSubtotalDiscountExclTaxStr; model.OrderSubTotalDiscountInclTaxValue = order.OrderSubTotalDiscountInclTax; model.OrderSubTotalDiscountExclTaxValue = order.OrderSubTotalDiscountExclTax; //shipping model.OrderShippingInclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.OrderShippingExclTax = _priceFormatter.FormatShippingPrice(order.OrderShippingExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); model.OrderShippingInclTaxValue = order.OrderShippingInclTax; model.OrderShippingExclTaxValue = order.OrderShippingExclTax; //payment method additional fee if (order.PaymentMethodAdditionalFeeInclTax > decimal.Zero) { model.PaymentMethodAdditionalFeeInclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true); model.PaymentMethodAdditionalFeeExclTax = _priceFormatter.FormatPaymentMethodAdditionalFee(order.PaymentMethodAdditionalFeeExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false); } model.PaymentMethodAdditionalFeeInclTaxValue = order.PaymentMethodAdditionalFeeInclTax; model.PaymentMethodAdditionalFeeExclTaxValue = order.PaymentMethodAdditionalFeeExclTax; //tax model.Tax = _priceFormatter.FormatPrice(order.OrderTax, true, false); SortedDictionary<decimal, decimal> taxRates = order.TaxRatesDictionary; bool displayTaxRates = _taxSettings.DisplayTaxRates && taxRates.Any(); bool displayTax = !displayTaxRates; foreach (var tr in order.TaxRatesDictionary) { model.TaxRates.Add(new OrderModel.TaxRate { Rate = _priceFormatter.FormatTaxRate(tr.Key), Value = _priceFormatter.FormatPrice(tr.Value, true, false), }); } model.DisplayTaxRates = displayTaxRates; model.DisplayTax = displayTax; model.TaxValue = order.OrderTax; model.TaxRatesValue = order.TaxRates; //discount if (order.OrderDiscount > 0) model.OrderTotalDiscount = _priceFormatter.FormatPrice(-order.OrderDiscount, true, false); model.OrderTotalDiscountValue = order.OrderDiscount; //gift cards foreach (var gcuh in order.GiftCardUsageHistory) { model.GiftCards.Add(new OrderModel.GiftCard { CouponCode = gcuh.GiftCard.GiftCardCouponCode, Amount = _priceFormatter.FormatPrice(-gcuh.UsedValue, true, false), }); } //reward points if (order.RedeemedRewardPointsEntry != null) { model.RedeemedRewardPoints = -order.RedeemedRewardPointsEntry.Points; model.RedeemedRewardPointsAmount = _priceFormatter.FormatPrice(-order.RedeemedRewardPointsEntry.UsedAmount, true, false); } //total model.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false); model.OrderTotalValue = order.OrderTotal; //refunded amount if (order.RefundedAmount > decimal.Zero) model.RefundedAmount = _priceFormatter.FormatPrice(order.RefundedAmount, true, false); //used discounts var duh = _discountService.GetAllDiscountUsageHistory(orderId: order.Id); foreach (var d in duh) { model.UsedDiscounts.Add(new OrderModel.UsedDiscountModel { DiscountId = d.DiscountId, DiscountName = d.Discount.Name }); } //profit (hide for vendors) if (_workContext.CurrentVendor == null) { var profit = _orderReportService.ProfitReport(orderId: order.Id); model.Profit = _priceFormatter.FormatPrice(profit, true, false); } #endregion #region Payment info //payment method info var pm = _paymentService.LoadPaymentMethodBySystemName(order.PaymentMethodSystemName); model.PaymentMethod = pm != null ? pm.PluginDescriptor.FriendlyName : order.PaymentMethodSystemName; model.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext); #endregion #region Billing & shipping info model.BillingAddress = order.BillingAddress.ToModel(); model.BillingAddress.FormattedCustomAddressAttributes = _addressAttributeFormatter.FormatAttributes(order.BillingAddress.CustomAttributes); model.BillingAddress.FirstNameEnabled = true; model.BillingAddress.FirstNameRequired = true; model.BillingAddress.LastNameEnabled = true; model.BillingAddress.LastNameRequired = true; model.BillingAddress.EmailEnabled = true; model.BillingAddress.EmailRequired = true; model.BillingAddress.CompanyEnabled = _addressSettings.CompanyEnabled; model.BillingAddress.CompanyRequired = _addressSettings.CompanyRequired; model.BillingAddress.CountryEnabled = _addressSettings.CountryEnabled; model.BillingAddress.CountryRequired = _addressSettings.CountryEnabled; //country is required when enabled model.BillingAddress.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.BillingAddress.CityEnabled = _addressSettings.CityEnabled; model.BillingAddress.CityRequired = _addressSettings.CityRequired; model.BillingAddress.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.BillingAddress.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.BillingAddress.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.BillingAddress.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.BillingAddress.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.BillingAddress.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.BillingAddress.PhoneEnabled = _addressSettings.PhoneEnabled; model.BillingAddress.PhoneRequired = _addressSettings.PhoneRequired; model.BillingAddress.FaxEnabled = _addressSettings.FaxEnabled; model.BillingAddress.FaxRequired = _addressSettings.FaxRequired; model.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext); ; if (order.ShippingStatus != ShippingStatus.ShippingNotRequired) { model.IsShippable = true; model.PickUpInStore = order.PickUpInStore; if (!order.PickUpInStore) { model.ShippingAddress = order.ShippingAddress.ToModel(); model.ShippingAddress.FormattedCustomAddressAttributes = _addressAttributeFormatter.FormatAttributes(order.ShippingAddress.CustomAttributes); model.ShippingAddress.FirstNameEnabled = true; model.ShippingAddress.FirstNameRequired = true; model.ShippingAddress.LastNameEnabled = true; model.ShippingAddress.LastNameRequired = true; model.ShippingAddress.EmailEnabled = true; model.ShippingAddress.EmailRequired = true; model.ShippingAddress.CompanyEnabled = _addressSettings.CompanyEnabled; model.ShippingAddress.CompanyRequired = _addressSettings.CompanyRequired; model.ShippingAddress.CountryEnabled = _addressSettings.CountryEnabled; model.ShippingAddress.CountryRequired = _addressSettings.CountryEnabled; //country is required when enabled model.ShippingAddress.StateProvinceEnabled = _addressSettings.StateProvinceEnabled; model.ShippingAddress.CityEnabled = _addressSettings.CityEnabled; model.ShippingAddress.CityRequired = _addressSettings.CityRequired; model.ShippingAddress.StreetAddressEnabled = _addressSettings.StreetAddressEnabled; model.ShippingAddress.StreetAddressRequired = _addressSettings.StreetAddressRequired; model.ShippingAddress.StreetAddress2Enabled = _addressSettings.StreetAddress2Enabled; model.ShippingAddress.StreetAddress2Required = _addressSettings.StreetAddress2Required; model.ShippingAddress.ZipPostalCodeEnabled = _addressSettings.ZipPostalCodeEnabled; model.ShippingAddress.ZipPostalCodeRequired = _addressSettings.ZipPostalCodeRequired; model.ShippingAddress.PhoneEnabled = _addressSettings.PhoneEnabled; model.ShippingAddress.PhoneRequired = _addressSettings.PhoneRequired; model.ShippingAddress.FaxEnabled = _addressSettings.FaxEnabled; model.ShippingAddress.FaxRequired = _addressSettings.FaxRequired; model.ShippingAddressGoogleMapsUrl = string.Format("http://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q={0}", Server.UrlEncode(order.ShippingAddress.Address1 + " " + order.ShippingAddress.ZipPostalCode + " " + order.ShippingAddress.City + " " + (order.ShippingAddress.Country != null ? order.ShippingAddress.Country.Name : ""))); } else { if (order.PickupAddress != null) { model.PickupAddress = order.PickupAddress.ToModel(); model.PickupAddressGoogleMapsUrl = string.Format("http://maps.google.com/maps?f=q&hl=en&ie=UTF8&oe=UTF8&geocode=&q={0}", Server.UrlEncode(string.Format("{0} {1} {2} {3}", order.PickupAddress.Address1, order.PickupAddress.ZipPostalCode, order.PickupAddress.City, order.PickupAddress.Country != null ? order.PickupAddress.Country.Name : string.Empty))); } } model.ShippingMethod = order.ShippingMethod; } #endregion #region Products model.CheckoutAttributeInfo = order.CheckoutAttributeDescription; bool hasDownloadableItems = false; var products = order.OrderItems; //a vendor should have access only to his products if (_workContext.CurrentVendor != null) { products = products .Where(orderItem => orderItem.Product.VendorId == _workContext.CurrentVendor.Id) .ToList(); } foreach (var orderItem in products) { if (orderItem.Product.IsDownload) hasDownloadableItems = true; var orderItemModel = new OrderModel.OrderItemModel { Id = orderItem.Id, ProductId = orderItem.ProductId, ProductName = orderItem.Product.Name, Sku = orderItem.Product.FormatSku(orderItem.AttributesXml, _productAttributeParser), Quantity = orderItem.Quantity, IsDownload = orderItem.Product.IsDownload, DownloadCount = orderItem.DownloadCount, DownloadActivationType = orderItem.Product.DownloadActivationType, IsDownloadActivated = orderItem.IsDownloadActivated }; //vendor var vendor = _vendorService.GetVendorById(orderItem.Product.VendorId); orderItemModel.VendorName = vendor != null ? vendor.Name : ""; //unit price orderItemModel.UnitPriceInclTaxValue = orderItem.UnitPriceInclTax; orderItemModel.UnitPriceExclTaxValue = orderItem.UnitPriceExclTax; orderItemModel.UnitPriceInclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.UnitPriceExclTax = _priceFormatter.FormatPrice(orderItem.UnitPriceExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); //discounts orderItemModel.DiscountInclTaxValue = orderItem.DiscountAmountInclTax; orderItemModel.DiscountExclTaxValue = orderItem.DiscountAmountExclTax; orderItemModel.DiscountInclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.DiscountExclTax = _priceFormatter.FormatPrice(orderItem.DiscountAmountExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); //subtotal orderItemModel.SubTotalInclTaxValue = orderItem.PriceInclTax; orderItemModel.SubTotalExclTaxValue = orderItem.PriceExclTax; orderItemModel.SubTotalInclTax = _priceFormatter.FormatPrice(orderItem.PriceInclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, true, true); orderItemModel.SubTotalExclTax = _priceFormatter.FormatPrice(orderItem.PriceExclTax, true, primaryStoreCurrency, _workContext.WorkingLanguage, false, true); orderItemModel.AttributeInfo = orderItem.AttributeDescription; if (orderItem.Product.IsRecurring) orderItemModel.RecurringInfo = string.Format(_localizationService.GetResource("Admin.Orders.Products.RecurringPeriod"), orderItem.Product.RecurringCycleLength, orderItem.Product.RecurringCyclePeriod.GetLocalizedEnum(_localizationService, _workContext)); //rental info if (orderItem.Product.IsRental) { var rentalStartDate = orderItem.RentalStartDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalStartDateUtc.Value) : ""; var rentalEndDate = orderItem.RentalEndDateUtc.HasValue ? orderItem.Product.FormatRentalDate(orderItem.RentalEndDateUtc.Value) : ""; orderItemModel.RentalInfo = string.Format(_localizationService.GetResource("Order.Rental.FormattedDate"), rentalStartDate, rentalEndDate); } model.Items.Add(orderItemModel); } model.HasDownloadableProducts = hasDownloadableItems; #endregion }
protected virtual async Task <PdfPTable> PreparePackagingSlipsAddress(Order order, Shipment shipment, Language language) { var font = PdfExtensions.GetFont(_pdfSettings.FontFileName); var titleFont = PdfExtensions.PrepareTitleFont(_pdfSettings.FontFileName); var addressTable = new PdfPTable(1); if (language.Rtl) { addressTable.RunDirection = PdfWriter.RUN_DIRECTION_RTL; } addressTable.DefaultCell.Border = Rectangle.NO_BORDER; addressTable.WidthPercentage = 100f; addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Shipment", language.Id), shipment.ShipmentNumber), titleFont)); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Order", language.Id), order.OrderNumber), titleFont)); if (!order.PickUpInStore) { if (order.ShippingAddress == null) { throw new GrandException(string.Format("Shipping is required, but address is not available. Order ID = {0}", order.Id)); } if (_addressSettings.CompanyEnabled && !String.IsNullOrEmpty(order.ShippingAddress.Company)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Company", language.Id), order.ShippingAddress.Company), font)); } addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Name", language.Id), order.ShippingAddress.FirstName + " " + order.ShippingAddress.LastName), font)); if (_addressSettings.PhoneEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Phone", language.Id), order.ShippingAddress.PhoneNumber), font)); } if (_addressSettings.StreetAddressEnabled) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address", language.Id), order.ShippingAddress.Address1), font)); } if (_addressSettings.StreetAddress2Enabled && !String.IsNullOrEmpty(order.ShippingAddress.Address2)) { addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.Address2", language.Id), order.ShippingAddress.Address2), font)); } if (_addressSettings.CityEnabled || _addressSettings.StateProvinceEnabled || _addressSettings.ZipPostalCodeEnabled) { addressTable.AddCell(new Paragraph(String.Format("{0}, {1} {2}", order.ShippingAddress.City, !String.IsNullOrEmpty(order.ShippingAddress.StateProvinceId) ? (await _serviceProvider.GetRequiredService <IStateProvinceService>().GetStateProvinceById(order.ShippingAddress.StateProvinceId)).GetLocalized(x => x.Name, language.Id) : "", order.ShippingAddress.ZipPostalCode), font)); } if (_addressSettings.CountryEnabled && !String.IsNullOrEmpty(order.ShippingAddress.CountryId)) { addressTable.AddCell(new Paragraph(String.Format("{0}", !String.IsNullOrEmpty(order.ShippingAddress.CountryId) ? (await _serviceProvider.GetRequiredService <ICountryService>().GetCountryById(order.ShippingAddress.CountryId)).GetLocalized(x => x.Name, language.Id) : ""), font)); } //custom attributes var customShippingAddressAttributes = await _addressAttributeFormatter.FormatAttributes(order.ShippingAddress.CustomAttributes); if (!String.IsNullOrEmpty(customShippingAddressAttributes)) { addressTable.AddCell(new Paragraph(HtmlHelper.ConvertHtmlToPlainText(customShippingAddressAttributes, true, true), font)); } } else if (order.PickupPoint != null) { if (order.PickupPoint.Address != null) { addressTable.AddCell(new Paragraph(_localizationService.GetResource("PDFInvoice.Pickup", language.Id), titleFont)); if (!string.IsNullOrEmpty(order.PickupPoint.Address.Address1)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", string.Format(_localizationService.GetResource("PDFInvoice.Address", language.Id), order.PickupPoint.Address.Address1)), font)); } if (!string.IsNullOrEmpty(order.PickupPoint.Address.City)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", order.PickupPoint.Address.City), font)); } if (!string.IsNullOrEmpty(order.PickupPoint.Address.CountryId)) { var country = await _serviceProvider.GetRequiredService <ICountryService>().GetCountryById(order.PickupPoint.Address.CountryId); if (country != null) { addressTable.AddCell(new Paragraph(string.Format(" {0}", country.Name), font)); } } if (!string.IsNullOrEmpty(order.PickupPoint.Address.ZipPostalCode)) { addressTable.AddCell(new Paragraph(string.Format(" {0}", order.PickupPoint.Address.ZipPostalCode), font)); } addressTable.AddCell(new Paragraph(" ")); } } addressTable.AddCell(new Paragraph(" ")); addressTable.AddCell(new Paragraph(String.Format(_localizationService.GetResource("PDFPackagingSlip.ShippingMethod", language.Id), order.ShippingMethod), font)); addressTable.AddCell(new Paragraph(" ")); return(addressTable); }
/// <summary> /// Formats attributes /// </summary> /// <param name="attributesXml">Attributes in XML format</param> /// <param name="serapator">Serapator</param> /// <param name="htmlEncode">A value indicating whether to encode (HTML) values</param> /// <returns>Attributes</returns> public string FormatAttributes(string attributesXml, string serapator = "<br />", bool htmlEncode = true) { return(_addressAttributeFormatter.FormatAttributes(attributesXml, serapator, htmlEncode)); }