/// <summary> /// Called when the item has deleted. /// </summary> /// <param name="args">The arguments.</param> public virtual void OnItemDeleted([NotNull] ClientPipelineArgs args) { Assert.ArgumentNotNull(args, "args"); foreach (Item item in this.GetItems(args)) { if (item.TemplateID == this.orderTemplateId) { return; } if (item.TemplateID != this.orderLineTemplateId) { continue; } string site = SiteUtils.GetSiteByItem(item.Parent); if (string.IsNullOrEmpty(site)) { return; } SiteContext siteContext = SiteContextFactory.GetSiteContext(site); using (new SiteContextSwitcher(siteContext)) { DomainModel.Orders.Order order = this.GetOrder(item.Parent); order.OrderLines.Remove(order.OrderLines.Where(ol => ol.Id == item.ID.ToString()).FirstOrDefault()); this.RecalculateOrder(order); } } }
/// <summary> /// Recalculates the order. /// </summary> /// <param name="order">The order.</param> protected virtual void RecalculateOrder(DomainModel.Orders.Order order) { if (order == null) { return; } OrderPriceCalculator manager = Context.Entity.Resolve <OrderPriceCalculator>(); manager.Recalculate(ref order); this.OrderManager.SaveOrder(order); }
/// <summary> /// Recalculates the order. /// </summary> /// <param name="item">The item.</param> protected virtual void RecalculateOrder([NotNull] Item item) { Assert.ArgumentNotNull(item, "item"); if (item.TemplateID.ToString().ToLower() == Settings.GetSetting("Ecommerce.Order.OrderItemTempalteId").ToLower() || item.TemplateID.ToString().ToLower() == Settings.GetSetting("Ecommerce.Order.OrderLineItemTempalteId").ToLower()) { string site = SiteUtils.GetSiteByItem(item); SiteContext siteContext = SiteContextFactory.GetSiteContext(site); using (new SiteContextSwitcher(siteContext)) { DomainModel.Orders.Order order = this.GetOrder(item); this.RecalculateOrder(order); } } }