-
No results found.
Try your search with a different keyword or use * as a wildcard.
ExportManager.cs
using System.Globalization;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Xml;
using ClosedXML.Excel;
using Nop.Core;
using Nop.Core.Domain.Catalog;
using Nop.Core.Domain.Common;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Directory;
using Nop.Core.Domain.Forums;
using Nop.Core.Domain.Gdpr;
using Nop.Core.Domain.Localization;
using Nop.Core.Domain.Messages;
using Nop.Core.Domain.Orders;
using Nop.Core.Domain.Payments;
using Nop.Core.Domain.Security;
using Nop.Core.Domain.Seo;
using Nop.Core.Domain.Shipping;
using Nop.Core.Domain.Tax;
using Nop.Core.Domain.Vendors;
using Nop.Services.Attributes;
using Nop.Services.Catalog;
using Nop.Services.Common;
using Nop.Services.Customers;
using Nop.Services.Directory;
using Nop.Services.Discounts;
using Nop.Services.ExportImport.Help;
using Nop.Services.Forums;
using Nop.Services.Gdpr;
using Nop.Services.Helpers;
using Nop.Services.Localization;
using Nop.Services.Logging;
using Nop.Services.Media;
using Nop.Services.Messages;
using Nop.Services.Orders;
using Nop.Services.Seo;
using Nop.Services.Shipping;
using Nop.Services.Shipping.Date;
using Nop.Services.Stores;
using Nop.Services.Tax;
using Nop.Services.Vendors;
namespace Nop.Services.ExportImport;
///
/// Export manager
///
public partial class ExportManager : IExportManager
{
#region Fields
protected readonly AddressSettings _addressSettings;
protected readonly CatalogSettings _catalogSettings;
protected readonly SecuritySettings _securitySettings;
protected readonly ICustomerActivityService _customerActivityService;
protected readonly CustomerSettings _customerSettings;
protected readonly DateTimeSettings _dateTimeSettings;
protected readonly ForumSettings _forumSettings;
protected readonly IAddressService _addressService;
protected readonly ICategoryService _categoryService;
protected readonly ICountryService _countryService;
protected readonly ICurrencyService _currencyService;
protected readonly IAttributeFormatter _customerAttributeFormatter;
protected readonly ICustomerService _customerService;
protected readonly IDateRangeService _dateRangeService;
protected readonly IDateTimeHelper _dateTimeHelper;
protected readonly IDiscountService _discountService;
protected readonly IForumService _forumService;
protected readonly IGdprService _gdprService;
protected readonly IGenericAttributeService _genericAttributeService;
protected readonly ILanguageService _languageService;
protected readonly ILocalizationService _localizationService;
protected readonly ILocalizedEntityService _localizedEntityService;
protected readonly IManufacturerService _manufacturerService;
protected readonly IMeasureService _measureService;
protected readonly INewsLetterSubscriptionService _newsLetterSubscriptionService;
protected readonly IOrderService _orderService;
protected readonly IPictureService _pictureService;
protected readonly IPriceFormatter _priceFormatter;
protected readonly IProductAttributeService _productAttributeService;
protected readonly IProductService _productService;
protected readonly IProductTagService _productTagService;
protected readonly IProductTemplateService _productTemplateService;
protected readonly IShipmentService _shipmentService;
protected readonly ISpecificationAttributeService _specificationAttributeService;
protected readonly IStateProvinceService _stateProvinceService;
protected readonly IStoreMappingService _storeMappingService;
protected readonly IStoreService _storeService;
protected readonly ITaxCategoryService _taxCategoryService;
protected readonly IUrlRecordService _urlRecordService;
protected readonly IVendorService _vendorService;
protected readonly IWorkContext _workContext;
protected readonly OrderSettings _orderSettings;
protected readonly ProductEditorSettings _productEditorSettings;
#endregion
#region Ctor
public ExportManager(AddressSettings addressSettings,
CatalogSettings catalogSettings,
SecuritySettings securitySettings,
CustomerSettings customerSettings,
DateTimeSettings dateTimeSettings,
ForumSettings forumSettings,
IAddressService addressService,
IAttributeFormatter customerAttributeFormatter,
ICategoryService categoryService,
ICountryService countryService,
ICurrencyService currencyService,
ICustomerActivityService customerActivityService,
ICustomerService customerService,
IDateRangeService dateRangeService,
IDateTimeHelper dateTimeHelper,
IDiscountService discountService,
IForumService forumService,
IGdprService gdprService,
IGenericAttributeService genericAttributeService,
ILanguageService languageService,
ILocalizationService localizationService,
ILocalizedEntityService localizedEntityService,
IManufacturerService manufacturerService,
IMeasureService measureService,
INewsLetterSubscriptionService newsLetterSubscriptionService,
IOrderService orderService,
IPictureService pictureService,
IPriceFormatter priceFormatter,
IProductAttributeService productAttributeService,
IProductService productService,
IProductTagService productTagService,
IProductTemplateService productTemplateService,
IShipmentService shipmentService,
ISpecificationAttributeService specificationAttributeService,
IStateProvinceService stateProvinceService,
IStoreMappingService storeMappingService,
IStoreService storeService,
ITaxCategoryService taxCategoryService,
IUrlRecordService urlRecordService,
IVendorService vendorService,
IWorkContext workContext,
OrderSettings orderSettings,
ProductEditorSettings productEditorSettings)
{
_addressSettings = addressSettings;
_catalogSettings = catalogSettings;
_securitySettings = securitySettings;
_customerSettings = customerSettings;
_dateTimeSettings = dateTimeSettings;
_addressService = addressService;
_customerAttributeFormatter = customerAttributeFormatter;
_forumSettings = forumSettings;
_categoryService = categoryService;
_countryService = countryService;
_currencyService = currencyService;
_customerActivityService = customerActivityService;
_customerService = customerService;
_dateRangeService = dateRangeService;
_dateTimeHelper = dateTimeHelper;
_discountService = discountService;
_forumService = forumService;
_gdprService = gdprService;
_genericAttributeService = genericAttributeService;
_languageService = languageService;
_localizationService = localizationService;
_localizedEntityService = localizedEntityService;
_manufacturerService = manufacturerService;
_measureService = measureService;
_newsLetterSubscriptionService = newsLetterSubscriptionService;
_orderService = orderService;
_pictureService = pictureService;
_priceFormatter = priceFormatter;
_productAttributeService = productAttributeService;
_productService = productService;
_productTagService = productTagService;
_productTemplateService = productTemplateService;
_shipmentService = shipmentService;
_specificationAttributeService = specificationAttributeService;
_stateProvinceService = stateProvinceService;
_storeMappingService = storeMappingService;
_storeService = storeService;
_taxCategoryService = taxCategoryService;
_urlRecordService = urlRecordService;
_vendorService = vendorService;
_workContext = workContext;
_orderSettings = orderSettings;
_productEditorSettings = productEditorSettings;
}
#endregion
#region Utilities
/// A task that represents the asynchronous operation
protected virtual async Task WriteCategoriesAsync(XmlWriter xmlWriter, int parentCategoryId, int totalCategories)
{
var categories = await _categoryService.GetAllCategoriesByParentCategoryIdAsync(parentCategoryId, true);
if (categories == null || !categories.Any())
return totalCategories;
totalCategories += categories.Count;
var languages = await _languageService.GetAllLanguagesAsync(showHidden: true);
foreach (var category in categories)
{
await xmlWriter.WriteStartElementAsync("Category");
await xmlWriter.WriteStringAsync("Id", category.Id);
await WriteLocalizedPropertyXmlAsync(category, c => c.Name, xmlWriter, languages);
await WriteLocalizedPropertyXmlAsync(category, c => c.Description, xmlWriter, languages);
await xmlWriter.WriteStringAsync("CategoryTemplateId", category.CategoryTemplateId);
await WriteLocalizedPropertyXmlAsync(category, c => c.MetaKeywords, xmlWriter, languages, await IgnoreExportCategoryPropertyAsync());
await WriteLocalizedPropertyXmlAsync(category, c => c.MetaDescription, xmlWriter, languages, await IgnoreExportCategoryPropertyAsync());
await WriteLocalizedPropertyXmlAsync(category, c => c.MetaTitle, xmlWriter, languages, await IgnoreExportCategoryPropertyAsync());
await WriteLocalizedSeNameXmlAsync(category, xmlWriter, languages, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("ParentCategoryId", category.ParentCategoryId);
await xmlWriter.WriteStringAsync("PictureId", category.PictureId);
await xmlWriter.WriteStringAsync("PageSize", category.PageSize, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("AllowCustomersToSelectPageSize", category.AllowCustomersToSelectPageSize, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("PageSizeOptions", category.PageSizeOptions, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("PriceRangeFiltering", category.PriceRangeFiltering, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("PriceFrom", category.PriceFrom, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("PriceTo", category.PriceTo, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("ManuallyPriceRange", category.ManuallyPriceRange, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("ShowOnHomepage", category.ShowOnHomepage, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("IncludeInTopMenu", category.IncludeInTopMenu, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("Published", category.Published, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("Deleted", category.Deleted, true);
await xmlWriter.WriteStringAsync("DisplayOrder", category.DisplayOrder);
await xmlWriter.WriteStringAsync("CreatedOnUtc", category.CreatedOnUtc, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStringAsync("UpdatedOnUtc", category.UpdatedOnUtc, await IgnoreExportCategoryPropertyAsync());
await xmlWriter.WriteStartElementAsync("Products");
var productCategories = await _categoryService.GetProductCategoriesByCategoryIdAsync(category.Id, showHidden: true);
foreach (var productCategory in productCategories)
{
var product = await _productService.GetProductByIdAsync(productCategory.ProductId);
if (product == null || product.Deleted)
continue;
await xmlWriter.WriteStartElementAsync("ProductCategory");
await xmlWriter.WriteStringAsync("ProductCategoryId", productCategory.Id);
await xmlWriter.WriteStringAsync("ProductId", productCategory.ProductId);
await WriteLocalizedPropertyXmlAsync(product, p => p.Name, xmlWriter, languages, overriddenNodeName: "ProductName");
await xmlWriter.WriteStringAsync("IsFeaturedProduct", productCategory.IsFeaturedProduct);
await xmlWriter.WriteStringAsync("DisplayOrder", productCategory.DisplayOrder);
await xmlWriter.WriteEndElementAsync();
}
await xmlWriter.WriteEndElementAsync();
await xmlWriter.WriteStartElementAsync("SubCategories");
totalCategories = await WriteCategoriesAsync(xmlWriter, category.Id, totalCategories);
await xmlWriter.WriteEndElementAsync();
await xmlWriter.WriteEndElementAsync();
}
return totalCategories;
}
///
/// Returns the path to the image file by ID
///
/// Picture ID
///
/// A task that represents the asynchronous operation
/// The task result contains the path to the image file
///
protected virtual async Task GetPicturesAsync(int pictureId)
{
var picture = await _pictureService.GetPictureByIdAsync(pictureId);
return await _pictureService.GetThumbLocalPathAsync(picture);
}
///
/// Returns the list of categories for a product separated by a ";"
///
/// Product
///
/// A task that represents the asynchronous operation
/// The task result contains the list of categories
///
protected virtual async Task