I am currently doing some improvements in nopCommerce's Import and Export manager.
such as Export/Import with localized content
In order to support localization, my understanding is that I need to get access to an ILocalizedEntityService instance inside the ImportManager and Export Manager class. So, what I am going to do is:
1- ExportManager class
inside fields area add
private readonly ILocalizedEntityService _localizedEntityService
Pass an instance of ILocalizedEntityService to the ImportManager constructor, and assign it to the local
variable I created above:
ILocalizedEntityService localizedEntityService
this._localizedEntityService = localizedEntityService;
inside ExportProductsToXlsx function add property need to export with the Arabic language
ExportProductsToXlsx(IEnumerable<Product> products){
new PropertyByName<Product>("ArName",p=>_localizedEntityService.GetLocalizedValue(2,
p.Id,"Product","Name")),
new PropertyByName<Product>("ArShortDescription",p=>_localizedEntityService.GetLocalizedValue(2,
p.Id,"Product","ShortDescription")),
new PropertyByName<Product>("ArFullDescription",p=>_localizedEntityService.GetLocalizedValue(2,
p.Id,"Product","FullDescription")),}
}
can flow all editing here
https://github.com/EgyNopCom/NopCommerce/blob/issue-524-Export-import-localized-content/Libraries/Nop.Services/ExportImport/ExportManager.cs
2-ImportManager class
using Nop.Core.Domain.Localization;
declare global variables
LocalizedProperty ArName;
LocalizedProperty ArShortDescription;
LocalizedProperty ArFullDescription;
inside fields area add
private readonly ILocalizedEntityService _localizedEntityService;
Pass an instance of ILocalizedEntityService to the ImportManager constructor, and assign it to the local
variable I created above:
ILocalizedEntityService localizedEntityService
this._localizedEntityService = localizedEntityService;
inside ImportProductsFromXlsx(Stream stream) function read property need to import with the Arabic language
from excel sheet
// read from excel new property with different language
ImportProductsFromXlsx(Stream stream) {
case "ArName":
var arname = property.StringValue;
ArName = new LocalizedProperty();
ArName.LanguageId = 2;
ArName.LocaleKey = "Name";
ArName.LocaleKeyGroup = "Product";
ArName.LocaleValue = arname;
break;
case "ArShortDescription":
var arshortdescription = property.StringValue;
ArShortDescription = new LocalizedProperty();
ArShortDescription.LanguageId = 2;
ArShortDescription.LocaleKey = "ShortDescription";
ArShortDescription.LocaleKeyGroup = "Product";
ArShortDescription.LocaleValue = arshortdescription;
break;
case "ArFullDescription":
var arfulldescription = property.StringValue;
ArFullDescription = new LocalizedProperty();
ArFullDescription.LanguageId = 2;
ArFullDescription.LocaleKey = "FullDescription";
ArFullDescription.LocaleKeyGroup = "Product";
ArFullDescription.LocaleValue = arfulldescription;
break;
}
then check if product new or not
inside this if statement
if (isNew)
{
_productService.InsertProduct(product);
// insert new product localized property in table localize
_localizedEntityService.SaveLocalizedValue(product, x => x.Name, ArName.LocaleValue,2);
_localizedEntityService.SaveLocalizedValue(product, x => x.ShortDescription, ArShortDescription.LocaleValue,2);
_localizedEntityService.SaveLocalizedValue(product, x => x.FullDescription, ArFullDescription.LocaleValue,2);
}
else
{
_productService.UpdateProduct(product);
// update product localized property in table localize
_localizedEntityService.SaveLocalizedValue(product, x => x.Name, ArName.LocaleValue,2);
_localizedEntityService.SaveLocalizedValue(product, x => x.ShortDescription,
ArShortDescription.LocaleValue,2);
_localizedEntityService.SaveLocalizedValue(product, x => x.FullDescription,
ArFullDescription.LocaleValue,2);
}
can flow all editing here:
https://github.com/EgyNopCom/NopCommerce/blob/issue-524-Export-import-localized-content/Libraries/Nop.Services/ExportImport/ImportManager.cs
Am I on the right track? Did I miss anything?
Thanks for your help.