public override bool Execute(OrderTaskContext context) { var order = context.Order; if (order != null) { var hccApp = context.HccApp; var store = hccApp.CurrentStore; if (order.CustomProperties.HccRewardsPointsIssued || !store.Settings.RewardsPointsEnabled || string.IsNullOrEmpty(context.UserId)) // skip if there is no user account { return(true); } var pointsAmount = GetPointsAmount(order, hccApp); var orderTotal = GetOrderTotal(order, store); if (orderTotal > pointsAmount) { var pointsManager = new CustomerPointsManager(hccApp.CurrentRequestContext); var pointsToIssue = pointsManager.PointsToIssueForSpend(orderTotal - pointsAmount); pointsManager.IssuePoints(order.UserID, pointsToIssue); order.CustomProperties.HccRewardsPointsIssued = true; hccApp.OrderServices.Orders.Update(order); } } return(true); }
public void CanIssuePointsForSpendUneven() { string connectionString = string.Empty; int pointsIssuedPerDollar = 1; int pointsNeededForDollarCredit = 100; long storeId = -1; CustomerPointsManager target = CustomerPointsManager.InstantiateForMemory(pointsIssuedPerDollar, pointsNeededForDollarCredit, storeId); Decimal spend = 43.51m; int expected = 43; int actual; actual = target.PointsToIssueForSpend(spend); Assert.AreEqual(expected, actual); }
public override bool Execute(OrderTaskContext context) { if (context.Order != null) { string issued = context.Order.CustomProperties.GetProperty("bvsoftware", "rewardspointsissued"); if (issued == "1") { return(true); } // skip if there is no user account if (context.UserId == string.Empty) { return(true); } bool hasPointsPayment = false; foreach (OrderTransaction t in context.MTApp.OrderServices.Transactions.FindForOrder(context.Order.bvin)) { if (t.Action == MerchantTribe.Payment.ActionType.RewardPointsInfo) { hasPointsPayment = true; break; } } // Don't issue points when paying with points if (hasPointsPayment) { return(true); } CustomerPointsManager pointsManager = CustomerPointsManager.InstantiateForDatabase(context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsIssuedPerDollarSpent, context.MTApp.CurrentRequestContext.CurrentStore.Settings.RewardsPointsNeededPerDollarCredit, context.MTApp.CurrentRequestContext.CurrentStore.Id); int pointsToIssue = pointsManager.PointsToIssueForSpend(context.Order.TotalOrderAfterDiscounts); pointsManager.IssuePoints(context.Order.UserID, pointsToIssue); context.Order.CustomProperties.SetProperty("bvsoftware", "rewardspointsissued", "1"); context.MTApp.OrderServices.Orders.Update(context.Order); } return(true); }