Ticket 100050: [Integria MVP] 3.4. Product details page changes
Need to Get details from GetProducts and save Product Enrichments on product index run
to do
Code idea get from: CategoryImportController > LinkProductPages()
public class ExtendedOfflineProductProvider : OfflineProductProvider, IExtendedProductProvider { /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Gets the admin data manager. /// </summary> protected virtual AdminDataManager DataManager { get { return AdminDataManager.Current; } } public override void SaveProducts(IEnumerable<IProduct> products) { base.SaveProducts(products); /// Ticket 100050: [Integria MVP] 3.4. Product details page changes LinkProductPages(products); } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Links the product pages to the currently imported navigation item. /// below Code from: CategoryImportController > LinkProductPages() /// </summary> /// <param name="products"></param> protected virtual void LinkProductPages(IEnumerable<IProduct> products) { using (var unit = DataManager.CreateUnitOfWork()) { var productIds = products.Select(r => r.Id).ToArray(); var enrichments = CommerceFrameworkBase.ProductContent.Provider.GetProductEnrichments(productIds) .ToDictionary(i => i.ProductId, StringComparer.OrdinalIgnoreCase); foreach (var product in products) { IProductEnrichment enrichment; if (enrichments.TryGetValue(product.Id, out enrichment)) { var IsValid = FillProductDetailLeveDescriptions(product, enrichment); if (IsValid) { Update(enrichment); } } else { enrichment = ObjectFactory.Create<IProductEnrichment>(); enrichment.ProductId = product.Id; // Save New Enrichments var IsValid = FillProductDetailLeveDescriptions(product, enrichment); if (IsValid) { Insert(enrichment); } } } unit.Flush(); unit.Commit(); } } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// This method will Fill Product level descriptions and check validity of updated Products. /// </summary> /// <param name="product">product</param> /// <param name="enrichment">enrichment</param> /// isChecked :Flag use to identify current product need to be updated or not. True:Should insert or update, Else :ignore /// <returns></returns> private bool FillProductDetailLeveDescriptions(IProduct product, IProductEnrichment enrichment) { bool isChecked = false; // Flag use to identify current product need to be updated or not. if (!string.IsNullOrEmpty(((Product)product).Indications)) { ((ProductEnrichment)enrichment).Description1 = ((Product)product).Indications; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).Dosage)) { ((ProductEnrichment)enrichment).Description2 = ((Product)product).Dosage; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).Indications)) { ((ProductEnrichment)enrichment).Description1 = ((Product)product).Indications; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).Cautions)) { ((ProductEnrichment)enrichment).Description3 = ((Product)product).Cautions; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).CompanionTherapy)) { ((ProductEnrichment)enrichment).Description4 = ((Product)product).CompanionTherapy; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).BeneficialFor)) { ((ProductEnrichment)enrichment).Description5 = ((Product)product).BeneficialFor; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).Ingredients)) { ((ProductEnrichment)enrichment).Description6 = ((Product)product).Ingredients; isChecked = true; } if (!string.IsNullOrEmpty(((Product)product).OtherInfo)) { ((ProductEnrichment)enrichment).Description7 = ((Product)product).OtherInfo; isChecked = true; } ((ProductEnrichment)enrichment).LevelId1 = ProductLevel.Level01; ((ProductEnrichment)enrichment).LevelId2 = ProductLevel.Level02; ((ProductEnrichment)enrichment).LevelId3 = ProductLevel.Level03; ((ProductEnrichment)enrichment).LevelId4 = ProductLevel.Level04; ((ProductEnrichment)enrichment).LevelId5 = ProductLevel.Level05; ((ProductEnrichment)enrichment).LevelId6 = ProductLevel.Level06; ((ProductEnrichment)enrichment).LevelId7 = ProductLevel.Level07; return isChecked; } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Updates the specified entity with invoking all registered persistence handlers. /// All operations are executed in a single transaction. /// </summary> /// <param name="entity">The entity.</param> protected virtual void Update(object entity) { using (var unit = DataManager.CreateUnitOfWork()) { OnBeforeUpdate(entity); DataManager.Save(entity); OnAfterUpdate(entity); unit.Commit(); } } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Inserts the specified entity with invoking all registered persistence handlers. /// All operations are executed in a single transaction. /// </summary> /// <param name="entity">The entity.</param> protected virtual void Insert(object entity) { using (var unit = DataManager.CreateUnitOfWork()) { OnBeforeSave(entity); DataManager.Save(entity); OnAfterSave(entity); unit.Commit(); } } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Called before an entity is updated in the datastore. /// If not overridden in a derived class, invokes the corresponding event on all registered persistence handlers. /// </summary> /// <param name="entity">The entity.</param> protected virtual void OnBeforeUpdate(object entity) { PersistenceHandlers.Handle(h => h.OnBeforeUpdate(entity)); } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Called after an entity has been updated in the datastore. /// If not overridden in a derived class, invokes the corresponding event on all registered persistence handlers. /// </summary> /// <param name="entity">The entity.</param> protected virtual void OnAfterUpdate(object entity) { PersistenceHandlers.Handle(h => h.OnAfterUpdate(entity)); } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Called before a new entity is saved to the datastore. /// If not overridden in a derived class, invokes the corresponding event on all registered persistence handlers. /// </summary> /// <param name="entity">The entity.</param> protected virtual void OnBeforeSave(object entity) { PersistenceHandlers.Handle(h => h.OnBeforeSave(entity)); } /// Ticket 100050: [Integria MVP] 3.4. Product details page changes /// <summary> /// Called after a new entity has been saved to the datastore. /// If not overridden in a derived class, invokes the corresponding event on all registered persistence handlers. /// </summary> /// <param name="entity">The entity.</param> protected virtual void OnAfterSave(object entity) { PersistenceHandlers.Handle(h => h.OnAfterSave(entity)); } }
