Пример #1
0
        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);
        }
Пример #2
0
        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);
        }