public IEnumerable <ContentReference> AllCategories() { List <ContentReference> localList = new List <ContentReference>(); List <int> nodeIds = new List <int>(); CatalogEntryDto dto = CatalogContext.Current.GetCatalogEntriesDto("Fashion"); CatalogRelationDto relDto = CatalogContext.Current.GetCatalogRelationDto(1, 0, 0, null, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); foreach (CatalogRelationDto.NodeEntryRelationRow item in relDto.NodeEntryRelation) { if (!nodeIds.Contains(item.CatalogNodeId)) { nodeIds.Add(item.CatalogNodeId); } } ReferenceConverter refConv = ServiceLocator.Current.GetInstance <ReferenceConverter>(); foreach (int item in nodeIds) { localList.Add(refConv.GetContentLink(item, CatalogContentType.CatalogNode, 0)); } return(localList); }
/// <summary> /// Binds the form. /// </summary> private void BindForm() { //autoComplete.ServiceMethod = this.ServiceMethod; GridHelper.BindGrid(EntryRelationDefaultGrid, "Catalog", Request.QueryString["_v"].ToString()); if (CatalogEntryId > 0) { CatalogRelationDto relation = CatalogContext.Current.GetCatalogRelationDto(ParentCatalogId, ParentCatalogNodeId, CatalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); DataTable table = new DataTable(); table.Columns.Add(new DataColumn("ID", typeof(int))); table.Columns.Add(new DataColumn("Name", typeof(string))); table.Columns.Add(new DataColumn("Quantity", typeof(decimal))); table.Columns.Add(new DataColumn("GroupName", typeof(string))); table.Columns.Add(new DataColumn("SortOrder", typeof(int))); foreach (CatalogRelationDto.CatalogEntryRelationRow row in relation.CatalogEntryRelation) { DataRow newRow = table.NewRow(); newRow["ID"] = row.ChildEntryId; newRow["Name"] = CatalogContext.Current.GetCatalogEntryDto(row.ChildEntryId).CatalogEntry[0].Name; newRow["Quantity"] = row.Quantity; newRow["GroupName"] = row.GroupName; newRow["SortOrder"] = row.SortOrder; table.Rows.Add(newRow); } EntryRelationDefaultGrid.DataSource = table; } EntryRelationDefaultGrid.DataBind(); }
/// <summary> /// Gets the catalog nodes dto. /// </summary> /// <param name="assetKey">The asset key.</param> /// <returns></returns> internal static CatalogRelationDto GetCatalogRelationDto(string assetKey) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = CatalogCache.CreateCacheKey("catalog-relation-asset", assetKey); CatalogRelationDto dto = null; // check cache first object cachedObject = CatalogCache.Get(cacheKey); if (cachedObject != null) { dto = (CatalogRelationDto)cachedObject; } // Load the object if (dto == null) { CatalogRelationAdmin admin = new CatalogRelationAdmin(); admin.LoadAsset(assetKey); dto = admin.CurrentDto; // Insert to the cache collection CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout); } dto.AcceptChanges(); return(dto); }
/// <summary> /// Gets the catalog nodes dto. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="groupName">Name of the group.</param> /// <param name="responseGroup">The response group.</param> /// <returns></returns> internal static CatalogRelationDto GetCatalogRelationDto(int catalogId, int catalogNodeId, int catalogEntryId, string groupName, CatalogRelationResponseGroup responseGroup) { // Assign new cache key, specific for site guid and response groups requested string cacheKey = CatalogCache.CreateCacheKey("catalog-relation", responseGroup.CacheKey, catalogId.ToString(), catalogNodeId.ToString(), catalogEntryId.ToString(), groupName); CatalogRelationDto dto = null; // check cache first object cachedObject = CatalogCache.Get(cacheKey); if (cachedObject != null) { dto = (CatalogRelationDto)cachedObject; } // Load the object if (dto == null) { CatalogRelationAdmin admin = new CatalogRelationAdmin(); admin.Load(catalogId, catalogNodeId, catalogEntryId, groupName, responseGroup.ResponseGroups.GetHashCode()); dto = admin.CurrentDto; // Insert to the cache collection CatalogCache.Insert(cacheKey, dto, CatalogConfiguration.Instance.Cache.CatalogCollectionTimeout); } dto.AcceptChanges(); return(dto); }
/// <summary> /// Saves the catalog relation. /// </summary> /// <param name="dto">The dto.</param> internal static void SaveCatalogRelation(CatalogRelationDto dto) { if (dto == null) { throw new ArgumentNullException("dto", String.Format("CatalogRelationDto can not be null")); } CatalogRelationAdmin admin = new CatalogRelationAdmin(dto); EventContext.Instance.RaiseRelationUpdatingEvent(dto, new RelationEventArgs("updating")); admin.Save(); EventContext.Instance.RaiseRelationUpdatedEvent(dto, new RelationEventArgs("updated")); string cacheKey = CatalogCache.CreateCacheKey("catalog-relation"); // remove cached items if (dto.CatalogEntryRelation.Rows.Count > 0) { int catalogEntryId = ((CatalogRelationDto.CatalogEntryRelationRow)dto.CatalogEntryRelation.Rows[0]).ParentEntryId; CatalogCache.RemoveByPattern(String.Format(@"{0}-(\w*)-(\d+)-(\d+)-{1}-.*", cacheKey, catalogEntryId.ToString())); } if (dto.CatalogNodeRelation.Rows.Count > 0) { int catalogId = ((CatalogRelationDto.CatalogNodeRelationRow)dto.CatalogNodeRelation.Rows[0]).CatalogId; int catalogNodeId = ((CatalogRelationDto.CatalogNodeRelationRow)dto.CatalogNodeRelation.Rows[0]).ChildNodeId; CatalogCache.RemoveByPattern(String.Format(@"{0}-(\w*)-{1}-{2}-(\d+)-.*", cacheKey, catalogId.ToString(), catalogNodeId.ToString())); } // TODO: remove cached items in case if CatalogRelations are deleted }
/// <summary> /// Called when [deleting]. /// </summary> protected override void OnDeleting() { base.OnDeleting(); CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(PrimaryKeyId.ToString()); if (catalogRelationDto.CatalogItemAsset.Count > 0) { for (int i = 0; i < catalogRelationDto.CatalogItemAsset.Count; i++) { catalogRelationDto.CatalogItemAsset[i].Delete(); } if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } // Clean Up BlobStorage BlobStorageProvider provider = BlobStorage.Providers[BlobStorageProvider]; if (provider != null) { BlobInfo blobInfo = provider.GetInfo((Guid)BlobUid); if (blobInfo != null) { provider.ReleaseStream(blobInfo); } } }
private void ValidateItems() { CatalogRelationDto relationDto = null; CatalogDto.CatalogRow catalogRow = null; var marketTester = new ExcludedCatalogEntryMarketsField(); var orderMarket = ServiceLocator.Current.GetInstance <IMarketService>().GetMarket(OrderGroup.MarketId); var orderForms = OrderGroup.OrderForms.ToArray(); var lineItems = orderForms.SelectMany(x => x.LineItems.ToArray()); var validLineItems = lineItems.Where(x => x.CatalogEntryId != "0" && !String.IsNullOrEmpty(x.CatalogEntryId) && !x.CatalogEntryId.StartsWith("@")); foreach (var lineItem in validLineItems) { var entryRow = GetEntryRowForLineItem(lineItem); if (entryRow == null) { AddWarningSafe(Warnings, "LineItemCodeRemoved-" + lineItem.Id, String.Format("The catalog entry code that maps to the line item {0} has been removed or changed. The line item is no longer valid", lineItem.CatalogEntryId)); DeleteInvalidItem(orderForms, lineItem); continue; } if (!marketTester.IsValidForMarket(entryRow, orderMarket)) { AddWarningSafe(Warnings, "LineItemRemoved-" + lineItem.LineItemId.ToString(), String.Format("Item \"{0}\" has been removed from the cart because it is not available in your market.", lineItem.DisplayName)); DeleteInvalidItem(orderForms, lineItem); } else if (entryRow.IsActive && entryRow.StartDate < FrameworkContext.Current.CurrentDateTime && entryRow.EndDate > FrameworkContext.Current.CurrentDateTime) { if (catalogRow == null || catalogRow.CatalogId != entryRow.CatalogId) { var catalogDto = CatalogContext.Current.GetCatalogDto(entryRow.CatalogId); catalogRow = catalogDto.Catalog.FirstOrDefault(); } // check if catalog is visible if (catalogRow != null && catalogRow.IsActive && catalogRow.StartDate < FrameworkContext.Current.CurrentDateTime && catalogRow.EndDate > FrameworkContext.Current.CurrentDateTime) { relationDto = CatalogContext.Current.GetCatalogRelationDto(entryRow.CatalogEntryId); // populate item lineItem.Catalog = catalogRow.Name; lineItem.ParentCatalogEntryId = GetParentCatalogEntryId(entryRow.CatalogEntryId, relationDto); //Inventory Info IWarehouseInventory aggregateInventory = ServiceLocator.Current.GetInstance <IWarehouseInventoryService>() .GetTotal(new CatalogKey(entryRow)); PopulateInventoryInfo(aggregateInventory, lineItem); //Variation Info PopulateVariationInfo(entryRow, lineItem); } } } }
/// <summary> /// Raises the relation updating event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="args">The <see cref="Mediachase.Commerce.Catalog.Events.RelationEventArgs"/> instance containing the event data.</param> public void RaiseRelationUpdatingEvent(CatalogRelationDto sender, RelationEventArgs args) { if (RelationUpdating != null) { RelationUpdating(sender, args); } }
/// <summary> /// Creates the empty dtos. /// </summary> /// <param name="entry">The entry.</param> /// <param name="relation">The relation.</param> /// <param name="association">The association.</param> /// <param name="persistInSession">if set to <c>true</c> [persist in session].</param> private void CreateEmptyDtos(ref CatalogEntryDto entry, ref CatalogRelationDto relation, ref CatalogAssociationDto association, bool persistInSession) { if (relation == null) { relation = new CatalogRelationDto(); if (persistInSession) { Session[_CatalogRelationDtoString] = relation; } } if (association == null) { association = new CatalogAssociationDto(); if (persistInSession) { Session[_CatalogAssociationDtoString] = association; } } if (entry == null) { entry = new CatalogEntryDto(); if (persistInSession) { Session[_CatalogEntryDtoString] = entry; } } }
public void MultipleParents() { var relations = new CatalogRelationDto(); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 10, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(2, 10, "", 0, "", 0); Assert.Throws <ArgumentException>(() => new ESalesVariantHelper(relations.CatalogEntryRelation)); }
/// <summary> /// Loads the fresh relation. /// </summary> /// <returns></returns> private CatalogRelationDto LoadFreshRelation() { CatalogRelationDto relation = LoadRelation(); // persist in session Session[_CatalogRelationDtoString] = relation; return(relation); }
/// <summary> /// Moves the node entry. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void MoveNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { if (catalogId != targetCatalogId) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId); if (catalogEntryDto.CatalogEntry.Count > 0) { catalogEntryDto.CatalogEntry[0].CatalogId = targetCatalogId; CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } } bool addNewRow = false; if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId) { if (catalogNodeId > 0) { CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); if (catalogRelationDto.NodeEntryRelation.Count > 0) { if (targetCatalogNodeId > 0) { catalogRelationDto.NodeEntryRelation[0].CatalogId = targetCatalogId; catalogRelationDto.NodeEntryRelation[0].CatalogNodeId = targetCatalogNodeId; } else { catalogRelationDto.NodeEntryRelation[0].Delete(); } CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } else if (targetCatalogNodeId > 0) { addNewRow = true; } } else if (targetCatalogNodeId > 0) { addNewRow = true; } if (addNewRow) { CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto(); CatalogRelationDto.NodeEntryRelationRow row = newCatalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow(); row.CatalogId = targetCatalogId; row.CatalogNodeId = targetCatalogNodeId; row.CatalogEntryId = catalogEntryId; row.SortOrder = 0; newCatalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row); CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto); } } }
public void FindNoParentProduct() { var relations = new CatalogRelationDto(); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 10, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 11, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(2, 12, "", 0, "", 0); var helper = new ESalesVariantHelper(relations.CatalogEntryRelation); Assert.Throws <KeyNotFoundException>(() => helper.GetParentProduct(13)); }
public void FindParentProduct() { var relations = new CatalogRelationDto(); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 10, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 11, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(2, 12, "", 0, "", 0); var helper = new ESalesVariantHelper(relations.CatalogEntryRelation); Assert.That(helper.GetParentProduct(12), Is.EqualTo(2)); }
/// <summary> /// Loads the context. /// </summary> private void LoadContext() { CatalogEntryDto entry = null; CatalogRelationDto relation = null; CatalogAssociationDto association = null; if (!this.IsPostBack && (!this.Request.QueryString.ToString().Contains("Callback=yes"))) // load fresh on initial load { entry = LoadFreshEntry(); relation = LoadFreshRelation(); association = LoadFreshAssociation(); // if Dtos not loaded, create empty Dtos CreateEmptyDtos(ref entry, ref relation, ref association, true); } else // load from session { entry = (CatalogEntryDto)Session[_CatalogEntryDtoString]; if (entry == null) { entry = LoadFreshEntry(); } association = (CatalogAssociationDto)Session[_CatalogAssociationDtoString]; if (association == null) { association = LoadFreshAssociation(); } relation = (CatalogRelationDto)Session[_CatalogRelationDtoString]; if (relation == null) { relation = LoadFreshRelation(); } } if (CatalogEntryId > 0 && entry.CatalogEntry.Count == 0) { Response.Redirect("ContentFrame.aspx?_a=Catalog&_v=Catalog-List"); } // Put a dictionary key that can be used by other tabs IDictionary dic = new ListDictionary(); dic.Add(_CatalogEntryDtoString, entry); dic.Add(_CatalogRelationDtoString, relation); dic.Add(_CatalogAssociationDtoString, association); // Call tabs load context ViewControl.LoadContext(dic); }
public void FindVariants() { var relations = new CatalogRelationDto(); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 10, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 11, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(2, 12, "", 0, "", 0); var helper = new ESalesVariantHelper(relations.CatalogEntryRelation); Assert.That(helper.GetVariants(1).ToArray(), Is.EquivalentTo(new[] { 10, 11 })); }
public void FindNoVariants() { var relations = new CatalogRelationDto(); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 10, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(1, 11, "", 0, "", 0); relations.CatalogEntryRelation.AddCatalogEntryRelationRow(2, 12, "", 0, "", 0); var helper = new ESalesVariantHelper(relations.CatalogEntryRelation); Assert.That(!helper.GetVariants(3).Any()); }
protected override void OnCatalogEntryIndex(ref SearchDocument document, Mediachase.Commerce.Catalog.Dto.CatalogEntryDto.CatalogEntryRow entry, string language) { if (entry != null && entry.ClassTypeId.Equals(EntryType.Product, StringComparison.InvariantCultureIgnoreCase)) { if (!MetaDataContextClone.Language.Equals(language, StringComparison.InvariantCultureIgnoreCase)) { MetaDataContextClone.Language = language; } CatalogRelationDto relationDto = _catalog.GetCatalogRelationDto(0, 0, entry.CatalogEntryId, string.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); if (relationDto != null && relationDto.CatalogEntryRelation != null && relationDto.CatalogEntryRelation.Count > 0) { List <int> childIds = new List <int>(); foreach (CatalogRelationDto.CatalogEntryRelationRow relationRow in relationDto.CatalogEntryRelation) { childIds.Add(relationRow.ChildEntryId); } CatalogEntryDto skuDto = _catalog.GetCatalogEntriesDto(childIds.ToArray(), new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); List <string> searchProperties = new List <string> { SearchField.Store.NO, SearchField.Index.TOKENIZED, SearchField.IncludeInDefaultSearch.YES }; List <string> colorVariations = new List <string>(); if (skuDto != null && skuDto.CatalogEntry != null && skuDto.CatalogEntry.Count > 0) { foreach (CatalogEntryDto.CatalogEntryRow row in skuDto.CatalogEntry) { Hashtable hash = ObjectHelper.GetMetaFieldValues(row); if (hash.Contains("Color")) { string color = hash["Color"].ToString(); if (!string.IsNullOrEmpty(color) && !colorVariations.Contains(color.ToLower())) { colorVariations.Add(color.ToLower()); document.Add(new SearchField("Color", color.ToLower(), searchProperties.ToArray())); OnSearchIndexMessage(new Mediachase.Search.SearchIndexEventArgs( $"The color {color} was added to the index for {entry.Name}.", 1)); } } } } } } }
/// <summary> /// Deletes the entry recursive. /// </summary> /// <param name="entryId">The entry id.</param> /// <param name="parentCatalogId">The parent catalog id.</param> private void DeleteEntryRecursive(int entryId, int parentCatalogId) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { //Delete NodeEntryRelation rows CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { if (row.CatalogId == parentCatalogId) { row.Delete(); } } if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } else //if NodeEntryRelation doesn't exist delete entry { //Delete CatalogEntryAssociation rows foreach (CatalogEntryDto.CatalogAssociationRow catalogAssociationRow in catalogEntryDto.CatalogAssociation) { CatalogAssociationDto catalogAssociationDto = FrameworkContext.Current.CatalogSystem.GetCatalogAssociationDto(catalogAssociationRow.CatalogAssociationId); foreach (CatalogAssociationDto.CatalogEntryAssociationRow itemCatalogEntryAssociation in catalogAssociationDto.CatalogEntryAssociation) { itemCatalogEntryAssociation.Delete(); } if (catalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(catalogAssociationDto); } } //Delete child entry rows CatalogEntryDto childrenDto = CatalogContext.Current.GetCatalogEntriesDto(entryId, String.Empty, String.Empty); foreach (CatalogEntryDto.CatalogEntryRow row in childrenDto.CatalogEntry) { DeleteEntryRecursive(row.CatalogEntryId, 0); } //Delete entry row catalogEntryDto.CatalogEntry[0].Delete(); CatalogContext.Current.SaveCatalogEntry(catalogEntryDto); } } }
private static string GetParentCatalogEntryId(int catalogEntryId, CatalogRelationDto relationDto) { string retVal = null; var entryRelationRows = relationDto.CatalogEntryRelation.Select(String.Format("ChildEntryId={0}", catalogEntryId)).Cast<CatalogRelationDto.CatalogEntryRelationRow>(); if (entryRelationRows.Count() > 0) { //This method use catalog entry id, not code, so it'll not use the cache we have with CatalogEntryResponseGroup.ResponseGroup.Variations CatalogEntryDto parentEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryRelationRows.First().ParentEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (parentEntryDto.CatalogEntry.Count > 0) { retVal = parentEntryDto.CatalogEntry[0].Code; } } return retVal; }
private static string GetParentCatalogEntryId(int catalogEntryId, CatalogRelationDto relationDto) { string retVal = null; var entryRelationRows = relationDto.CatalogEntryRelation.Select(String.Format("ChildEntryId={0}", catalogEntryId)).Cast <CatalogRelationDto.CatalogEntryRelationRow>(); if (entryRelationRows.Count() > 0) { CatalogEntryDto parentEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryRelationRows.First().ParentEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (parentEntryDto.CatalogEntry.Count > 0) { retVal = parentEntryDto.CatalogEntry[0].Code; } } return(retVal); }
private static string GetParentCatalogEntryId(int catalogEntryId, CatalogRelationDto relationDto) { string retVal = null; var entryRelationRows = relationDto.CatalogEntryRelation.Select(String.Format("ChildEntryId={0}", catalogEntryId)).Cast <CatalogRelationDto.CatalogEntryRelationRow>(); if (entryRelationRows.Count() > 0) { //This method use catalog entry id, not code, so it'll not use the cache we have with CatalogEntryResponseGroup.ResponseGroup.Variations CatalogEntryDto parentEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryRelationRows.First().ParentEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (parentEntryDto.CatalogEntry.Count > 0) { retVal = parentEntryDto.CatalogEntry[0].Code; } } return(retVal); }
/// <summary> /// Deletes the catalog node. /// </summary> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogId">The catalog id.</param> internal static void DeleteCatalogNode(int catalogNodeId, int catalogId) { CatalogNodeDto catalogNodeDto = GetCatalogNodesDto(catalogId, new CatalogNodeResponseGroup(CatalogNodeResponseGroup.ResponseGroup.CatalogNodeFull)); CatalogRelationDto catalogRelationDto = CatalogRelationManager.GetCatalogRelationDto(0, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode | CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); DeleteNodeRecursive(catalogNodeId, catalogId, ref catalogNodeDto, ref catalogRelationDto); if (catalogRelationDto.HasChanges()) { CatalogRelationManager.SaveCatalogRelation(catalogRelationDto); } if (catalogNodeDto.HasChanges()) { SaveCatalogNode(catalogNodeDto); } }
/// <summary> /// Copies the node entry. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void CopyNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId) { CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(targetCatalogId, targetCatalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); if (catalogRelationDto.NodeEntryRelation.Count == 0) { CatalogRelationDto.NodeEntryRelationRow row = catalogRelationDto.NodeEntryRelation.NewNodeEntryRelationRow(); row.CatalogId = targetCatalogId; row.CatalogNodeId = targetCatalogNodeId; row.CatalogEntryId = catalogEntryId; row.SortOrder = 0; catalogRelationDto.NodeEntryRelation.AddNodeEntryRelationRow(row); CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } }
public List <KeyValuePair <int, decimal> > GetPackageChildEntries(int id) { List <KeyValuePair <int, decimal> > childEntryQuanities = new List <KeyValuePair <int, decimal> >(); CatalogRelationResponseGroup group = new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogEntry); CatalogRelationDto relations = CatalogContext.Current.GetCatalogRelationDto(0, 0, id, string.Empty, group); if (relations != null && relations.CatalogEntryRelation != null && relations.CatalogEntryRelation.Count > 0) { foreach (CatalogRelationDto.CatalogEntryRelationRow row in relations.CatalogEntryRelation.Rows) { childEntryQuanities.Add(new KeyValuePair <int, decimal>(row.ChildEntryId, row.Quantity)); } } return(childEntryQuanities); }
/// <summary> /// Copies the catalog node. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void CopyCatalogNode(int catalogId, int catalogNodeId, int targetCatalogId, int targetCatalogNodeId) { if (catalogId != targetCatalogId || catalogNodeId != targetCatalogNodeId) { if (catalogNodeId > 0) { CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode)); DataView dv = catalogRelationDto.CatalogNodeRelation.DefaultView; dv.RowFilter = String.Format("CatalogId = {0} AND ParentNodeId = {1} AND ChildNodeId = {2}", targetCatalogId, targetCatalogNodeId, catalogNodeId); if (dv.Count == 0) { CatalogRelationDto.CatalogNodeRelationRow row = catalogRelationDto.CatalogNodeRelation.NewCatalogNodeRelationRow(); row.CatalogId = targetCatalogId; row.ParentNodeId = targetCatalogNodeId; row.ChildNodeId = catalogNodeId; row.SortOrder = 0; catalogRelationDto.CatalogNodeRelation.AddCatalogNodeRelationRow(row); CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } } } }
/// <summary> /// Builds the path. /// </summary> /// <param name="doc">The doc.</param> /// <param name="catalog">The catalog.</param> /// <param name="catalogNode">The catalog node.</param> /// <param name="level">The level.</param> private void BuildPath(Document doc, CatalogDto catalog, CatalogNodeDto catalogNode, int level) { CatalogNodeDto node = catalogNode; doc.Add(new Field("_catalog", catalog.Catalog[0].Name, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("_node", catalogNode.CatalogNode[0].Code, Field.Store.YES, Field.Index.UN_TOKENIZED)); doc.Add(new Field("_level", level.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED)); level++; CatalogRelationDto relationDto = CatalogContext.Current.GetCatalogRelationDto(catalog.Catalog[0].CatalogId, catalogNode.CatalogNode[0].CatalogNodeId, 0, "", new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode)); foreach (CatalogRelationDto.CatalogNodeRelationRow relation in relationDto.CatalogNodeRelation) { CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodeDto(relation.ParentNodeId); CatalogDto catalogDto = CatalogContext.Current.GetCatalogDto(relation.CatalogId); BuildPath(doc, catalogDto, catalogNodeDto, level); } string path = String.Format("{0}/{1}", catalog.Catalog[0].Name, node.CatalogNode[0].Code); int catalogNodeId = node.CatalogNode[0].ParentNodeId; while ((node = CatalogContext.Current.GetCatalogNodeDto(catalogNodeId)) != null) { if (node.CatalogNode == null || node.CatalogNode.Count == 0) { break; } path = String.Format("{0}/{1}", path, node.CatalogNode[0].Code); catalogNodeId = node.CatalogNode[0].ParentNodeId; if (catalogNodeId == 0) { break; } } doc.Add(new Field(String.Format("_outline"), path, Field.Store.YES, Field.Index.UN_TOKENIZED)); }
/// <summary> /// When overridden in a derived class, retrieves the parent node of a specific <see cref="T:System.Web.SiteMapNode"></see> object. /// </summary> /// <param name="node">The <see cref="T:System.Web.SiteMapNode"></see> for which to retrieve the parent node.</param> /// <returns> /// A <see cref="T:System.Web.SiteMapNode"></see> that represents the parent of node; otherwise, null, if the <see cref="T:System.Web.SiteMapNode"></see> has no parent or security trimming is enabled and the parent node is not accessible to the current user. /// </returns> public override SiteMapNode GetParentNode(SiteMapNode catalogNode) { SiteMapNode ret = null; if (catalogNode != null) { lock (this) { if (catalogNode.Key.IndexOf("ce_", 0) == 0) { int entryCodeId = Int32.Parse(catalogNode.Key.Substring("ce_".Length)); CatalogRelationDto relation = CatalogContext.Current.GetCatalogRelationDto(0, 0, entryCodeId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); if (relation.NodeEntryRelation.Count > 0) { int catalogNodeId = relation.NodeEntryRelation[0].CatalogNodeId; CatalogNode node = CatalogContext.Current.GetCatalogNode(catalogNodeId); if (node != null && !String.IsNullOrEmpty(node.ID)) { return(CreateSiteMapNode(node));; } } } else if (catalogNode.Key.IndexOf("c_", 0) == 0) { string[] keys = catalogNode.Key.Substring("c_".Length).Split('_'); int parentNodeId = Int32.Parse(keys[1]); CatalogNode node = CatalogContext.Current.GetCatalogNode(parentNodeId); if (node != null && !String.IsNullOrEmpty(node.ID)) { return(CreateSiteMapNode(node)); } } } } return(ret); }
/// <summary> /// Processes the delete command. /// </summary> /// <param name="items">The items.</param> /// <param name="parentCatalogId">The parent catalog id.</param> /// <param name="parentCatalogNodeId">The parent catalog node id.</param> void ProcessDeleteCommand(string[] items, int parentCatalogId, int parentCatalogNodeId) { for (int i = 0; i < items.Length; i++) { string[] keys = EcfListView.GetPrimaryKeyIdStringItems(items[i]); if (keys != null) { int id = Int32.Parse(keys[0]); string type = keys[1]; if (id > 0) { if (String.Compare(type, "Node", true) == 0 || String.Compare(type, "LevelUp", true) == 0) { CatalogNodeDto catalogNodeDto = CatalogContext.Current.GetCatalogNodesDto(parentCatalogId); CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(0, 0, 0, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.CatalogNode | CatalogRelationResponseGroup.ResponseGroup.NodeEntry)); DeleteNodeRecursive(id, parentCatalogId, ref catalogNodeDto, ref catalogRelationDto); if (catalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(catalogRelationDto); } if (catalogNodeDto.HasChanges()) { CatalogContext.Current.SaveCatalogNode(catalogNodeDto); } } else // entry { DeleteEntryRecursive(id, parentCatalogId, parentCatalogNodeId); } } } } }
/// <summary> /// Pre-commit changes. /// </summary> /// <param name="context">The context.</param> public void PreCommitChanges(IDictionary context) { CatalogEntryDto dto = (CatalogEntryDto)context[_CatalogEntryDtoString]; CatalogRelationDto relationDto = (CatalogRelationDto)context[_CatalogRelationDtoString]; // Save Meta Data IDictionary dic = new ListDictionary(); MetaDataTab.MDContext = CatalogContext.MetaDataContext; MetaDataTab.SaveChanges(dic); byte[] serializedObject = ((MetaObjectSerialized)dic["MetaObjectSerialized"]).BinaryValue; dto.CatalogEntry[0][MetaObjectSerialized.SerializedFieldName] = serializedObject; // Update relations foreach (CatalogRelationDto.NodeEntryRelationRow row in relationDto.NodeEntryRelation) { if (row.CatalogEntryId == dto.CatalogEntry[0].CatalogEntryId && row.CatalogId == this.ParentCatalogId && row.CatalogNodeId == this.ParentCatalogNodeId) { row.SortOrder = Int32.Parse(SortOrder.Text); } } }
protected virtual void NodeEntryRelationRowChanging(object sender, CatalogRelationDto.NodeEntryRelationRowChangeEvent e) { if (e.Action == DataRowAction.Commit || e.Action == DataRowAction.Delete || e.Action == DataRowAction.Change) { if (e.Row.RowState == DataRowState.Added || e.Row.RowState == DataRowState.Deleted || e.Row.RowState == DataRowState.Modified) { int id = 0, catalogNodeId = 0; if (e.Row.RowState == DataRowState.Deleted) { id = (int)e.Row["CatalogEntryId", DataRowVersion.Original]; catalogNodeId = (int)e.Row["CatalogNodeId", DataRowVersion.Original]; } else { id = e.Row.CatalogEntryId; catalogNodeId = e.Row.CatalogNodeId; } UpdateSearchIndexWithParentCategoryIdChanges(id, catalogNodeId, e.Row.RowState); } } }
/// <summary> /// Clones the node entry. /// </summary> /// <param name="catalogId">The catalog id.</param> /// <param name="catalogNodeId">The catalog node id.</param> /// <param name="catalogEntryId">The catalog entry id.</param> /// <param name="targetCatalogId">The target catalog id.</param> /// <param name="targetCatalogNodeId">The target catalog node id.</param> private void CloneNodeEntry(int catalogId, int catalogNodeId, int catalogEntryId, int targetCatalogId, int targetCatalogNodeId) { using (TransactionScope scope = new TransactionScope()) { CatalogEntryDto catalogEntryDto = CatalogContext.Current.GetCatalogEntryDto(catalogEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryFull)); if (catalogEntryDto.CatalogEntry.Count > 0) { if (catalogId <= 0) { catalogId = catalogEntryDto.CatalogEntry[0].CatalogId; } if (targetCatalogId <= 0) { targetCatalogId = catalogId; } CatalogRelationDto catalogRelationDto = CatalogContext.Current.GetCatalogRelationDto(catalogId, catalogNodeId, catalogEntryId, String.Empty, new CatalogRelationResponseGroup(CatalogRelationResponseGroup.ResponseGroup.NodeEntry | CatalogRelationResponseGroup.ResponseGroup.CatalogEntry)); CatalogAssociationDto catalogAssociationDto = CatalogContext.Current.GetCatalogAssociationDtoByEntryId(catalogEntryId); CatalogEntryDto newCatalogEntryDto = new CatalogEntryDto(); newCatalogEntryDto.CatalogEntry.ImportRow(catalogEntryDto.CatalogEntry[0]); newCatalogEntryDto.CatalogEntry[0].SetAdded(); newCatalogEntryDto.CatalogEntry[0].Code = Guid.NewGuid().ToString(); if (catalogEntryDto.CatalogItemSeo.Count > 0) { foreach (CatalogEntryDto.CatalogItemSeoRow row in catalogEntryDto.CatalogItemSeo.Rows) { newCatalogEntryDto.CatalogItemSeo.ImportRow(row); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].SetAdded(); newCatalogEntryDto.CatalogItemSeo[newCatalogEntryDto.CatalogItemSeo.Count - 1].Uri = Guid.NewGuid().ToString() + ".aspx"; } } if (catalogEntryDto.Variation.Count > 0) { foreach (CatalogEntryDto.VariationRow row in catalogEntryDto.Variation.Rows) { newCatalogEntryDto.Variation.ImportRow(row); newCatalogEntryDto.Variation[newCatalogEntryDto.Variation.Count - 1].SetAdded(); } } if (catalogEntryDto.SalePrice.Count > 0) { foreach (CatalogEntryDto.SalePriceRow row in catalogEntryDto.SalePrice.Rows) { CatalogEntryDto.SalePriceRow newRow = newCatalogEntryDto.SalePrice.NewSalePriceRow(); newRow.ItemArray = row.ItemArray; newRow.ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; newCatalogEntryDto.SalePrice.Rows.Add(newRow); //newCatalogEntryDto.SalePrice.ImportRow(row); //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].ItemCode = newCatalogEntryDto.CatalogEntry[0].Code; //newCatalogEntryDto.SalePrice[newCatalogEntryDto.SalePrice.Count - 1].SetAdded(); } } if (catalogEntryDto.Inventory.Count > 0) { foreach (CatalogEntryDto.InventoryRow row in catalogEntryDto.Inventory.Rows) { newCatalogEntryDto.Inventory.ImportRow(row); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SetAdded(); newCatalogEntryDto.Inventory[newCatalogEntryDto.Inventory.Count - 1].SkuId = newCatalogEntryDto.CatalogEntry[0].Code; } } if (newCatalogEntryDto.HasChanges()) { CatalogContext.Current.SaveCatalogEntry(newCatalogEntryDto); } if (newCatalogEntryDto.CatalogEntry.Count > 0) { CatalogEntryDto.CatalogEntryRow entry = newCatalogEntryDto.CatalogEntry[0]; int newCatalogEntryId = entry.CatalogEntryId; int metaClassId = entry.MetaClassId; // load list of MetaFields for MetaClass MetaClass metaClass = MetaClass.Load(CatalogContext.MetaDataContext, metaClassId); MetaFieldCollection metaFields = metaClass.MetaFields; // cycle through each language and get meta objects CatalogContext.MetaDataContext.UseCurrentUICulture = false; string[] languages = GetCatalogLanguages(catalogId); if (languages != null) { foreach (string language in languages) { CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogContext.MetaDataContext.Language = language; MetaObject metaObject = MetaObject.Load(CatalogContext.MetaDataContext, catalogEntryDto.CatalogEntry[0].CatalogEntryId, metaClassId); MetaObject newMetaObject = MetaObject.NewObject(CatalogContext.MetaDataContext, newCatalogEntryId, metaClassId, FrameworkContext.Current.Profile.UserName); foreach (MetaField metaField in metaFields) { // skip system MetaFields if (!metaField.IsUser) { continue; } switch (metaField.DataType) { case MetaDataType.File: case MetaDataType.Image: case MetaDataType.ImageFile: MetaFile metaFile = (MetaFile)metaObject[metaField]; if (metaFile != null) { newMetaObject[metaField] = new MetaFile(metaFile.Name, metaFile.ContentType, metaFile.Buffer); } break; default: if (metaObject[metaField] != null) { newMetaObject[metaField] = metaObject[metaField]; } break; } } newMetaObject.AcceptChanges(CatalogContext.MetaDataContext); } } CatalogContext.MetaDataContext.UseCurrentUICulture = false; CatalogRelationDto newCatalogRelationDto = new CatalogRelationDto(); foreach (CatalogRelationDto.CatalogEntryRelationRow row in catalogRelationDto.CatalogEntryRelation.Rows) { if (row.ParentEntryId == catalogEntryId) { newCatalogRelationDto.CatalogEntryRelation.ImportRow(row); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.CatalogEntryRelation[newCatalogRelationDto.CatalogEntryRelation.Count - 1].ParentEntryId = newCatalogEntryId; } } if (targetCatalogNodeId > 0) { foreach (CatalogRelationDto.NodeEntryRelationRow row in catalogRelationDto.NodeEntryRelation.Rows) { if (row.CatalogEntryId == catalogEntryId) { newCatalogRelationDto.NodeEntryRelation.ImportRow(row); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].SetAdded(); newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogId = targetCatalogId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogNodeId = targetCatalogNodeId; newCatalogRelationDto.NodeEntryRelation[newCatalogRelationDto.NodeEntryRelation.Count - 1].CatalogEntryId = newCatalogEntryId; } } } if (newCatalogRelationDto.HasChanges()) { CatalogContext.Current.SaveCatalogRelationDto(newCatalogRelationDto); } CatalogAssociationDto newCatalogAssociationDto = new CatalogAssociationDto(); foreach (CatalogAssociationDto.CatalogAssociationRow row in catalogAssociationDto.CatalogAssociation.Rows) { newCatalogAssociationDto.CatalogAssociation.ImportRow(row); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].SetAdded(); newCatalogAssociationDto.CatalogAssociation[newCatalogAssociationDto.CatalogAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } foreach (CatalogAssociationDto.CatalogEntryAssociationRow row in catalogAssociationDto.CatalogEntryAssociation.Rows) { newCatalogAssociationDto.CatalogEntryAssociation.ImportRow(row); newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].SetAdded(); //newCatalogAssociationDto.CatalogEntryAssociation[newCatalogAssociationDto.CatalogEntryAssociation.Count - 1].CatalogEntryId = newCatalogEntryId; } if (newCatalogAssociationDto.HasChanges()) { CatalogContext.Current.SaveCatalogAssociation(newCatalogAssociationDto); } } } scope.Complete(); } }
private static string GetParentCatalogEntryId(int catalogEntryId, CatalogRelationDto relationDto) { string retVal = null; var entryRelationRows = relationDto.CatalogEntryRelation.Select(String.Format("ChildEntryId={0}", catalogEntryId)).Cast<CatalogRelationDto.CatalogEntryRelationRow>(); if (entryRelationRows.Count() > 0) { CatalogEntryDto parentEntryDto = CatalogContext.Current.GetCatalogEntryDto(entryRelationRows.First().ParentEntryId, new CatalogEntryResponseGroup(CatalogEntryResponseGroup.ResponseGroup.CatalogEntryInfo)); if (parentEntryDto.CatalogEntry.Count > 0) { retVal = parentEntryDto.CatalogEntry[0].Code; } } return retVal; }