コード例 #1
0
        protected void btnAddPromotion_Click(Object sender, EventArgs e)
        {
            String promotionCode = txtPromotionCode.Text.ToLower().Trim();

            txtPromotionCode.Text  = String.Empty;
            lblPromotionError.Text = String.Empty;

            IEnumerable <IPromotionValidationResult> validationResults = PromotionManager.ValidatePromotion(promotionCode, PromotionManager.CreateRuleContext(cart));

            if (validationResults.Count() > 0 && validationResults.Any(vr => !vr.IsValid))
            {
                foreach (var reason in validationResults.Where(vr => !vr.IsValid).SelectMany(vr => vr.Reasons))
                {
                    String message = reason.MessageKey.StringResource();
                    if (reason.ContextItems != null && reason.ContextItems.Any())
                    {
                        foreach (var item in reason.ContextItems)
                        {
                            message = message.Replace(String.Format("{{{0}}}", item.Key), item.Value.ToString());
                        }
                    }

                    lblPromotionError.Text += String.Format("<div class='promotion-reason error-wrap'>{0}</div>", message);
                }
                return;
            }
            else
            {
                PromotionManager.AssignPromotion(ThisCustomer.CustomerID, promotionCode);
            }

            UpdateCart();
            BindPromotions();
        }
コード例 #2
0
        public ActionResult AddPromoCode(PromotionsViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            var promoCode = model.EnteredCode.ToLower();
            var customer  = HttpContext.GetCustomer();
            var cart      = CachedShoppingCartProvider.Get(customer, CartTypeEnum.ShoppingCart, AppLogic.StoreID());

            var validationResults         = PromotionManager.ValidatePromotion(promoCode, PromotionManager.CreateRuleContext(cart));
            var validationFailureMessages = validationResults
                                            .Where(validationResult => !validationResult.IsValid)
                                            .SelectMany(validationResult => validationResult.Reasons)
                                            .Select(reason => new
            {
                message = AppLogic.GetString(reason.MessageKey),
                context = reason.ContextItems,
            })
                                            .Select(o => o.context == null
                                        ? o.message
                                        : o.context.Aggregate(
                                                        o.message,
                                                        (message, item) => message.Replace(string.Format("{{{0}}}", item.Key), item.Value.ToString())));

            if (validationFailureMessages.Any())
            {
                foreach (var failureMessage in validationFailureMessages)
                {
                    ModelState.AddModelError("EnteredCode", failureMessage);
                }

                return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
            }

            PromotionManager.AssignPromotion(customer.CustomerID, promoCode);

            return(RedirectToAction(ActionNames.Index, ControllerNames.Checkout));
        }
コード例 #3
0
        private void UpdateCart()
        {
            if (cart.InventoryTrimmed)
            {
                cart = new ShoppingCart(SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, 0, false);
                ctrlCartSummary.DataSource = cart;
                Response.Redirect(string.Format("shoppingcart.aspx?InvTrimmed=true"));
            }
            cart = new ShoppingCart(SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, 0, false);
            cart.SetCoupon(CouponCode.Text.ToUpperInvariant(), true);

            foreach (string code in txtPromotionCode.Text.Split(' '))
            {
                PromotionManager.AssignPromotion(ThisCustomer.CustomerID, code);
            }

            UpdateCartQuantity();
            ctrlOrderOption.UpdateChanges();
            ProcessCart(false, false, false);
            InitializePageContent();
            InitializeShoppingCartControl();
        }