/// <summary> /// Prepares the specified structure info. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="packageInfo"> The package info. </param> protected void Prepare(StructureInfo structureInfo, PackageInfo packageInfo) { _mediaStructurePackage.PrepareImport(structureInfo, packageInfo); _productStructurePackage.PrepareImport(structureInfo, packageInfo); _ecommerceStructurePackage.PrepareImport(structureInfo, packageInfo); _websiteStructurePackage.PrepareImport(structureInfo, packageInfo); }
/// <inheritdoc /> /// <summary> /// Exports to structure info. /// </summary> /// <param name="packageInfo"> The package info. </param> /// <returns> </returns> public StructureInfo Export(PackageInfo packageInfo) { var languagedMap = _languageService.GetAll().ToDictionary(x => x.SystemId, x => x.CultureInfo.Name); var visitorGroupId = (_groupService.Get <Group>("Visitors") ?? _groupService.Get <Group>("Besökare")).SystemId; var currencies = _currencyService.GetAll().ToList(); var relationTemplates = _fieldTemplateService.GetAll().OfType <Customers.FieldTemplateBase>().ToDictionary(x => x.SystemId, x => x.Id); var website = _websiteStructurePackage.Export(packageInfo); var mediaArchive = _mediaStructurePackage.Export(packageInfo); var productCatalog = _productStructurePackage.Export(packageInfo); var ecommerce = _ecommerceStructurePackage.Export(packageInfo); var structureInfo = new StructureInfo { Foundation = new StructureInfo.FoundationStructure { LanguageMap = languagedMap, VisitorGroupId = visitorGroupId, Currencies = currencies, RelationTemplates = relationTemplates }, Website = website, MediaArchive = mediaArchive, ProductCatalog = productCatalog, ECommerce = ecommerce }; return(structureInfo); }
/// <summary> /// Imports the specified structure info. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="folder"> The folder. </param> /// <param name="parentId"> The parent id. </param> protected virtual void Import(StructureInfo structureInfo, Folder folder, Guid parentId) { foreach (var folderCarrier in structureInfo.MediaArchive.Folders.Where(x => x.ParentFolderSystemId == parentId)) { var newFolder = new Folder(structureInfo.MediaArchive.FolderTemplateId, folderCarrier.Name) { SystemId = structureInfo.Id(folderCarrier.SystemId), ParentFolderSystemId = folder.SystemId, }; foreach (var item in folderCarrier.AccessControlList) { newFolder.AccessControlList.Add(new AccessControlEntry(item.Operation, structureInfo.Id(structureInfo.Foundation.VisitorGroupId))); } _folderService.Create(newFolder); if (structureInfo.CreateExampleProducts) { Import(structureInfo, newFolder, folderCarrier.SystemId); } else { ImportFiles(structureInfo, newFolder, folderCarrier.SystemId); } } ImportFiles(structureInfo, folder, parentId); }
public void PrepareImport(StructureInfo structureInfo, PackageInfo packageInfo) { foreach (var page in structureInfo.Website.ChildPages) { structureInfo.Mappings.Add(page.SystemId, Guid.NewGuid()); } foreach (var block in structureInfo.Website.Blocks ?? Enumerable.Empty <Block>()) { structureInfo.Mappings.Add(block.SystemId, Guid.NewGuid()); } PrepareTaxclassImport(structureInfo); PrepareCountryImport(structureInfo); foreach (var pageTemplate in structureInfo.Website.PageTemplateMap) { if (!structureInfo.Mappings.ContainsKey(pageTemplate.Key)) { var template = _fieldTemplateService.Get <PageFieldTemplate>(pageTemplate.Value)?.MakeWritableClone() as PageFieldTemplate; structureInfo.Mappings.Add(pageTemplate.Key, template?.SystemId ?? Guid.Empty); } } foreach (var blockTemplate in structureInfo.Website.BlockTemplateMap ?? new Dictionary <Guid, string>()) { var template = _fieldTemplateService.Get <BlockFieldTemplate>(blockTemplate.Value)?.MakeWritableClone() as BlockFieldTemplate; structureInfo.Mappings.Add(blockTemplate.Key, template?.SystemId ?? Guid.Empty); } }
public void Import(StructureInfo structureInfo, PackageInfo packageInfo) { structureInfo.Prefix = DateTime.Now.Ticks.ToString(CultureInfo.InvariantCulture); ImportProducts(structureInfo); ImportCategories(structureInfo); }
private string GetNewId(StructureInfo structureInfo, string id, Guid systemId) { //only limit to 100 chars to not break the db constraint var newId = $"{structureInfo.Prefix}-{(string.IsNullOrEmpty(id) ? systemId.ToString() : id)}"; return(newId.Length < 100 ? newId : newId.Substring(0, 100)); }
private string CorrectValue(StructureInfo structureInfo, string field, string fieldValue, FieldDefinition fieldDefinition, bool changeUrl) { if (changeUrl && field == SystemFieldDefinitionConstants.Url) { fieldValue = $"{fieldValue}-{structureInfo.Prefix}"; } else { switch (fieldDefinition.FieldType) { case SystemFieldTypeConstants.Text: case SystemFieldTypeConstants.MultirowText: case SystemFieldTypeConstants.Editor: fieldValue = structureInfo.ReplaceText(fieldValue); break; case SystemFieldTypeConstants.MediaPointerFile: case SystemFieldTypeConstants.MediaPointerImage: case SystemFieldTypeConstants.Pointer: fieldValue = structureInfo.Id(new Guid(fieldValue)).ToString(); break; } } return(fieldValue); }
/// <summary> /// Imports the specified structure info. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="packageInfo"> The package info. </param> public void Import(StructureInfo structureInfo, PackageInfo packageInfo) { Prepare(structureInfo, packageInfo); _mediaStructurePackage.Import(structureInfo, packageInfo); _productStructurePackage.Import(structureInfo, packageInfo); _ecommerceStructurePackage.Import(structureInfo, packageInfo); _websiteStructurePackage.Import(structureInfo, packageInfo); }
private ICollection <BlockToChannelLink> UpdateBlockChannelLink(StructureInfo structureInfo, ICollection <BlockToChannelLink> blockChannelLinks) { foreach (var channelLink in blockChannelLinks) { channelLink.ChannelSystemId = structureInfo.Id(channelLink.ChannelSystemId); } return(blockChannelLinks); }
private PointerItem CorrectValue(StructureInfo structureInfo, PointerItem fieldValue) { if (fieldValue is PointerPageItem pointerPageItem) { pointerPageItem.ChannelSystemId = structureInfo.Id(pointerPageItem.ChannelSystemId); } fieldValue.EntitySystemId = structureInfo.Id(fieldValue.EntitySystemId); return(fieldValue); }
private void MapPublish(StructureInfo structureInfo, ICollection <CategoryToChannelLink> oldChannelLink, ICollection <CategoryToChannelLink> newChannelLink) { foreach (var item in oldChannelLink) { if (item.ChannelSystemId == structureInfo.Website.Channel.SystemId) { newChannelLink.Add(new CategoryToChannelLink(structureInfo.Id(item.ChannelSystemId))); } } }
/// <summary> /// Prepares the import. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="packageInfo"> The package info. </param> public virtual void PrepareImport(StructureInfo structureInfo, PackageInfo packageInfo) { foreach (var item in structureInfo.ECommerce.DeliveryMethod) { structureInfo.Mappings.Add(item.ID, Guid.NewGuid()); } foreach (var item in structureInfo.ECommerce.PaymentMethod) { structureInfo.Mappings.Add(item.ID, Guid.NewGuid()); } }
/// <summary> /// Imports the specified structure info. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="packageInfo"> The package info. </param> public virtual void Import(StructureInfo structureInfo, PackageInfo packageInfo) { foreach (var delivery in structureInfo.ECommerce.DeliveryMethod) { CreateDeliveryMethod(delivery, structureInfo); } //foreach (var payment in structureInfo.ECommerce.PaymentMethod) //{ // CreatePaymentMethod(payment, structureInfo); //} }
private JToken CorrectValue <TArea>(StructureInfo structureInfo, string field, JToken fieldValue, FieldDefinition fieldDefinition, bool changeUrl) where TArea : IArea { if (field.Equals(SystemFieldDefinitionConstants.ThumbnailsMetadata, StringComparison.OrdinalIgnoreCase)) { var channelId = structureInfo.Id(structureInfo.Website.Channel.SystemId).ToString("N"); foreach (var item in ((JArray)fieldValue)) { var fileNameSuffix = item.SelectToken("fileNameSuffix"); if (fileNameSuffix.Value <string>() == channelId) { fileNameSuffix.Replace(new JValue(channelId)); } } return(fieldValue); } var value = ConvertFromJsonValue(fieldValue); switch (value) { case List <string> _: var items = value as List <string>; for (var i = 0; i < items.Count; i++) { items[i] = CorrectValue(structureInfo, field, items[i], fieldDefinition, changeUrl); } return(new JArray(items)); case string _: return(CorrectValue(structureInfo, field, (string)value, fieldDefinition, changeUrl)); case List <PointerItem> pointerItems: for (var i = 0; i < pointerItems.Count; i++) { pointerItems[i] = CorrectValue(structureInfo, pointerItems[i]); } return(JArray.FromObject(pointerItems, _jsonSerializer)); case List <MultiFieldItem> multiFieldItems: foreach (var item in multiFieldItems) { if (item != null) { AddProperties <TArea>(structureInfo, item.Fields, item.Fields); } } return(JArray.FromObject(multiFieldItems, _jsonSerializer)); } return(fieldValue); }
public void AddProperties <TArea>(StructureInfo structureInfo, IFieldFramework oldFieldContainer, IFieldFramework fieldContainer, bool changeUrl = true, IList <string> excludeFields = null) where TArea : IArea { if (oldFieldContainer[SystemFieldDefinitionConstants.Images] is List <Guid> images) { var newImages = images.Select(structureInfo.Id).ToList(); fieldContainer[SystemFieldDefinitionConstants.Images] = newImages; } var fields = Get <TArea>((IFieldContainerAccessor)oldFieldContainer); foreach (var field in fields) { if (excludeFields?.Contains(field.Key) == true) { continue; } var fieldDefinition = _fieldDefinitionService.Get <TArea>(field.Key); if (fieldDefinition == null) { continue; } if (fieldDefinition.MultiCulture) { foreach (var cultureValue in field.Value) { var value = CorrectValue <TArea>(structureInfo, field.Key, cultureValue.Value, fieldDefinition, changeUrl); fieldContainer[fieldDefinition.Id, cultureValue.Key] = ConvertFromEditValue( new EditFieldTypeConverterArgs(fieldDefinition, new CultureInfo(cultureValue.Key)), value); } } else { if (field.Value.TryGetValue("*", out var value)) { var newValue = CorrectValue <TArea>(structureInfo, field.Key, value, fieldDefinition, changeUrl); fieldContainer[fieldDefinition.Id] = ConvertFromEditValue( new EditFieldTypeConverterArgs(fieldDefinition, CultureInfo.CurrentCulture), newValue); } else { fieldContainer.TryRemoveValue(fieldDefinition.Id, out _); } } } }
/// <summary> /// Prepares the import. /// </summary> /// <param name="structureInfo"> The structure info. </param> /// <param name="packageInfo"> The package info. </param> public virtual void PrepareImport(StructureInfo structureInfo, PackageInfo packageInfo) { structureInfo.Mappings.Add(packageInfo.Folder.SystemId, Guid.Empty); foreach (var item in structureInfo.MediaArchive.Folders) { structureInfo.Mappings.Add(item.SystemId, Guid.NewGuid()); } foreach (var item in structureInfo.MediaArchive.Files) { structureInfo.Mappings.Add(item.SystemId, Guid.NewGuid()); } structureInfo.MediaArchive.FolderTemplateId = _fieldTemplateService.GetAll().First(c => (c is FolderFieldTemplate)).SystemId; }
private void MapCategories(StructureInfo structureInfo, ICollection <CategoryToProductLink> oldCategories, ICollection <CategoryToProductLink> newCategories) { foreach (var categoryLink in oldCategories) { var baseProductSystemId = structureInfo.Id(categoryLink.BaseProductSystemId); newCategories.Add(new CategoryToProductLink(baseProductSystemId) { MainCategory = categoryLink.MainCategory, ActiveVariantSystemIds = new HashSet <Guid>(categoryLink.ActiveVariantSystemIds.Select(structureInfo.Id)) }); } }
private void AddPrices(StructureInfo structureInfo) { if (structureInfo.ProductCatalog.PriceListItems != null && structureInfo.ProductCatalog.PriceListItems.Count > 0) { foreach (var priceItem in structureInfo.ProductCatalog.PriceListItems) { _priceListItemService.Create(new PriceListItem(structureInfo.Id(priceItem.VariantSystemId), structureInfo.Id(priceItem.PriceListSystemId)) { MinimumQuantity = priceItem.MinimumQuantity, Price = priceItem.Price, }); } } }
private void CreateWebsite(string name, StructureInfo structureInfo) { var website = structureInfo.Website.Website.MakeWritableClone(); website.Id = _slugifyService.Slugify(CultureInfo.CurrentCulture, name).NullIfEmpty(); foreach (var language in _languageService.GetAll()) { website.Localizations[language.CultureInfo].Name = name; } website.SystemId = structureInfo.Id(website.SystemId); website.FieldTemplateSystemId = structureInfo.Id(website.FieldTemplateSystemId); _websiteService.Create(website); structureInfo.Website.Website = website; }
public void PersistStructureInfo(StructureInfo structureInfo) { var maFileData = structureInfo.MediaArchive.FileData; var fileInfo = new FileInfo(GetStructureInfoPath(".storage")); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.PersistCompressedJson(maFileData); structureInfo.MediaArchive.FileData = null; var pageThumbnailData = structureInfo.Website.PageThumbnailData; fileInfo = new FileInfo(GetStructureInfoPath(".pageData.storage")); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.PersistCompressedJson(pageThumbnailData); structureInfo.Website.PageThumbnailData = null; var blockThumbnailData = structureInfo.Website.BlockThumbnailData; fileInfo = new FileInfo(GetStructureInfoPath(".blockData.storage")); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.PersistCompressedJson(blockThumbnailData); structureInfo.Website.BlockThumbnailData = null; fileInfo = new FileInfo(GetStructureInfoPath() + ".json"); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.PersistJson(structureInfo); fileInfo = new FileInfo(GetStructureInfoPath()); if (fileInfo.Exists) { fileInfo.Delete(); } fileInfo.PersistCompressedJson(structureInfo); }
private void CreateDomainName(string domain, StructureInfo structureInfo) { var name = ExtractDomainName(domain); var domainName = _domainNameService.Get(name); if (domainName == null) { domainName = new DomainName(name); _domainNameService.Create(domainName); } structureInfo.Website.DomainName = domainName; structureInfo.Mappings.Add(structureInfo.Website.DomainName.SystemId, domainName.SystemId); }
public void Import(StructureInfo structureInfo, PackageInfo packageInfo) { CreateBlocks(structureInfo); CreatePages(structureInfo, packageInfo); if (structureInfo.Website.BlockThumbnailData != null) { ImportThumbnail(structureInfo.Website.BlockThumbnailData, structureInfo, Block.BlobAuthority); } if (structureInfo.Website.PageThumbnailData != null) { ImportThumbnail(structureInfo.Website.PageThumbnailData, structureInfo, Page.BlobAuthority); } }
private void CreatePaymentMethod(PaymentMethodCarrier payment, StructureInfo structureInfo) { var paymentMethod = ModuleECommerce.Instance.PaymentMethods.Get(payment.Name, payment.PaymentProviderName, _securityToken); if (paymentMethod != null) { var paymentMethodCarrier = paymentMethod.GetAsCarrier(); paymentMethodCarrier.ImageID = Guid.Empty; //paymentMethodCarrier.ID = structureInfo.Id(paymentMethod.ID); PaymentMethodSaveNamesAndDescriptions(paymentMethodCarrier, payment); SavePaymentMethodCosts(paymentMethodCarrier, payment); paymentMethod.SetValuesFromCarrier(paymentMethodCarrier, _securityToken); } }
private Assortment CreateAssortment(StructureInfo structureInfo, string name, string domainName) { var assortment = new Assortment { Id = structureInfo.ProductCatalog.Assortment.Id + _slugifyService.Slugify(CultureInfo.CurrentCulture, name), AccessControlList = structureInfo.ProductCatalog.Assortment.AccessControlList.MakeWritable() }; foreach (var language in _languageService.GetAll()) { assortment.Localizations[language.CultureInfo].Name = name; } _assortmentService.Create(assortment); return(assortment); }
private void AddInventories(StructureInfo structureInfo) { if (structureInfo.ProductCatalog.InventoryItems != null && structureInfo.ProductCatalog.InventoryItems.Count > 0) { foreach (var inventoryItem in structureInfo.ProductCatalog.InventoryItems) { _inventoryItemService.Create( new InventoryItem( structureInfo.Id(inventoryItem.VariantSystemId), structureInfo.Id(inventoryItem.InventorySystemId)) { InStockQuantity = inventoryItem.InStockQuantity }); } } }
private void CreateMarket(StructureInfo structureInfo, Guid assortmentSystemId, string marketName) { var market = structureInfo.Website.Market.MakeWritableClone(); market.SystemId = structureInfo.Id(market.SystemId); market.FieldTemplateSystemId = structureInfo.Id(market.FieldTemplateSystemId); _structureInfoService.AddProperties <WebsiteArea>(structureInfo, structureInfo.Website.Market.Fields, market.Fields, false); market.AssortmentSystemId = assortmentSystemId; foreach (var language in _languageService.GetAll()) { market.Localizations[language.CultureInfo].Name = marketName; } market.Id = _slugifyService.Slugify(CultureInfo.CurrentCulture, marketName).NullIfEmpty(); _marketService.Create(market); structureInfo.Website.Market = market; }
private void AddBundles(StructureInfo structureInfo, Variant variant, Variant newVariant) { if (variant.BundledVariants != null && variant.BundledVariants.Count > 0) { newVariant.BundledVariants = new List <VariantBundledLink>(); foreach (var bundleItem in variant.BundledVariants) { if (structureInfo.Id(bundleItem.BundledVariantSystemId) != bundleItem.BundledVariantSystemId) { newVariant.BundledVariants.Add(new VariantBundledLink(structureInfo.Id(bundleItem.BundledVariantSystemId)) { Quantity = bundleItem.Quantity }); } } } }
private void CreateDeliveryMethod(DeliveryMethodCarrier delivery, StructureInfo structureInfo) { var delMethod = ModuleECommerce.Instance.DeliveryMethods.Get(delivery.ID, _securityToken); if (delMethod == null) { var carrier = new DeliveryMethodCarrier(); carrier.Name = delivery.Name; carrier.DeliveryProviderID = delivery.DeliveryProviderID; carrier.ImageID = Guid.Empty; carrier.ID = delivery.ID; DeliveryMethodSaveNamesAndDescriptions(carrier, delivery); carrier.Costs = UpdateDeliveryCurrency(delivery.Costs, structureInfo); carrier.Translations = UpdateLanguageId(delivery.Translations, structureInfo); ModuleECommerce.Instance.DeliveryMethods.Create(carrier, _securityToken); } }
private void CreateBlocks(StructureInfo structureInfo) { using (var db = _dataService.CreateBatch()) { foreach (var block in structureInfo.Website.Blocks) { var newBlock = block.MakeWritableClone(); newBlock.SystemId = structureInfo.Id(block.SystemId); newBlock.FieldTemplateSystemId = structureInfo.Id(block.FieldTemplateSystemId); newBlock.AccessControlList = _structureInfoService.GetAccessControlList(block.AccessControlList); _structureInfoService.AddProperties <BlockArea>(structureInfo, block.Fields, newBlock.Fields, false); newBlock.ChannelLinks = UpdateBlockChannelLink(structureInfo, block.ChannelLinks); db.Create(newBlock); } db.Commit(); } }
/// <summary> /// Imports the categories. /// </summary> /// <param name="structureInfo">The structure info.</param> private void ImportCategories(StructureInfo structureInfo) { foreach (var category in structureInfo.ProductCatalog.Categories) { var newCategory = new Category(structureInfo.Id(category.FieldTemplateSystemId), structureInfo.Id(structureInfo.ProductCatalog.Assortment.SystemId)) { SystemId = structureInfo.Id(category.SystemId), ParentCategorySystemId = structureInfo.Id(category.ParentCategorySystemId), AccessControlList = category.AccessControlList.MakeWritable() }; MapCategories(structureInfo, category.ProductLinks, newCategory.ProductLinks); _structureInfoService.AddProperties <ProductArea>(structureInfo, category.Fields, newCategory.Fields, false); MapPublish(structureInfo, category.ChannelLinks, newCategory.ChannelLinks); AddRelations(structureInfo, category, newCategory); _categoryService.Create(newCategory); } }