/// <summary> /// Adds the discount to line item. /// </summary> /// <param name="order">The order.</param> /// <param name="itemRecord">The item record.</param> /// <param name="entryCode">The entry code.</param> /// <param name="itemDiscount">The item discount.</param> /// <param name="orderLevelDiscount">The order level discount.</param> private void AddDiscountToLineItem(OrderGroup order, PromotionItemRecord itemRecord, PromotionEntry promotionEntry, decimal itemDiscount, decimal orderLevelDiscount) { LineItem item = FindLineItemByPromotionEntry(order, promotionEntry); if (item != null) { // Add line item properties item.LineItemDiscountAmount += itemDiscount; item.OrderLevelDiscountAmount += orderLevelDiscount; item.ExtendedPrice = item.ListPrice * item.Quantity - item.LineItemDiscountAmount - item.OrderLevelDiscountAmount; if (itemRecord.PromotionItem.DataRow.PromotionGroup.Equals(PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key, StringComparison.OrdinalIgnoreCase)) { LineItemDiscount discount = FindLineItemDiscountById(order, itemRecord.PromotionItem.DataRow.PromotionId, item.LineItemId); if (discount == null) { discount = new LineItemDiscount(); } discount.DiscountAmount = itemRecord.PromotionItem.DataRow.OfferAmount; discount.DiscountCode = itemRecord.PromotionItem.DataRow.CouponCode; discount.DiscountName = itemRecord.PromotionItem.DataRow.Name; discount.DiscountValue = itemRecord.PromotionItem.DataRow.OfferAmount; discount.DisplayMessage = GetDisplayName(itemRecord.PromotionItem.DataRow, Thread.CurrentThread.CurrentCulture.Name); discount.LineItemId = item.LineItemId; discount.DiscountId = itemRecord.PromotionItem.DataRow.PromotionId; item.Discounts.Add(discount); } } }
private void AddDiscountToEntity(StorageEntity entity, PromotionReward reward, decimal discountAmount) { var orderForm = entity as OrderForm; var lineItem = entity as LineItem; var shipment = entity as Shipment; if (orderForm != null && reward is CartSubtotalReward) { var discount = orderForm.Discounts.FirstOrDefault(x => x.PromotionId == reward.PromotionId); if (discount == null) { discount = new OrderFormDiscount { PromotionId = reward.PromotionId, DiscountName = reward.Promotion.Name, DisplayMessage = reward.Promotion.Description, OrderFormId = orderForm.OrderFormId, DiscountCode = reward.Promotion.Coupon != null ? reward.Promotion.Coupon.Code : null }; orderForm.Discounts.Add(discount); } discount.DiscountAmount += discountAmount; } else if (lineItem != null && reward is CatalogItemReward) { var discount = lineItem.Discounts.FirstOrDefault(x => x.PromotionId == reward.PromotionId); if (discount == null) { discount = new LineItemDiscount { PromotionId = reward.PromotionId, DiscountName = reward.Promotion.Name, DisplayMessage = reward.Promotion.Description, LineItemId = lineItem.LineItemId, DiscountCode = reward.Promotion.Coupon != null ? reward.Promotion.Coupon.Code : null }; lineItem.Discounts.Add(discount); } discount.DiscountAmount += discountAmount; } else if (shipment != null && reward is ShipmentReward) { var discount = shipment.Discounts.FirstOrDefault(x => x.PromotionId == reward.PromotionId); if (discount == null) { discount = new ShipmentDiscount { PromotionId = reward.PromotionId, DiscountName = reward.Promotion.Name, DisplayMessage = reward.Promotion.Description, ShipmentId = shipment.ShipmentId, DiscountCode = reward.Promotion.Coupon != null ? reward.Promotion.Coupon.Code : null }; shipment.Discounts.Add(discount); } discount.DiscountAmount += discountAmount; } }
/// <summary> /// Creates the line item discount. /// </summary> /// <returns></returns> public static LineItemDiscount CreateLineItemDiscount() { LineItemDiscount discount = new LineItemDiscount(); discount.DisplayMessage = "Line Item Discount"; discount.DiscountName = "@New Discount"; discount.DiscountId = -1; discount.DiscountAmount = 12; discount.DiscountCode = ""; return(discount); }
private void AddDiscountToLineItem(OrderGroup order, PromotionItemRecord itemRecord, PromotionEntry promotionEntry, decimal itemDiscount, decimal orderLevelDiscount) { orderLevelDiscount = Math.Floor(orderLevelDiscount * 100) * 0.01m; LineItem item = FindLineItemByPromotionEntry(order, promotionEntry); if (item != null) { //reset gift line item discount if (IsGiftLineItem(item)) { item.PlacedPrice = promotionEntry.CostPerEntry; item.LineItemDiscountAmount = itemDiscount; item.OrderLevelDiscountAmount = 0; item.ExtendedPrice = item.PlacedPrice; } else { // Add line item properties item.LineItemDiscountAmount += itemDiscount; item.OrderLevelDiscountAmount += orderLevelDiscount; item.ExtendedPrice = item.PlacedPrice * item.Quantity - item.LineItemDiscountAmount - item.OrderLevelDiscountAmount; } if (itemRecord.PromotionItem.DataRow.PromotionGroup.Equals(PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key, StringComparison.OrdinalIgnoreCase) || itemRecord.PromotionReward is GiftPromotionReward || (itemRecord.PromotionItem.DataRow.PromotionGroup.Equals(PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Order).Key, StringComparison.OrdinalIgnoreCase) && itemRecord.PromotionReward.RewardType == PromotionRewardType.EachAffectedEntry)) { LineItemDiscount discount = FindLineItemDiscountById(order, itemRecord.PromotionItem.DataRow.PromotionId, item.LineItemId); if (discount == null) { discount = new LineItemDiscount(); item.Discounts.Add(discount); } var discountName = itemRecord.PromotionItem.DataRow.Name; if (itemRecord.PromotionReward is GiftPromotionReward) { discount.DiscountName = GetGiftPromotionName(itemRecord); } else { discount.DiscountName = String.Format("{0}{1}", itemRecord.PromotionItem.DataRow.Name, itemRecord.PromotionItem.DataRow.OfferType == 1 ? ":PercentageBased" : ":ValueBased"); } discount.DiscountAmount = itemRecord.PromotionReward.AmountOff; discount.DiscountCode = itemRecord.PromotionItem.DataRow.CouponCode; discount.DiscountValue = itemDiscount; // use the promotion name if the localized display message is null or empty discount.DisplayMessage = GetDisplayName(itemRecord.PromotionItem.DataRow, Thread.CurrentThread.CurrentCulture.Name); if (string.IsNullOrEmpty(discount.DisplayMessage)) discount.DisplayMessage = itemRecord.PromotionItem.DataRow.Name; discount.LineItemId = item.LineItemId; discount.DiscountId = itemRecord.PromotionItem.DataRow.PromotionId; } } }
public LineItemBuilder Discount(LineItemDiscount discount) { _lineItem.Discounts.Add(discount); return(this); }
private void AddDiscountToLineItem(OrderGroup order, PromotionItemRecord itemRecord, PromotionEntry promotionEntry, decimal itemDiscount, decimal orderLevelDiscount) { itemDiscount = _currency.Round(itemDiscount); orderLevelDiscount = _currency.Round(orderLevelDiscount); LineItem item = FindLineItemByPromotionEntry(order, promotionEntry); if (item != null) { //reset gift line item discount if (IsGiftLineItem(item)) { item.PlacedPrice = promotionEntry.CostPerEntry; item.LineItemDiscountAmount = itemDiscount; item.OrderLevelDiscountAmount = 0; item.ExtendedPrice = item.PlacedPrice; } else { // Add line item properties item.LineItemDiscountAmount += itemDiscount; item.OrderLevelDiscountAmount += orderLevelDiscount; item.ExtendedPrice = item.PlacedPrice * item.Quantity - item.LineItemDiscountAmount - item.OrderLevelDiscountAmount; } if (itemRecord.PromotionItem.DataRow.PromotionGroup.Equals(PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Entry).Key, StringComparison.OrdinalIgnoreCase) || itemRecord.PromotionReward is GiftPromotionReward || (itemRecord.PromotionItem.DataRow.PromotionGroup.Equals(PromotionGroup.GetPromotionGroup(PromotionGroup.PromotionGroupKey.Order).Key, StringComparison.OrdinalIgnoreCase) && itemRecord.PromotionReward.RewardType == PromotionRewardType.EachAffectedEntry)) { LineItemDiscount discount = FindLineItemDiscountById(order, itemRecord.PromotionItem.DataRow.PromotionId, item.LineItemId); if (discount == null) { discount = new LineItemDiscount(); item.Discounts.Add(discount); } var discountName = itemRecord.PromotionItem.DataRow.Name; if (itemRecord.PromotionReward is GiftPromotionReward) { discount.DiscountName = GetGiftPromotionName(itemRecord); } else { discount.DiscountName = String.Format("{0}{1}", itemRecord.PromotionItem.DataRow.Name, itemRecord.PromotionItem.DataRow.OfferType == 1 ? ":PercentageBased" : ":ValueBased"); } discount.DiscountAmount = itemRecord.PromotionReward.AmountOff; discount.DiscountCode = itemRecord.PromotionItem.DataRow.CouponCode; discount.DiscountValue = itemDiscount; // use the promotion name if the localized display message is null or empty discount.DisplayMessage = GetDisplayName(itemRecord.PromotionItem.DataRow, Thread.CurrentThread.CurrentCulture.Name); if (string.IsNullOrEmpty(discount.DisplayMessage)) { discount.DisplayMessage = itemRecord.PromotionItem.DataRow.Name; } discount.LineItemId = item.LineItemId; discount.DiscountId = itemRecord.PromotionItem.DataRow.PromotionId; } } }