protected override RewardDescription Evaluate( Free2 promotionData , PromotionProcessorContext context) { // RequiredQty & FreeItem in the model IOrderForm orderForm = context.OrderGroup.GetFirstForm(); IEnumerable <ILineItem> lineItems = context.OrderGroup.GetFirstForm().GetAllLineItems(); ContentReference freeItem = promotionData.FreeItem.Items.First(); // Using "First()" just to show string freeItemCode = _referenceConverter.GetCode(freeItem); FulfillmentStatus status = promotionData.RequiredQty.GetFulfillmentStatus( orderForm, _collectionTargetEvaluator, _fulfillmentEvaluator); IList <string> applicableEntryCodes = _collectionTargetEvaluator.GetApplicableCodes( lineItems, promotionData.RequiredQty.Items, false); string description = promotionData.Description; return(RewardDescription.CreateFreeItemReward( status , GetRedemptionDescriptions(promotionData, context, applicableEntryCodes) , promotionData , description + " : " + freeItemCode)); // description, just to show }
private void SetupPromotionEngine() { _promotionEngineMock = new Mock <IPromotionEngine>(); _discountAmount = 0.3m; var lineItem = new InMemoryLineItem { Code = "code1", Quantity = 1, LineItemDiscountAmount = _discountAmount }; var affectedItems = new[] { lineItem }; var redemptionDescription = new FakeRedemptionDescription(affectedItems.Select(item => new AffectedEntries(new List <PriceEntry> { new PriceEntry(item) }))); var rewardDescription = RewardDescription.CreateMoneyReward(FulfillmentStatus.Fulfilled, new [] { redemptionDescription }, null, 0m, null); _promotionEngineMock .Setup(x => x.Evaluate( It.IsAny <IEnumerable <ContentReference> >(), It.IsAny <IMarket>(), It.IsAny <Currency>(), RequestFulfillmentStatus.Fulfilled )) .Returns(new RewardDescription[] { rewardDescription }); }
public static TaxType GetTaxType(this RewardDescription description) { switch (description.Promotion.DiscountType) { case DiscountType.Shipping: return(TaxType.ShippingTax); default: return(TaxType.SalesTax); } }
public void Index_AppliablePromotionsAlwaysDisable_ShouldNotSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var notFulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.NotFulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny <PromotionEngineSettings>())).Returns(new[] { notFulfilledRewardDesciption }); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Never); }
public static Money GetSavedAmountIncludingTax(this RewardDescription description, MarketId marketId, Currency currency, IOrderAddress address, TaxUtility taxUtility = null) { var initialAmount = new Money(description.SavedAmount, currency); if (taxUtility == null) { taxUtility = ServiceLocator.Current.GetInstance <TaxUtility>(); } var taxCategoryId = taxUtility.GetDefaultTaxCategoryId(); return(taxUtility.GetPriceWithTax(initialAmount, marketId, address, GetTaxType(description), taxCategoryId)); }
public void Index_AppliablePromotionsChangeFromDisableToEnable_ShouldSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var fulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.Fulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny <PromotionEngineSettings>())).Returns(new[] { fulfilledRewardDesciption }); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny <PromotionEngineSettings>())).Callback(() => _cart.GetFirstForm().Promotions.Add(new PromotionInformation())); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Once); }
public static Money GetSavedAmountIncludingTax(this RewardDescription description, ICart cart, TaxUtility taxUtility = null) { var initialAmount = new Money(description.SavedAmount, cart.Currency); if (cart.PricesIncludeTax) { return(initialAmount); } var shipment = cart.GetFirstShipment(); var shippingAddress = shipment?.ShippingAddress; return(GetSavedAmountIncludingTax(description, cart.MarketId, cart.Currency, shippingAddress, taxUtility)); }
public void AddCouponCode_WhenCouponCodeIsNotAppliedToPromotion_ShouldReturnFalse() { var couponCode = "IDONTEXIST"; _promotionEngineMock .Setup(x => x.Run(It.IsAny <IOrderGroup>(), It.IsAny <PromotionEngineSettings>())) .Returns(new[] { RewardDescription.CreatePercentageReward(FulfillmentStatus.Fulfilled, null, new PromotionForTest(), 10, string.Empty) }); var result = _subject.AddCouponCode(_cart, couponCode); Assert.False(result); }
private OmniumDiscount MapDiscount( RewardDescription reward, Currency currency, IMarket market, IOrderAddress address) { var discountValue = market.PricesIncludeTax ? reward.SavedAmount : reward.SavedAmount; //reward.GetSavedAmountIncludingTax(market.MarketId, currency, address); return(new OmniumDiscount { DiscountAmount = discountValue, DiscountCode = reward.AppliedCoupon, DiscountName = reward.Promotion.Name, DiscountValue = discountValue, RewardType = reward.RewardType.ToString(), DiscountType = reward.Promotion.DiscountType.ToString() }); }
protected override RewardDescription Evaluate( FreeItemPromotion data, PromotionProcessorContext ctx) { // is this used IEnumerable <ContentReference> targetItems = data.DiscountTargets.Items.ToList(); // get which LI this promo is for var targets = data.DiscountTargets; var freeItem = data.FreeItem.Items.First().ToReferenceWithoutVersion(); //var freeItemCode = ServiceLocator.Current.GetInstance<ReferenceConverter>().GetCode(freeItem); var freeItemCode = _refConv.Service.GetCode(freeItem); // Have RefConv. below IOrderForm form = ctx.OrderForm; var lineItems = form.GetAllLineItems(); //var lineItems = GetLineItems(ctx.OrderForm.get); // not anymore var matchRecursive = false; // mandatory var skuCodes = _targetEvaluator.GetApplicableCodes( lineItems, targets.Items, targets.MatchRecursive); // get one if kicked in, 0 if not FulfillmentStatus status = data.RequiredQty.GetFulfillmentStatus(form, _targetEvaluator, _fulfillmentEvaluator); List <RewardDescription> rewardDescriptions = new List <RewardDescription>(); List <RedemptionDescription> redemptionDescriptions = new List <RedemptionDescription>(); // GetAllAffectedItems is the only method - name was changed var affectedItems = _targetEvaluator.GetApplicableCodes(lineItems, targetItems, matchRecursive); // only a single method to use on the "FulfillmentEvaluator" - out commented //var status = FulfillmentEvaluator.GetStatusForBuyQuantityPromotion(affectedItems.Select(x => x.LineItem) // , data.RequiredQty,0); // "Required" in the model // This way (demo) of using it is maybe not the intended, thought of like "buy 5 - get one for free" // ...have to load the gift and add it to the cart // ...have "Money" and "Percentage" return(RewardDescription.CreateFreeItemReward( status , GetRedemptions(skuCodes, data, ctx) , data , data.Description + " : " + freeItemCode //status, //affectedItems, //data //GetRewardDescriptionText(tagets, status, data) )); }
public void Index_NoPromotionAndUseBillingAddressForShipment_ShouldSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var fulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.Fulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny<PromotionEngineSettings>())).Returns(new[] { fulfilledRewardDesciption }); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny<PromotionEngineSettings>())).Callback(() => _cart.GetFirstForm().Promotions.Clear()); _checkoutViewModelFactoryMock .Setup(x => x.CreateCheckoutViewModel(It.IsAny<ICart>(), It.IsAny<CheckoutPage>(), It.IsAny<PaymentMethodViewModel<PaymentMethodBase>>())) .Returns((ICart cart, CheckoutPage currentPage, PaymentMethodViewModel<PaymentMethodBase> paymentMethodViewModel) => CreateCheckoutViewModelWithAddressIds(currentPage, paymentMethodViewModel, true)); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Once); }
protected override RewardDescription Evaluate(FreeStuffPromotion promotionData, PromotionProcessorContext context) { var condition = promotionData.RequiredQty; var lineItems = context.OrderForm.GetAllLineItems(); var skuCodes = _collectionTargetEvaluator.GetApplicableCodes(lineItems, condition.Items, false); var status = promotionData.RequiredQty.GetFulfillmentStatus(context.OrderForm, _collectionTargetEvaluator, _fulfillmentEvaluator); var redemptions = new List <RedemptionDescription>(); if (status == FulfillmentStatus.Fulfilled) { var entries = _giftItemFactory.CreateGiftItems(promotionData.FreeItems, context); redemptions.Add(CreateRedemptionDescription(entries)); } return(RewardDescription.CreateGiftItemsReward(status, redemptions, promotionData, status.GetRewardDescriptionText())); }
public void Index_NoPromotionAndUseShippingAddressForShipment_ShouldSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var fulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.Fulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny <PromotionEngineSettings>())).Returns(new[] { fulfilledRewardDesciption }); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny <PromotionEngineSettings>())).Callback(() => _cart.GetFirstForm().Promotions.Clear()); _checkoutViewModelFactoryMock .Setup(x => x.CreateCheckoutViewModel(It.IsAny <ICart>(), It.IsAny <CheckoutPage>(), It.IsAny <PaymentMethodViewModel <PaymentMethodBase> >())) .Returns((ICart cart, CheckoutPage currentPage, PaymentMethodViewModel <PaymentMethodBase> paymentMethodViewModel) => CreateCheckoutViewModelWithAddressIds(currentPage, paymentMethodViewModel, false)); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Once); }
public override RewardDescription Evaluate(IOrderForm orderForm, BuyXFromCategoryGetProductForFree promotionData, PromotionProcessorContext context) { IEnumerable <ILineItem> items = GetLineItemsInOrder(orderForm); List <AffectedItem> affectedItems = new List <AffectedItem>(); var lineItemCategories = items.Select(i => new { Quantity = i.Quantity, NodesForEntry = GetNodesForEntry(i.Code), Code = i.Code, LineItem = i }); decimal numberOfItemsInPromotionCategory = 0; NodeContent category = _contentLoader.Get <NodeContent>(promotionData.Category); foreach (var lineItemCategory in lineItemCategories) { if (lineItemCategory.NodesForEntry.Contains(category.Code)) { numberOfItemsInPromotionCategory += lineItemCategory.Quantity; // TODO: This has not yet been implemented //affectedItems.Add( // new AffectedItem( // _referenceConverter.GetContentLink(lineItemCategory.Code), // lineItemCategory.LineItem, // lineItemCategory.Quantity)); } } FulfillmentStatus fulfillment = this.GetFulfillment(numberOfItemsInPromotionCategory, promotionData.Threshold); // context.OrderGroup //if(fulfillment == FulfillmentStatus.Fulfilled) //{ // affectedItems.Add( // new AffectedItem( // promotionData // _referenceConverter.GetContentLink(lineItemCategory.Code), // lineItemCategory.LineItem, // lineItemCategory.Quantity)); //} return(RewardDescription.CreateFreeItemReward(fulfillment, affectedItems, promotionData, "Got something for free")); // return new RewardDescription(fulfillment, affectedItems, promotionData, 0, 0, RewardType.Free, "Got something for free"); }
Injected <ReferenceConverter> _refConv; // lazy dev - fix protected override RewardDescription Evaluate( FreeItemPromotion data, PromotionProcessorContext ctx) { // is this used IEnumerable <ContentReference> targetItems = data.DiscountTargets.Items.ToList(); // get which LI this promo is for // data - the promotion itself, and the custom model provided // ctx - gives OrderGroup, OrderForm, Prices (PriceMatrix) & some calc var targets = data.DiscountTargets; var freeItem = data.FreeItem.Items.First().ToReferenceWithoutVersion(); // just to show some var freeItemCode = _refConv.Service.GetCode(freeItem); // Have RefConv. injected below IOrderForm form = ctx.OrderForm; var lineItems = form.GetAllLineItems(); //var lineItems = GetLineItems(ctx.OrderForm.get); // not anymore var matchRecursive = false; // mandatory IList <string> skuCodes = _targetEvaluator.GetApplicableCodes( lineItems, targets.Items, targets.MatchRecursive); // get one if kicked in, 0 if not FulfillmentStatus status = data.RequiredQty.GetFulfillmentStatus( form, _targetEvaluator, _fulfillmentEvaluator); // extension method List <RewardDescription> rewardDescriptions = new List <RewardDescription>(); List <RedemptionDescription> redemptionDescriptions = new List <RedemptionDescription>(); // GetAllAffectedItems is the only method - name was changed var affectedItems = _targetEvaluator.GetApplicableCodes(lineItems, targetItems, matchRecursive); // "FulfillmentEvaluator" - not used much here - gives different statuses //_fulfillmentEvaluator.GetStatusForSpendAmountPromotion() //... as an example // This way (demo) of using it is maybe not the intended, thought of like // "buy 5 - get one for free" // ...have to load the gift and add it to the cart // ...have "Money", "Percentage", GiftItem, FreeItem etc. return(RewardDescription.CreateFreeItemReward( status , GetRedemptions(skuCodes, data, ctx) // explanation below , data , data.Description + " : " + freeItemCode )); }
public void AddCouponCode_WhenPromotionWithCodeExists_ShouldReturnTrue() { var couponCode = "IBUYALOT"; _promotionEngineMock .Setup(x => x.Run(It.IsAny <IOrderGroup>(), It.IsAny <PromotionEngineSettings>())) .Returns(new[] { RewardDescription.CreatePercentageReward(FulfillmentStatus.Fulfilled, null, new PromotionForTest { Coupon = new CouponData { Code = couponCode } }, 10, string.Empty) }); var result = _subject.AddCouponCode(_cart, couponCode); Assert.True(result); }
protected override RewardDescription Evaluate(VisitorGroupDiscountPromotion promotionData, PromotionProcessorContext context) { // get all items from the cart var lineItems = this.GetLineItems(context.OrderForm).ToList(); // get any codes that the promotion applies to (check visitor group to filter) Guid visitorGroupGuid; Guid.TryParse(promotionData.VisitorGroup, out visitorGroupGuid); var user = HttpContext.Current.User; var visitorGroupHelper = new VisitorGroupHelper(this._visitorGroupRoleRepository.Service); var visitorGroup = this._visitorGroupRepository.Service.Load(visitorGroupGuid); var isVisitorGroup = visitorGroupHelper.IsPrincipalInGroup(user, visitorGroup.Name); var applicableCodes = isVisitorGroup ? this._targetEvaluator.Service.GetApplicableCodes(lineItems, promotionData.Entries, true).ToList() : new List <string>(); // check to see whether the promotion has been fulfilled var fulfillmentStatus = this._fulfillmentEvaluator.Service .GetStatusForBuyFromCategoryPromotion(applicableCodes, lineItems); // get redemption status var redemptions = new List <RedemptionDescription>(); var affectedEntries = context.EntryPrices.ExtractEntries(applicableCodes, 1); if (affectedEntries != null) { redemptions.Add(this.CreateRedemptionDescription(affectedEntries)); } return(RewardDescription.CreatePercentageReward( fulfillmentStatus, redemptions, promotionData, promotionData.Percentage, fulfillmentStatus.GetRewardDescriptionText(this._localizationService.Service))); }
/* RewardDescription is "checking" whether the promotion was fulfilled (or not, or partially), * ...which items the promotion was applied to... * ...the fake-cart is taken care of) * PromotionProcessorBase has one abstract method to be implemented, Evaluate. * ...the method is supplied with a PromotionData, and a PromotionProcessorContext object * ...that contains information about the current order/fakeCart. */ protected override RewardDescription Evaluate( // note: it's OrderForm now... MyPercentagePromotion promotionData // the model --> look in the UI to see the properties , PromotionProcessorContext context) { /* A reward description contains information about if and how a reward is applied. * ...some properties are: * - A list of redemption descriptions, one for each of the maximum amount of redemptions * ...that could be applied to the current order. * This does not have to take redemption limits into consideration, that is handled by the * promotion engine. * - A reward type. Depending on the type, the promotion value is read from the properties * UnitDiscount, Percentage or Quantity. * - A status flag. Indicates if a promotion is not, partially, or fully fulfilled. * - A saved amount. The amount by which this reward reduces the order cost. * Is set by the promotion engine; should not be set in the promotion processor*/ IOrderForm orderForm = context.OrderForm; // OrderForm now pops in with the context //context. // lots of things IEnumerable <ILineItem> lineItemsCheck = orderForm.GetAllLineItems(); IEnumerable <ILineItem> lineItems = GetLineItems(context.OrderForm); #region Just Checking //var e = _contentLoader.Get<EntryContentBase>(item0); //should check if it's applicable... at all //var li = _orderFactory.Service.CreateLineItem(e.Code); //li.Quantity = 1; //li.PlacedPrice = 15; //orderForm.Shipments.First().LineItems.Add(li); #endregion // GetFulfillmentStatus - extension method FulfillmentStatus status = promotionData.MinNumberOfItems.GetFulfillmentStatus( orderForm, _targetEvaluator, _fulfillmentEvaluator); List <RewardDescription> rewardDescriptions = new List <RewardDescription>(); List <RedemptionDescription> redemptionDescriptions = new List <RedemptionDescription>(); #region NewStuff // The below does not see the cart, it's for landing pages for the Promotion itself (rendering) PromotionItems promoItems = GetPromotionItems(promotionData); // gets null var condition = promotionData.PercentageDiscount; // ...in the model var targets = promotionData.DiscountTargets; // get one in any case, points to what's at "promo" var skuCodes = _targetEvaluator.GetApplicableCodes( lineItems, targets.Items, targets.MatchRecursive); // get one if kicked in, 0 if not var fulfillmentStatus = _fulfillmentEvaluator.GetStatusForBuyQuantityPromotion( skuCodes , lineItems , promotionData.MinNumberOfItems.RequiredQuantity , promotionData.PartialFulfillmentNumberOfItems); // Just checking // The promotion engine creates a "price matrix" for all items in the order form. // OrderFormPriceMatrix, is accessible through the EntryPrices property // of the PromotionProcessorContext object. // PromotionProcessorContext is passed to the Evaluate method as one of the arguments. // ...the matrix holds "codes" and quantity // The second ExtractEntries call starts to receive entries where the first call ended. // ... makes it easy to create several redemptions by calling ExtractEntries in a loop, // ... and create one RedemptionDescription inside the loop. // The price matrix has one public method (ExtractEntries) // ... two overloads, both overloads takes entry codes and quantity as parameters. // ... one contains an action for getting the entries in a specific order. // ... if no specific order is specified, MostExpensiveFirst is used. var affectedEntries = context.EntryPrices.ExtractEntries( skuCodes, 1); // get one if it kicks in, null if not if (affectedEntries != null) { IEnumerable <PriceEntry> priceEntries = affectedEntries.PriceEntries; foreach (var item in priceEntries) { var qty = item.Quantity; var price = item.Price; var calc = item.CalculatedTotal; // involves the Qty var actuals = item.ActualTotal; // includes rounding } } // could have a look here switch (fulfillmentStatus) { case FulfillmentStatus.NotFulfilled: break; case FulfillmentStatus.PartiallyFulfilled: break; case FulfillmentStatus.Fulfilled: break; case FulfillmentStatus.CouponCodeRequired: break; case FulfillmentStatus.Excluded: break; case FulfillmentStatus.VisitorGroupRequired: break; case FulfillmentStatus.RedemptionLimitReached: break; case FulfillmentStatus.NoMoneySaved: break; case FulfillmentStatus.InvalidCoupon: break; case FulfillmentStatus.InvalidCombination: break; case FulfillmentStatus.MissingVisitorGroup: break; case FulfillmentStatus.NoRedemptionRemaining: break; case FulfillmentStatus.Ineffective: break; default: break; } // ... an extension method return(RewardDescription.CreatePercentageReward( fulfillmentStatus , GetRedemptions(skuCodes, promotionData, context) , promotionData , promotionData.PercentageDiscount.Percentage //, fulfillmentStatus.GetRewardDescriptionText() , fulfillmentStatus.GetRewardDescriptionText() + " : " + promotionData.Description + " : " )); #endregion #region Older stuff and debug - no show #region Older not in use //RewardDescription rewardDescription = new RewardDescription(); //var codes = _targetEvaluator.GetApplicableCodes(lineItems,) //_fulfillmentEvaluator.GetStatusForBuyQuantityPromotion( // ) #endregion // new stuff #region Previous version //if (status.HasFlag(FulfillmentStatus.Fulfilled)) //{ // return RewardDescription.CreateMoneyOrPercentageRewardDescription( // status, // redemptionDescriptions, // promotionData, // promotionData.PercentageDiscount, // context.OrderGroup.Currency, // "Custom promotion fulfilled"); // should have a more flexible way... GetDescription() //} //else //{ // return RewardDescription.CreateNotFulfilledDescription( // promotionData, FulfillmentStatus.NotFulfilled); //} #endregion #region Debug //RedemptionDescription rFirst; //redemptionDescriptions.Add(CreateRedemptionDescriptionText(orderForm)); // below "if-construct" is for debug //if (promotionData.PercentageDiscount <= 0) // ... return "sorry, no discount" //{ // return RewardDescription.CreatePercentageReward( // FulfillmentStatus.NotFulfilled, // redemptionDescriptions, // promotionData, // 0, // CreateRewardDescriptionText(redemptionDescriptions.First(), FulfillmentStatus.NotFulfilled, promotionData)); // /*RewardDescription.CreateMoneyOrPercentageRewardDescription(FulfillmentStatus.NotFulfilled,r,promotionData,null);*/ //} //IEnumerable<ContentReference> targetItems = promotionData.DiscountTargets.Items.ToList(); // set by the Promo-UI //bool matchRecursive = true; // walking down the catalog hierarchy //var lineItems = GetLineItems(orderForm); // "GetLineItems" - in the base class (PromotionProcessorBase) //var affectedItems = _targetEvaluator.GetApplicableItems(lineItems, targetItems, matchRecursive); // in CollectionTargetEvaluator //var affectedItems = _targetEvaluator.GetApplicableCodes(orderForm.GetAllLineItems(), targetItems, false); // small class --> just to get the status by the settings //var status = FulfillmentEvaluator.GetStatusForBuyQuantityPromotion(affectedItems.Select(x => x.LineItem) // , promotionData.MinNumberOfItems, promotionData.PartialFulfillmentNumberOfItems); // in the model //var s = FulfillmentEvaluator. //FulfillmentEvaluator ff = new FulfillmentEvaluator(); //if (rewardDescriptions.Any()) //{ // return rewardDescriptions.First(); //} //else //{ // return null; //} /*return RewardDescription.CreateMoneyOrPercentageRewardDescription( * status, * affectedItems, * promotionData, * promotionData.PercentageDiscount, * GetRewardDescriptionText(affectedItems, status, promotionData));*/ #endregion #endregion } // end RewardDescription
public ActionResult Index(ShirtVariation currentContent) { IsOnLine = CheckIfOnLine.IsInternetAvailable; // Need to know... for Find CheckWarehouses(currentContent); // WH-info on the Page var startPage = _contentLoader.Get <StartPage>(ContentReference.StartPage); var cartUrl = _urlResolver.GetUrl(startPage.Settings.cartPage, currentContent.Language.Name); var wUrl = _urlResolver.GetUrl(startPage.Settings.cartPage, currentContent.Language.Name); PricingService pSrvs = new PricingService( _priceService, _currentMarket, _priceDetailService); // used elsewere //currentContent.GetCustomerPrices() // works with the R/O-pricingLoader, would miss the custom SaleTypes //currentContent.GetPrices() // this one also uses the R/O-Loader ... unusable #region Newpromotions // New promotions decimal savedMoney = 0; string rewardDescription = String.Empty; //IEnumerable<RewardDescription> rewards; // get prices incl. "BasePrice" //IPriceValue salePrice = BestPricingCalculatorEver.GetSalePrice(currentContent.ContentLink);// IPriceValue salePrice = _myPriceCalculator.GetSalePrice(currentContent, 1); // the below does the second "Evaluate" var descr = _promotionEngine.Evaluate(currentContent.ContentLink).ToList(); if (descr.Count == 0) // No promos { var d = new RewardDescription( FulfillmentStatus.NotFulfilled, null, null, 0, 0, RewardType.None, "No promo"); descr.Add(d); rewardDescription = descr.First().Description; // ...just to show } else { foreach (var item in descr) { rewardDescription += item.Description; } } // previous way if (descr.Count() >= 1) { savedMoney = descr.First().Percentage *salePrice.UnitPrice.Amount / 100; //rewardDescription = descr.First().Description; Session["SavedMoney"] = savedMoney; } else { savedMoney = 0; //rewardDescription = "No discount"; } // ...this goes to PriceCalc-discount var promoPrice = salePrice.UnitPrice.Amount - savedMoney; #endregion #region just checking on promos //List<RewardDescription> rewards = new List<RewardDescription>(); //rewards = _promotionEngine.Evaluate(currentContent.ContentLink).ToList(); //IEnumerable<DiscountedEntry> entries = _promotionEngine.GetDiscountPrices(currentContent.ContentLink, _currentMarket.GetCurrentMarket()); #endregion #region FindStuff // new Find-Stuff - need to check this out... // FindQueries Qs = new FindQueries(); // Qs.NewExtensionMethods(currentContent); // Qs.SDKExamples(currentContent.ContentLink); #endregion #region Checking some for routing and http-ctx /* * var str = currentContent.GetOriginalType().Name; // not for redirect * var x = ServiceLocator.Current.GetInstance<TemplateResolver>(); * * RequestContext requestContext = new RequestContext(base.HttpContext, base.RouteData); * var parentStack = requestContext.HttpContext.Items[ContentContext.ContentContextKey] as * Stack<ContentContext.ContentPropertiesStack>; * * string controller = requestContext.GetController(); * var t = x.Resolve(requestContext.HttpContext, new CartPage(), TemplateTypeCategories.MvcController); // could use .Name */ #endregion #region LookingAround (incl. new and old Promo-engine) //LoadingExamples(currentContent); //CheckPrices(currentContent); // Have to fake a cart... but it looks good //string rewardDescription = String.Empty; //decimal savedMoney = CheckBetaPromotions(currentContent, out rewardDescription); //var theProxy = currentContent.GetType(); //var yourClass = currentContent.GetOriginalType(); //StoreHelper.GetDiscountPrice(currentContent.LoadEntry()); //StoreHelper.GetSalePrice(currentContent.LoadEntry() #endregion #region Relations, parent - child, etc. CheckOnRelations(currentContent); #endregion #region RoCe - check this // quick-fix - nothing back ICart dummyCart = _orderRepository.LoadOrCreateCart <ICart>(new Guid(), "DummyCart"); ILineItem lineItem = _orderGroupFactory.CreateLineItem(currentContent.Code, dummyCart); var c2 = _lineItemCalculator.GetExtendedPrice(lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency); var check = _lineItemCalculator.GetDiscountedPrice( lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency).Amount; // Should check the BasePrice here (new way) // BestPricingCalc is the old way // should override the LI-calculator #endregion //_currentMarket.GetCurrentMarket().DefaultCurrency.Format(cu) //Currency.SetFormat(_currentMarket.GetCurrentMarket().DefaultCurrency.Format.CurrencySymbol); string thePriceString = string.Empty; if (currentContent.GetDefaultPrice().UnitPrice.Amount == 0) { thePriceString = "no default price"; } else { thePriceString = currentContent.GetDefaultPrice().UnitPrice.ToString(); } var model = new ShirtVariationViewModel { MainBody = currentContent.MainBody, // Pricing priceString = thePriceString, //theRightPriceToPlace = GetThePriceToPlace(currentContent), // tiered pricing...old, not in use CustomerPricingPrice = GetCustomerPricingPrice(currentContent), //discountPrice = CustomStoreHelper.GetDiscountPrice(currentContent.LoadEntry(CatalogEntryResponseGroup.ResponseGroup.Nodes)), discountPriceNew = _lineItemCalculator.GetDiscountedPrice(lineItem, _currentMarket.GetCurrentMarket().DefaultCurrency).Amount, image = GetDefaultAsset((IAssetContainer)currentContent), CanBeMonogrammed = currentContent.CanBeMonogrammed, ProductArea = currentContent.ProductArea, CartUrl = cartUrl, // new stuff - not yet in course WishlistUrl = wUrl, // new stuff - not yet in course // Added for Adv. below //labPrice = BestPricingCalculatorEver.GetDiscountPrice(currentContent, 1, promoPrice), // , "Fashion", "Shirts" labPrice = _myPriceCalculator.CheckDiscountPrice(currentContent, 1, promoPrice), overridePrices = pSrvs.GetPrices(currentContent.Code), PromoString = rewardDescription, // in #region LookingAround betaDiscountPrice = savedMoney, // in #region LookingAround // warehouse info (Lists get filled up in the entrance of "Index-method") generalWarehouseInfo = this.generalWarehouseInfo, specificWarehouseInfo = this.specificWarehouseInfo, // Fills up "Specific-List" localMarketWarehouses = GetLocalMarketWarehouses(), entryCode = currentContent.Code, //Markets currentMarket = GetCurrentMarket(), marketOwner = GetMarketOwner(), // Associations //Associations = GetAssociatedEntries(currentContent), // IEnumerable<ContentReference> // Remove when Aggregation is done //AssociationMetaData = GetAssociationMetaData(currentContent), // string // Remove when Aggregation is done AssocAggregated = GetAggregatedAssocciations(currentContent), // Dictionary<string, ContentReference> // The final thing // Searchendizing ... need to be OnLine to use BoughtThisBoughtThat = GetOtherEntries(currentContent.Code), // Taxes Tax = GetTaxOldSchool(currentContent), TaxString = GetTaxStrings(currentContent), TaxNewSchool = GetTaxNewSchool(currentContent), // info about the variation VariationAvailability = currentContent.IsAvailableInCurrentMarket(), VariationInfo = "Info: " + CollectInfo() }; return(View(model)); }
public void Index_AppliablePromotionsChangeFromDisableToEnable_ShouldSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var fulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.Fulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny<PromotionEngineSettings>())).Returns(new[] { fulfilledRewardDesciption }); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny<PromotionEngineSettings>())).Callback(() => _cart.GetFirstForm().Promotions.Add(new PromotionInformation())); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Once); }
public void Index_AppliablePromotionsAlwaysDisable_ShouldNotSaveCart() { _cart.GetFirstForm().Shipments.First().ShippingMethodId = Guid.NewGuid(); _cart.GetFirstForm().Promotions.Clear(); var notFulfilledRewardDesciption = new RewardDescription(FulfillmentStatus.NotFulfilled, null, null, 0, 0, RewardType.Money, string.Empty); _promotionEngineMock.Setup(x => x.Run(_cart, It.IsAny<PromotionEngineSettings>())).Returns(new[] { notFulfilledRewardDesciption }); _subject.Index(new CheckoutPage()); _orderRepositoryMock.Verify(s => s.Save(_cart), Times.Never); }
public static bool IsOfType(this RewardDescription description, DiscountType discountType) { return(description.Promotion?.DiscountType == discountType); }