コード例 #1
0
        /// <summary>
        /// The add to cart.
        /// </summary>
        /// <param name="Source">
        /// The source.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        protected void AddToCart(object Source, EventArgs e)
        {
            if (CanAddProduct(DistributorID, ref errSKU))
            {
                //List<string> friendlyMessages = new List<string>();
                List <ShoppingCartItem_V01> products = getAllInput(friendlyMessages);
                //CheckForOrderThresholds(products);

                uxErrores.DataSource = errSKU;
                uxErrores.DataBind();


                try
                {
                    if (products.Count > 0)
                    {
                        AddItemsToCart(products);
                        findCrossSell(products);
                    }
                    //errSKU.AddRange(friendlyMessages);

                    if (ShoppingCart.RuleResults.Any(rs => rs.Result == RulesResult.Feedback))
                    {
                        string feedback = ShoppingCart.RuleResults.Where(r => r.Result == RulesResult.Feedback).First().Messages[0];
                        if (!string.IsNullOrEmpty(feedback))
                        {
                            string title = PlatformResources.GetGlobalResourceString("GlobalResources", "FeedbackNotification");
                            if (IsChina)
                            {
                                title = GetGlobalResourceString("FeedbackNotification");
                            }
                            (this.Master as OrderingMaster).ShowMessage(title, feedback);
                        }
                    }
                    else
                    {
                        if (ShoppingCart.RuleResults.Any(rs => rs.RuleName == "PurchasingLimits Rules" && rs.Result == RulesResult.Failure))
                        {
                            PurchasingLimitProvider.SetPostErrorRemainingLimitsSummaryMessage(ShoppingCart);
                        }
                        if (ShoppingCart.RuleResults.Any(
                                rs =>
                                rs.RuleName == "PurchaseRestriction Rules" && rs.Result == RulesResult.Failure))
                        {
                            var ruleResultMsgs =
                                ShoppingCart.RuleResults.Where(r => r.Result == RulesResult.Failure && r.RuleName == "PurchaseRestriction Rules")
                                .Select(r => r.Messages);
                            errSKU.AddRange(ruleResultMsgs.First().Distinct().ToList());
                            ShoppingCart.RuleResults.RemoveAll(x => x.RuleName == "PurchaseRestriction Rules");
                        }
                        IEnumerable <string> ruleResultMessages = from r in ShoppingCart.RuleResults where r.Result == RulesResult.Failure select r.Messages[0];

                        if (null != ruleResultMessages && ruleResultMessages.Count() > 0)
                        {
                            errSKU.AddRange(ruleResultMessages.Distinct().ToList());
                        }
                    }

                    ShoppingCart.RuleResults.Clear();

                    if (errSKU.Count > 0)
                    {
                        uxErrores.DataSource = errSKU;
                        uxErrores.DataBind();
                    }
                    if (friendlyMessages.Count > 0)
                    {
                        ShowBackorderMessage(friendlyMessages);
                    }

                    OmnitureHelper.RegisterOmnitureAddCartScript(Page, ShoppingCart.ShoppingCartItems, products);
                }
                catch (Exception ex)
                {
                    LoggerHelper.Error(GetDistributorInfo() + "Can't add to cart!\n" + ex);
                }

                ClearItemsOnPage();
            }
            else
            {
                uxErrores.DataSource = errSKU;
                uxErrores.DataBind();
            }

            // Initializing again the controls.
            System.Web.UI.ScriptManager.RegisterStartupScript(
                Page,
                Page.GetType(),
                Guid.NewGuid().ToString(),
                "InitializeControls();",
                true);
        }