/// <summary> /// Creates a SannsynUpdateEntityModel with customerId, buy tag and list of entries /// </summary> /// <param name="lineItem">LineItem with entry</param> /// <param name="customerId">Customer buying</param> /// <returns></returns> private SannsynUpdateEntityModel CreateSannsynObject(LineItem lineItem, Guid customerId) { var entry = lineItem.GetEntryContent <EntryContentBase>(); if (entry == null) { // Entry could have been deleted after order was placed return(null); } var parent = entry.GetParent(); string code = parent == null ? entry.Code : parent.Code; SannsynUpdateEntityModel model = new SannsynUpdateEntityModel(); model.Customer = customerId.ToString(); model.Tags = new List <string> { Constants.Tags.Buy }; model.EntityIDs = new List <string> { code }; model.Time = lineItem.Modified.ToJavaTimeStamp(); model.Boost = (float)0.0; model.Number = (int)lineItem.Quantity; return(model); }
protected virtual List <SannsynUpdateEntityModel> GetUpdateModels(Dictionary <string, EntryContentBase> indexableContentItems) { List <SannsynUpdateEntityModel> sannsynObjects = new List <SannsynUpdateEntityModel>(); foreach (var indexableContentItem in indexableContentItems) { EntryContentBase product = indexableContentItem.Value; List <string> parentCategories = product.GetParentCategoryCodes(product.Language.Name); SannsynUpdateEntityModel model = new SannsynUpdateEntityModel(); model.Customer = product.Code; model.Tags = new List <string> { Constants.Tags.ItemCat }; model.EntityIDs = parentCategories; sannsynObjects.Add(model); } return(sannsynObjects); }
/// <summary> /// Creates a update model to Sannsyn, with a list of entry/variation codes, and service name /// </summary> /// <param name="orderGroup">Order to get lineitems from</param> public void AddLineItemsToSannsyn(OrderGroup orderGroup) { LineItemCollection lineItems = orderGroup.OrderForms.First().LineItems; List <SannsynUpdateEntityModel> sannsynObjects = new List <SannsynUpdateEntityModel>(); foreach (LineItem lineItem in lineItems) { SannsynUpdateEntityModel model = CreateSannsynObject(lineItem, orderGroup.CustomerId); if (model != null) { sannsynObjects.Add(model); } } // Make sure we have something to index if (sannsynObjects.Any()) { SannsynUpdateModel sannsynModel = new SannsynUpdateModel(); sannsynModel.Service = _configuration.Service; sannsynModel.Updates = sannsynObjects; _sannsynUpdateService.SendToSannsyn(sannsynModel); } }