Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            CommonHelper.SetResponseNoCache(Response);

            if (!SettingManager.GetSettingValueBoolean("Common.EnableWishlist"))
            {
                Response.Redirect(CommonHelper.GetStoreLocation());
            }

            string title = GetLocaleResourceString("PageTitle.Wishlist");

            SEOHelper.RenderTitle(this, title, true);

            if (!Page.IsPostBack)
            {
                Customer customer = CustomerManager.GetCustomerByGuid(this.CustomerGuid.HasValue ? this.CustomerGuid.Value : Guid.Empty);
                if (customer != null)
                {
                    lTitle.Text = string.Format(GetLocaleResourceString("Wishlist.WishlistOf"), Server.HtmlEncode(customer.FullName), Server.HtmlEncode(customer.Email));
                    CustomerSession customerSession = CustomerManager.GetCustomerSessionByCustomerId(customer.CustomerId);
                    if (customerSession != null)
                    {
                        ctrlWishlist.CustomerSessionGuid = customerSession.CustomerSessionGuid;
                    }
                    ctrlWishlist.IsEditable = false;
                    ctrlWishlist.BindData();
                }
                else
                {
                    lTitle.Text = GetLocaleResourceString("Wishlist.YourWishlist");
                    if (NopContext.Current.Session != null)
                    {
                        ctrlWishlist.CustomerSessionGuid = NopContext.Current.Session.CustomerSessionGuid;
                    }
                    ctrlWishlist.IsEditable = true;
                    ctrlWishlist.BindData();

                    if (NopContext.Current.User != null && !NopContext.Current.User.IsGuest)
                    {
                        lblYourWishlistURL.Visible = true;
                        lnkWishListUrl.Visible     = true;
                        lblYourWishlistURL.Text    = GetLocaleResourceString("Wishlist.YourWishlistURL");
                        string wishListUrl = SEOHelper.GetWishlistUrl();
                        wishListUrl = CommonHelper.ModifyQueryString(wishListUrl, "CustomerGUID=" + NopContext.Current.User.CustomerGuid.ToString(), null);
                        lnkWishListUrl.NavigateUrl = wishListUrl;
                        lnkWishListUrl.Text        = wishListUrl;
                    }
                }
            }
        }
        protected void UpdateWishlist()
        {
            if (!IsEditable)
            {
                return;
            }

            bool hasErrors = ValidateWishlistItems();

            if (!hasErrors)
            {
                foreach (RepeaterItem item in rptShoppingCart.Items)
                {
                    var txtQuantity           = item.FindControl("txtQuantity") as TextBox;
                    var lblShoppingCartItemId = item.FindControl("lblShoppingCartItemId") as Label;
                    var cbRemoveFromCart      = item.FindControl("cbRemoveFromCart") as CheckBox;

                    int shoppingCartItemId = 0;
                    int quantity           = 0;
                    if (txtQuantity != null && lblShoppingCartItemId != null && cbRemoveFromCart != null)
                    {
                        int.TryParse(lblShoppingCartItemId.Text, out shoppingCartItemId);
                        if (cbRemoveFromCart.Checked)
                        {
                            this.ShoppingCartService.DeleteShoppingCartItem(shoppingCartItemId, false);
                        }
                        else
                        {
                            int.TryParse(txtQuantity.Text, out quantity);
                            List <string> addToCartWarning = this.ShoppingCartService.UpdateCart(shoppingCartItemId, quantity, false);
                        }
                    }
                }

                Response.Redirect(SEOHelper.GetWishlistUrl());
            }
        }
Пример #3
0
        protected void rptVariants_OnItemCommand(Object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "AddToCart" || e.CommandName == "AddToWishlist")
            {
                var txtQuantity             = e.Item.FindControl("txtQuantity") as NumericTextBox;
                var txtCustomerEnteredPrice = e.Item.FindControl("txtCustomerEnteredPrice") as DecimalTextBox;
                var productVariantId        = e.Item.FindControl("ProductVariantId") as Label;
                var ctrlProductAttributes   = e.Item.FindControl("ctrlProductAttributes") as ProductAttributesControl;
                var ctrlGiftCardAttributes  = e.Item.FindControl("ctrlGiftCardAttributes") as GiftCardAttributesControl;
                var lblError = e.Item.FindControl("lblError") as Label;

                var pv = ProductManager.GetProductVariantById(Convert.ToInt32(productVariantId.Text));
                if (pv == null)
                {
                    return;
                }

                string  attributes                    = ctrlProductAttributes.SelectedAttributes;
                decimal customerEnteredPrice          = txtCustomerEnteredPrice.Value;
                decimal customerEnteredPriceConverted = CurrencyManager.ConvertCurrency(customerEnteredPrice, NopContext.Current.WorkingCurrency, CurrencyManager.PrimaryStoreCurrency);
                int     quantity = txtQuantity.Value;

                //gift cards
                if (pv.IsGiftCard)
                {
                    string recipientName   = ctrlGiftCardAttributes.RecipientName;
                    string recipientEmail  = ctrlGiftCardAttributes.RecipientEmail;
                    string senderName      = ctrlGiftCardAttributes.SenderName;
                    string senderEmail     = ctrlGiftCardAttributes.SenderEmail;
                    string giftCardMessage = ctrlGiftCardAttributes.GiftCardMessage;

                    attributes = ProductAttributeHelper.AddGiftCardAttribute(attributes,
                                                                             recipientName, recipientEmail, senderName, senderEmail, giftCardMessage);
                }

                try
                {
                    if (e.CommandName == "AddToCart")
                    {
                        string        sep = "<br />";
                        List <string> addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.ShoppingCart,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            if (SettingManager.GetSettingValueBoolean("Display.Products.DisplayCartAfterAddingProduct"))
                            {
                                //redirect to shopping cart page
                                Response.Redirect(SEOHelper.GetShoppingCartUrl());
                            }
                            else
                            {
                                //display notification message
                                this.DisplayAlertMessage(GetLocaleResourceString("Products.ProductHasBeenAddedToTheCart"));
                            }
                        }
                        else
                        {
                            StringBuilder addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }

                    if (e.CommandName == "AddToWishlist")
                    {
                        string sep = "<br />";
                        var    addToCartWarnings = ShoppingCartManager.AddToCart(
                            ShoppingCartTypeEnum.Wishlist,
                            pv.ProductVariantId,
                            attributes,
                            customerEnteredPriceConverted,
                            quantity);
                        if (addToCartWarnings.Count == 0)
                        {
                            Response.Redirect(SEOHelper.GetWishlistUrl());
                        }
                        else
                        {
                            var addToCartWarningsSb = new StringBuilder();
                            for (int i = 0; i < addToCartWarnings.Count; i++)
                            {
                                addToCartWarningsSb.Append(Server.HtmlEncode(addToCartWarnings[i]));
                                if (i != addToCartWarnings.Count - 1)
                                {
                                    addToCartWarningsSb.Append(sep);
                                }
                            }
                            string errorFull = addToCartWarningsSb.ToString();
                            lblError.Text = errorFull;
                            if (SettingManager.GetSettingValueBoolean("Common.ShowAlertForProductAttributes"))
                            {
                                this.DisplayAlertMessage(errorFull.Replace(sep, "\\n"));
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    LogManager.InsertLog(LogTypeEnum.CustomerError, exc.Message, exc);
                    lblError.Text = Server.HtmlEncode(exc.Message);
                }
            }
        }