public static Dictionary <ILineItem, IList <ValidationIssue> > ValidateCart(this ICart cart) { var lineItemValidator = ServiceLocator.Current.GetInstance <ILineItemValidator>(); var placedPriceProcessor = ServiceLocator.Current.GetInstance <IPlacedPriceProcessor>(); var inventoryProcessor = ServiceLocator.Current.GetInstance <IInventoryProcessor>(); var promotionEngine = ServiceLocator.Current.GetInstance <IPromotionEngine>(); /* if (cart.Name.Equals(DefaultWishListName)) * { * return new Dictionary<ILineItem, List<ValidationIssue>>(); * }*/ var validationIssues = new Dictionary <ILineItem, IList <ValidationIssue> >(); cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), lineItemValidator); cart.UpdatePlacedPriceOrRemoveLineItems(CustomerContext.Current.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), placedPriceProcessor); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), inventoryProcessor); cart.ApplyDiscounts(promotionEngine, new PromotionEngineSettings()); // Try to validate gift items inventory and don't catch validation issues. cart.UpdateInventoryOrRemoveLineItems((item, issue) => { }, inventoryProcessor); return(validationIssues); }
public Dictionary <ILineItem, List <ValidationIssue> > ValidateCart(ICart cart) { if (cart.Name.Equals(DefaultWishListName)) { return(new Dictionary <ILineItem, List <ValidationIssue> >()); } var validationIssues = new Dictionary <ILineItem, List <ValidationIssue> >(); cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator); cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor); cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); // Try to validate gift items inventory and don't catch validation issues. cart.UpdateInventoryOrRemoveLineItems((item, issue) => { if (!item.IsGift) { validationIssues.AddValidationIssues(item, issue); } else { validationIssues.AddValidationIssues(item, ValidationIssue.RemovedGiftDueToInsufficientQuantityInInventory); } }, _inventoryProcessor); return(validationIssues); }
public virtual IEnumerable <RewardDescription> ApplyDiscounts(ICart cart, RequestFulfillmentStatus requestedStatuses = RequestFulfillmentStatus.Fulfilled) { return(cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings { RequestedStatuses = requestedStatuses, ExclusionLevel = ExclusionLevel.Unit })); }
public void ValidateAndApplyCampaigns() { var validationIssues = new Dictionary <ILineItem, List <ValidationIssue> >(); _cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator); _cart.UpdatePlacedPriceOrRemoveLineItems(CustomerContext.Current.GetContactById(_cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); _cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor); _cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); _orderRepository.Save(_cart); }
public Dictionary <ILineItem, List <ValidationIssue> > ValidateCart(ICart cart) { if (cart.Name.Equals(DefaultWishListName)) { return(new Dictionary <ILineItem, List <ValidationIssue> >()); } var validationIssues = new Dictionary <ILineItem, List <ValidationIssue> >(); cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator); cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor); cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); return(validationIssues); }
public static Dictionary <ILineItem, ValidationIssue> ValidateCart(ICart cart) { var validationIssues = new Dictionary <ILineItem, ValidationIssue>(); cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.Add(item, issue)); cart.UpdatePlacedPriceOrRemoveLineItems(CustomerContext.Current.GetContactById(cart.CustomerId), (item, issue) => validationIssues.Add(item, issue), _placedPriceProcessor.Service); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.Add(item, issue)); cart.ApplyDiscounts(); cart.UpdateInventoryOrRemoveLineItems((item, issue) => {}); return(validationIssues); }
public bool AddCouponCode(ICart cart, string couponCode) { var couponCodes = cart.GetFirstForm().CouponCodes; if (couponCodes.Any(c => c.Equals(couponCode, StringComparison.OrdinalIgnoreCase))) { return(false); } couponCodes.Add(couponCode); var rewardDescriptions = cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); var appliedCoupons = rewardDescriptions.Where(r => r.Status == FulfillmentStatus.Fulfilled && !string.IsNullOrEmpty(r.Promotion.Coupon.Code)) .Select(c => c.Promotion.Coupon.Code); var couponApplied = appliedCoupons.Any(c => c.Equals(couponCode, StringComparison.OrdinalIgnoreCase)); if (!couponApplied) { couponCodes.Remove(couponCode); } return(couponApplied); }
public Dictionary <ILineItem, List <ValidationIssue> > ValidateCart(ICart cart) { var validationIssues = new Dictionary <ILineItem, List <ValidationIssue> >(); if (cart.Name.Equals(DefaultWishListName)) { cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); return(validationIssues); } cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator); cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor); var shipments = cart.GetFirstForm().Shipments; foreach (var shipment in shipments) { var dynamicLineItems = shipment.LineItems.Where(x => !string.IsNullOrEmpty(x.Properties[VariantOptionCodesProperty]?.ToString())); foreach (var item in dynamicLineItems) { var dynamicCodesStr = item.Properties[VariantOptionCodesProperty].ToString(); var dynamicCodes = dynamicCodesStr.Split(','); var contentLink = _referenceConverter.GetContentLink(item.Code); var variant = _contentLoader.Get <IContent>(contentLink) as DynamicVariant; var dynamicVariants = variant.VariantOptions.Where(x => dynamicCodes.Contains(x.Code)); var totalDynamicVariantsPrice = dynamicVariants.Sum(x => x.Prices.FirstOrDefault(p => p.Currency == cart.Currency.CurrencyCode).Amount); item.Properties["BasePrice"] = item.PlacedPrice; item.Properties["OptionPrice"] = totalDynamicVariantsPrice; item.PlacedPrice += totalDynamicVariantsPrice; cart.UpdateLineItemQuantity(shipment, item, item.Quantity); } } cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); return(validationIssues); }
private IHttpActionResult Finalize(ICart cart) { cart.ApplyDiscounts(); var total = _orderGroupCalculator.GetSubTotal(cart); var vippsPaymentMethodDto = PaymentHelper.GetVippsPaymentMethodDto().PaymentMethod.FirstOrDefault(); if (vippsPaymentMethodDto == null) { _logger.Warning("No payment method is setup for vipps"); return(GetUnsuccessfulResult("No payment method is setup for vipps")); } cart.GetFirstForm().Payments.Clear(); var payment = PaymentHelper.CreateVippsPayment(cart, total, vippsPaymentMethodDto.PaymentMethodId); cart.AddPayment(payment); _orderRepository.Save(cart); try { var paymentProcessingResults = cart.ProcessPayments().ToArray(); var successfulResult = paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful && !string.IsNullOrEmpty(x.RedirectUrl)); if (successfulResult != null) { return(GetSuccessfulResult(paymentProcessingResults.FirstOrDefault(x => x.IsSuccessful) ?? paymentProcessingResults.FirstOrDefault())); } return(GetUnsuccessfulResult(paymentProcessingResults.FirstOrDefault(x => !string.IsNullOrEmpty(x.Message))?.Message)); } catch (Exception ex) { _logger.Error($"{ex.Message} {ex.StackTrace}"); return(GetUnsuccessfulResult(ex.Message)); } }
static void Run(ICart cart, IDeliveryCostCalculator deliveryCostCalculator) { ICategory categoryConsumerElectronics = new Category("Consumer Electronics"); IProduct productAppleWatch = new Product(categoryConsumerElectronics, "Apple Watch", 2000.0); IProduct productAppleMacbookPro = new Product(categoryConsumerElectronics, "Apple Macbook Pro", 10000.0); ICategory categoryToysAndGames = new Category("Toys & Games"); IProduct productLego = new Product(categoryToysAndGames, "Lego Classic Pack", 100.0); cart.Add(productAppleWatch, 2); cart.Add(productAppleMacbookPro, 1); cart.Add(productLego, 10); ICollection <ICampaign> campaigns = new Collection <ICampaign>(); ICollection <ICoupon> coupons = new Collection <ICoupon>(); IRateCampaign inapplicableRateCampaign = new RateCampaign(categoryToysAndGames, "80% discount on Toys & Games category", .5, true, true, 50000.0, 20); IAmountCampaign lowAmountCampaign = new AmountCampaign(categoryConsumerElectronics, "100 TL discount on Toys & Games category", 100, false, false, 0.0, 0); IAmountCampaign bestAmountCampaign = new AmountCampaign(categoryConsumerElectronics, "1400 TL discount on Toys & Games category", 1400, false, true, 0.0, 3); IAmountCoupon inapplicableAmountCoupon = new AmountCoupon(5000, "5000 TL discount coupon", true, true, 50000, 50); IRateCoupon lowRateCoupon = new RateCoupon(.1, "10% discount coupon", false, false, 0.0, 0); IRateCoupon bestRateCoupon = new RateCoupon(.5, "50% discount coupon", true, true, 10000, 13); campaigns.Add(inapplicableRateCampaign); campaigns.Add(lowAmountCampaign); campaigns.Add(bestAmountCampaign); coupons.Add(inapplicableAmountCoupon); coupons.Add(lowRateCoupon); coupons.Add(bestRateCoupon); cart.ApplyDiscounts(campaigns, coupons); cart.DeliveryCost = deliveryCostCalculator.Calculate(cart); var response = cart.Print(); Console.Write(response); }
public IEnumerable <RewardDescription> ApplyDiscounts(ICart cart) { return(cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings())); }
public virtual void ApplyDiscounts(ICart cart) { cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); }
public void RemoveCouponCode(ICart cart, string couponCode) { cart.GetFirstForm().CouponCodes.Remove(couponCode); cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); }
public bool AddCouponCode(ICart cart, string couponCode) { var couponCodes = cart.GetFirstForm().CouponCodes; if (couponCodes.Any(c => c.Equals(couponCode, StringComparison.OrdinalIgnoreCase))) { return false; } couponCodes.Add(couponCode); var rewardDescriptions = cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); var appliedCoupons = rewardDescriptions.Where(r => r.Status == FulfillmentStatus.Fulfilled && !string.IsNullOrEmpty(r.Promotion.Coupon.Code)) .Select(c => c.Promotion.Coupon.Code); var couponApplied = appliedCoupons.Any(c => c.Equals(couponCode, StringComparison.OrdinalIgnoreCase)); if (!couponApplied) { couponCodes.Remove(couponCode); } return couponApplied; }
public Dictionary<ILineItem, List<ValidationIssue>> ValidateCart(ICart cart) { if (cart.Name.Equals(DefaultWishListName)) { return new Dictionary<ILineItem, List<ValidationIssue>>(); } var validationIssues = new Dictionary<ILineItem, List<ValidationIssue>>(); cart.ValidateOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _lineItemValidator); cart.UpdatePlacedPriceOrRemoveLineItems(_customerContext.GetContactById(cart.CustomerId), (item, issue) => validationIssues.AddValidationIssues(item, issue), _placedPriceProcessor); cart.UpdateInventoryOrRemoveLineItems((item, issue) => validationIssues.AddValidationIssues(item, issue), _inventoryProcessor); cart.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings()); return validationIssues; }