override protected void OnPreInit(EventArgs e)
        {
            if (AppLogic.AppConfigBool("TemplateSwitching.Enabled"))
            {
                string currentEntityTemplateName = String.Empty;
                if (CommonLogic.QueryStringCanBeDangerousContent("CategoryID").Length != 0)
                {
                    currentEntityTemplateName =
                        AppLogic.GetCurrentEntityTemplateName(
                            EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName);
                }
                else if (CommonLogic.QueryStringCanBeDangerousContent("DepartmentID").Length != 0)
                {
                    currentEntityTemplateName =
                        AppLogic.GetCurrentEntityTemplateName(EntityDefinitions.readonly_SectionEntitySpecs.m_EntityName);
                }
                else if (CommonLogic.QueryStringCanBeDangerousContent("ManufacturerID").Length != 0)
                {
                    currentEntityTemplateName =
                        AppLogic.GetCurrentEntityTemplateName(
                            EntityDefinitions.readonly_ManufacturerEntitySpecs.m_EntityName);
                }
                else
                {
                    string itemCode   = InterpriseHelper.GetInventoryItemCode(CommonLogic.QueryStringUSInt("ProductID"));
                    string categoryId = EntityHelper.GetProductsFirstEntity(itemCode, "Category").ToString();
                    currentEntityTemplateName =
                        AppLogic.GetCurrentEntityTemplateName(
                            EntityDefinitions.readonly_CategoryEntitySpecs.m_EntityName, categoryId);
                }

                SetTemplate(currentEntityTemplateName);
            }
            base.OnPreInit(e);
        }
        private void InitializePageContent()
        {
            bool   exists      = false;
            string ImgFilename = string.Empty;
            bool   existing    = false;

            AppLogic.LogEvent(ThisCustomer.CustomerCode, 10, ItemCode);
            pnlRequireReg.Visible         = (RequiresReg && ThisCustomer.IsNotRegistered);
            this.pnlEmailToFriend.Visible = !(RequiresReg && ThisCustomer.IsNotRegistered);

            emailproduct_aspx_1.Text = "<br><br><br><br><b>" + AppLogic.GetString("emailproduct.aspx.1", SkinID, ThisCustomer.LocaleSetting) + "</b><br><br><br><a href=\"signin.aspx?returnurl=showproduct.aspx?" + Server.HtmlEncode(Server.UrlEncode(CommonLogic.ServerVariables("QUERY_STRING"))) + "\">" + AppLogic.GetString("emailproduct.aspx.2", SkinID, ThisCustomer.LocaleSetting) + "</a> " + AppLogic.GetString("emailproduct.aspx.3", SkinID, ThisCustomer.LocaleSetting);

            string ProdPic = string.Empty;

            using (var con = DB.NewSqlConnection())
            {
                con.Open();
                using (var reader = DB.GetRSFormat(con, "SELECT Filename FROM InventoryOverrideImage with (NOLOCK) WHERE ItemCode = {0} AND WebSiteCode = {1} AND IsDefaultIcon = 1", DB.SQuote(InterpriseHelper.GetInventoryItemCode(productID)), DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode)))
                {
                    existing = reader.Read();
                    if (existing)
                    {
                        ImgFilename = (DB.RSField(reader, "Filename"));
                    }
                }
            }
            ProdPic             = AppLogic.LocateImageFilenameUrl("Product", InterpriseHelper.GetInventoryItemCode(productID), "medium", ImgFilename, AppLogic.AppConfigBool("Watermark.Enabled"), out exists);
            imgProduct.ImageUrl = ProdPic;

            string imgAltText = "";

            using (var con = DB.NewSqlConnection())
            {
                con.Open();
                using (var reader = DB.GetRSFormat(con, "exec EcommerceDefaultMediumImage @ItemCode={0}, @WebSiteCode={1}, @LanguageCode={2} ", DB.SQuote(InterpriseHelper.GetInventoryItemCode(productID)), DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode), DB.SQuote(Customer.Current.LanguageCode)))
                {
                    existing = reader.Read();
                    if (existing)
                    {
                        imgAltText = (DB.RSField(reader, "SEAltTextMedium"));
                    }
                }
            }

            imgProduct.AlternateText = imgAltText;

            ProductNavLink.NavigateUrl = InterpriseHelper.MakeItemLink(ItemCode);
            ProductNavLink.Text        = AppLogic.GetString("emailproduct.aspx.23", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_4.Text   = AppLogic.GetString("emailproduct.aspx.4", SkinID, ThisCustomer.LocaleSetting) + " " + Security.HtmlEncode(ProductName) + CommonLogic.IIF(VariantName.Length > 0, " - " + Security.HtmlEncode(VariantName), "");
            emailproduct_aspx_11.Text  = AppLogic.GetString("emailproduct.aspx.11", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_12.Text  = AppLogic.GetString("emailproduct.aspx.12", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_22.Text  = AppLogic.GetString("emailproduct.aspx.21", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_15.Text  = AppLogic.GetString("emailproduct.aspx.15", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_18.Text  = AppLogic.GetString("emailproduct.aspx.18", SkinID, ThisCustomer.LocaleSetting);
            emailproduct_aspx_19.Text  = AppLogic.GetString("emailproduct.aspx.19", SkinID, ThisCustomer.LocaleSetting);
            txtMessage.Text            = AppLogic.GetString("emailproduct.aspx.22", SkinID, ThisCustomer.LocaleSetting);
            btnSubmit.Text             = AppLogic.GetString("emailproduct.aspx.20", SkinID, ThisCustomer.LocaleSetting);
        }
Esempio n. 3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            ThisCustomer = ((InterpriseSuiteEcommercePrincipal)Context.User).ThisCustomer;
            ThisCustomer.RequireCustomerRecord();
            _SkinID   = CommonLogic.CookieUSInt(SkinBase.ro_SkinCookieName);
            ProductID = CommonLogic.QueryStringUSInt("ProductID");
            ItemCode  = InterpriseHelper.GetInventoryItemCode(ProductID);
            String ProductName = HttpContext.Current.Server.HtmlEncode(AppLogic.GetProductName(ProductID.ToString(), ThisCustomer.LocaleSetting));
            String ReturnURL   = CommonLogic.QueryStringCanBeDangerousContent("ReturnURL");


            if (ReturnURL.IndexOf("<script>", StringComparison.InvariantCultureIgnoreCase) != -1)
            {
                throw new ArgumentException("SECURITY EXCEPTION");
            }

            using (SqlConnection con = DB.NewSqlConnection())
            {
                con.Open();
                using (IDataReader rs = DB.GetRSFormat(con, String.Format("SELECT * FROM EcommerceRating with (NOLOCK) WHERE CustomerCode={0} AND ItemCode={1} AND WebsiteCode={2} AND ContactCode={3}",
                                                                          DB.SQuote(ThisCustomer.CustomerCode), DB.SQuote(ItemCode), DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode), DB.SQuote(ThisCustomer.ContactCode))))
                {
                    if (rs.Read())
                    {
                        TheirCurrentRating  = DB.RSFieldInt(rs, "Rating");
                        TheirCurrentComment = DB.RSField(rs, "Comments");
                        Editing             = true;
                    }
                }
            }

            if (!IsPostBack)
            {
                InitializePageContent();
            }
        }
Esempio n. 4
0
    public void ProcessRequest(HttpContext context)
    {
        context.Response.CacheControl = "private";
        context.Response.Expires      = 0;
        context.Response.AddHeader("pragma", "no-cache");

        var ThisCustomer = ((InterpriseSuiteEcommercePrincipal)context.User).ThisCustomer;

        ThisCustomer.RequireCustomerRecord();

        string ReturnURL = CommonLogic.QueryStringCanBeDangerousContent("ReturnURL");

        if (ReturnURL.IndexOf("<script>", StringComparison.InvariantCultureIgnoreCase) != -1)
        {
            throw new ArgumentException("SECURITY EXCEPTION");
        }

        //Anonymous users should not be allowed to used WishList, they must register first.
        if (ThisCustomer.IsNotRegistered)
        {
            string ErrMsg = string.Empty;

            if (CommonLogic.FormNativeInt("IsWishList") == 1 || CommonLogic.QueryStringUSInt("IsWishList") == 1)
            {
                ErrMsg = AppLogic.GetString("signin.aspx.19", ThisCustomer.SkinID, ThisCustomer.LocaleSetting);
                context.Response.Redirect("signin.aspx?ErrorMsg=" + ErrMsg + "&ReturnUrl=" + Security.UrlEncode(ReturnURL));
            }
        }

        string ShippingAddressID = CommonLogic.QueryStringCanBeDangerousContent("ShippingAddressID"); // only used for multi-ship

        if (ShippingAddressID.IsNullOrEmptyTrimmed())
        {
            ShippingAddressID = CommonLogic.FormCanBeDangerousContent("ShippingAddressID");
        }

        if (ShippingAddressID.IsNullOrEmptyTrimmed() && !ThisCustomer.PrimaryShippingAddressID.IsNullOrEmptyTrimmed())
        {
            ShippingAddressID = ThisCustomer.PrimaryShippingAddressID;
        }

        string ProductID = CommonLogic.QueryStringCanBeDangerousContent("ProductID");

        if (ProductID.IsNullOrEmptyTrimmed())
        {
            ProductID = CommonLogic.FormCanBeDangerousContent("ProductID");
        }

        string itemCode = CommonLogic.QueryStringCanBeDangerousContent("ItemCode");

        // check if the item being added is matrix group
        // look for the matrix item and use it as itemcode instead
        if (!string.IsNullOrEmpty(CommonLogic.FormCanBeDangerousContent("MatrixItem")))
        {
            itemCode = CommonLogic.FormCanBeDangerousContent("MatrixItem");
        }

        bool   itemExisting       = false;
        string defaultUnitMeasure = string.Empty;

        if (itemCode.IsNullOrEmptyTrimmed())
        {
            int itemCounter = 0;
            if (!ProductID.IsNullOrEmptyTrimmed() &&
                int.TryParse(ProductID, out itemCounter) &&
                itemCounter > 0)
            {
                using (var con = DB.NewSqlConnection())
                {
                    con.Open();
                    using (var reader = DB.GetRSFormat(con, "SELECT i.ItemCode, ium.UnitMeasureCode FROM InventoryItem i with (NOLOCK) INNER JOIN InventoryUnitMeasure ium with (NOLOCK) ON i.ItemCode = ium.ItemCode AND IsBase = 1 WHERE i.Counter = {0}", itemCounter))
                    {
                        itemExisting = reader.Read();

                        if (itemExisting)
                        {
                            itemCode           = DB.RSField(reader, "ItemCode");
                            defaultUnitMeasure = DB.RSField(reader, "UnitMeasureCode");
                        }
                    }
                }
            }
        }
        else
        {
            // verify we have a valid item code
            using (var con = DB.NewSqlConnection())
            {
                con.Open();
                using (var reader = DB.GetRSFormat(con, "SELECT i.ItemCode FROM InventoryItem i with (NOLOCK) WHERE i.ItemCode = {0}", DB.SQuote(itemCode)))
                {
                    itemExisting = reader.Read();

                    if (itemExisting)
                    {
                        itemCode = DB.RSField(reader, "ItemCode");
                    }
                }
            }
        }

        if (!itemExisting)
        {
            GoNextPage(context);
        }

        // get the unit measure code
        string unitMeasureCode = CommonLogic.QueryStringCanBeDangerousContent("UnitMeasureCode");

        if (unitMeasureCode.IsNullOrEmptyTrimmed())
        {
            unitMeasureCode = CommonLogic.FormCanBeDangerousContent("UnitMeasureCode");
        }

        if (unitMeasureCode.IsNullOrEmptyTrimmed())
        {
            unitMeasureCode = defaultUnitMeasure;
        }

        // check if the unit measure is default so that we won't have to check
        // if the unit measure specified is valid...
        if (false.Equals(unitMeasureCode.Equals(defaultUnitMeasure, StringComparison.InvariantCultureIgnoreCase)))
        {
            bool isValidUnitMeasureForThisItem = false;

            using (var con = DB.NewSqlConnection())
            {
                con.Open();
                using (var reader = DB.GetRSFormat(con, "SELECT UnitMeasureCode FROM InventoryUnitMeasure with (NOLOCK) WHERE ItemCode= {0} AND UnitMeasureCode = {1}", DB.SQuote(itemCode), DB.SQuote(unitMeasureCode)))
                {
                    isValidUnitMeasureForThisItem = reader.Read();

                    if (isValidUnitMeasureForThisItem)
                    {
                        // maybe mixed case specified, just set..
                        unitMeasureCode = DB.RSField(reader, "UnitMeasureCode");
                    }
                }
            }

            if (!isValidUnitMeasureForThisItem)
            {
                GoNextPage(context);
            }
        }
        decimal Quantity = CommonLogic.FormLocaleDecimal("Quantity", ThisCustomer.LocaleSetting);//CommonLogic.QueryStringUSDecimal("Quantity");

        if (Quantity == 0)
        {
            Quantity = CommonLogic.FormNativeDecimal("Quantity");
        }

        if (Quantity == 0)
        {
            Quantity = 1;
        }

        Quantity = CommonLogic.RoundQuantity(Quantity);

        // Now let's check the shipping address if valid if specified
        if (ShippingAddressID != ThisCustomer.PrimaryShippingAddressID)
        {
            if (ThisCustomer.IsRegistered)
            {
                bool shippingAddressIsValidForThisCustomer = false;

                using (var con = DB.NewSqlConnection())
                {
                    con.Open();
                    using (var reader = DB.GetRSFormat(con, "SELECT ShipToCode FROM CustomerShipTo with (NOLOCK) WHERE CustomerCode = {0} AND IsActive = 1 AND ShipToCode = {1}", DB.SQuote(ThisCustomer.CustomerCode), DB.SQuote(ShippingAddressID)))
                    {
                        shippingAddressIsValidForThisCustomer = reader.Read();

                        if (shippingAddressIsValidForThisCustomer)
                        {
                            // maybe mixed case, just set...
                            ShippingAddressID = DB.RSField(reader, "ShipToCode");
                        }
                    }
                }

                if (!shippingAddressIsValidForThisCustomer)
                {
                    GoNextPage(context);
                }
            }
            else
            {
                ShippingAddressID = ThisCustomer.PrimaryShippingAddressID;
            }
        }

        var CartType = CartTypeEnum.ShoppingCart;

        if (CommonLogic.FormNativeInt("IsWishList") == 1 || CommonLogic.QueryStringUSInt("IsWishList") == 1)
        {
            CartType = CartTypeEnum.WishCart;
        }

        var giftRegistryItemType = GiftRegistryItemType.vItem;

        if (CommonLogic.FormNativeInt("IsAddToGiftRegistry") == 1 || CommonLogic.QueryStringUSInt("IsAddToGiftRegistry") == 1)
        {
            CartType = CartTypeEnum.GiftRegistryCart;
        }

        if (CommonLogic.FormNativeInt("IsAddToGiftRegistryOption") == 1 || CommonLogic.QueryStringUSInt("IsAddToGiftRegistryOption") == 1)
        {
            CartType             = CartTypeEnum.GiftRegistryCart;
            giftRegistryItemType = GiftRegistryItemType.vOption;
        }

        ShoppingCart cart = null;
        bool         itemIsARegistryItem = false;

        if (!itemCode.IsNullOrEmptyTrimmed())
        {
            #region " --GIFTREGISTRY-- "

            if (CartType == CartTypeEnum.GiftRegistryCart)
            {
                Guid?registryID = CommonLogic.FormCanBeDangerousContent("giftregistryOptions").TryParseGuid();
                if (registryID.HasValue)
                {
                    var selectedGiftRegistry = ThisCustomer.GiftRegistries.FindFromDb(registryID.Value);
                    if (selectedGiftRegistry != null)
                    {
                        bool             isKit = AppLogic.IsAKit(itemCode);
                        KitComposition   preferredComposition = null;
                        GiftRegistryItem registryItem         = null;

                        if (isKit)
                        {
                            preferredComposition = KitComposition.FromForm(ThisCustomer, itemCode);
                            var registrytems = selectedGiftRegistry.GiftRegistryItems.Where(giftItem => giftItem.ItemCode == itemCode &&
                                                                                            giftItem.GiftRegistryItemType == giftRegistryItemType);
                            Guid?matchedRegitryItemCode = null;
                            //Do this routine to check if there are kit items
                            //matched the selected kit items from the cart in the registry items
                            foreach (var regitm in registrytems)
                            {
                                regitm.IsKit = true;
                                var compositionItems = regitm.GetKitItemsFromComposition();

                                if (compositionItems.Count() == 0)
                                {
                                    continue;
                                }

                                var arrItemCodes = compositionItems.Select(item => item.ItemCode)
                                                   .ToArray();
                                var preferredItemCodes = preferredComposition.Compositions.Select(kititem => kititem.ItemCode);
                                var lst = arrItemCodes.Except(preferredItemCodes);

                                //has match
                                if (lst.Count() == 0)
                                {
                                    matchedRegitryItemCode = regitm.RegistryItemCode;
                                    break;
                                }
                            }

                            if (matchedRegitryItemCode.HasValue)
                            {
                                registryItem = selectedGiftRegistry.GiftRegistryItems.FirstOrDefault(giftItem => giftItem.RegistryItemCode == matchedRegitryItemCode);
                            }
                        }

                        //if not kit item get the item as is
                        if (registryItem == null && !isKit)
                        {
                            registryItem = selectedGiftRegistry.GiftRegistryItems.FirstOrDefault(giftItem => giftItem.ItemCode == itemCode &&
                                                                                                 giftItem.GiftRegistryItemType == giftRegistryItemType);
                        }

                        if (registryItem != null)
                        {
                            registryItem.Quantity       += Quantity;
                            registryItem.UnitMeasureCode = unitMeasureCode;
                            selectedGiftRegistry.GiftRegistryItems.UpdateToDb(registryItem);
                        }
                        else
                        {
                            registryItem = new GiftRegistryItem()
                            {
                                GiftRegistryItemType = giftRegistryItemType,
                                RegistryItemCode     = Guid.NewGuid(),
                                ItemCode             = itemCode,
                                Quantity             = Quantity,
                                RegistryID           = registryID.Value,
                                UnitMeasureCode      = unitMeasureCode
                            };

                            selectedGiftRegistry.GiftRegistryItems.AddToDb(registryItem);
                        }

                        if (isKit && preferredComposition != null)
                        {
                            registryItem.ClearKitItemsFromComposition();
                            preferredComposition.AddToGiftRegistry(registryID.Value, registryItem.RegistryItemCode);
                        }

                        HttpContext.Current.Response.Redirect(string.Format("~/editgiftregistry.aspx?{0}={1}", DomainConstants.GIFTREGISTRYPARAMCHAR, registryID.Value));
                    }
                }

                GoNextPage(context);
            }

            #endregion

            CartRegistryParam registryCartParam = null;
            if (AppLogic.AppConfigBool("GiftRegistry.Enabled"))
            {
                registryCartParam = new CartRegistryParam()
                {
                    RegistryID       = CommonLogic.FormGuid("RegistryID"),
                    RegistryItemCode = CommonLogic.FormGuid("RegistryItemCode")
                };
            }

            if (registryCartParam != null && registryCartParam.RegistryID.HasValue && registryCartParam.RegistryItemCode.HasValue)
            {
                ShippingAddressID   = GiftRegistryDA.GetPrimaryShippingAddressCodeOfOwnerByRegistryID(registryCartParam.RegistryID.Value);
                itemIsARegistryItem = true;
            }

            cart = new ShoppingCart(null, 1, ThisCustomer, CartType, string.Empty, false, true, string.Empty);
            if (Quantity > 0)
            {
                if (AppLogic.IsAKit(itemCode))
                {
                    var preferredComposition = KitComposition.FromForm(ThisCustomer, CartType, itemCode);

                    if (preferredComposition == null)
                    {
                        int itemCounter = 0;
                        int.TryParse(ProductID, out itemCounter);
                        var kitData = KitItemData.GetKitComposition(ThisCustomer, itemCounter, itemCode);

                        var kitContents = new StringBuilder();
                        foreach (var kitGroup in kitData.Groups)
                        {
                            if (kitContents.Length > 0)
                            {
                                kitContents.Append(",");
                            }

                            var selectedItems   = new StringBuilder();
                            int kitGroupCounter = kitGroup.Id;

                            var selectedKitItems = kitGroup.Items.Where(i => i.IsSelected == true);

                            foreach (var item in selectedKitItems)
                            {
                                if (selectedItems.Length > 0)
                                {
                                    selectedItems.Append(",");
                                }

                                //note: since we are adding the kit counter and kit item counter in KitItemData.GetKitComposition (stored proc. EcommerceGetKitItems)
                                //as "kit item counter", we'll reverse the process in order to get the "real kit item counter"

                                int kitItemCounter = item.Id - itemCounter;
                                selectedItems.Append(kitGroupCounter.ToString() + DomainConstants.KITCOMPOSITION_DELIMITER + kitItemCounter.ToString());
                            }
                            kitContents.Append(selectedItems.ToString());
                        }
                        preferredComposition = KitComposition.FromComposition(kitContents.ToString(), ThisCustomer, CartType, itemCode);
                    }

                    preferredComposition.PricingType = CommonLogic.FormCanBeDangerousContent("KitPricingType");

                    if (CommonLogic.FormBool("IsEditKit") &&
                        !CommonLogic.IsStringNullOrEmpty(CommonLogic.FormCanBeDangerousContent("KitCartID")) &&
                        InterpriseHelper.IsValidGuid(CommonLogic.FormCanBeDangerousContent("KitCartID")))
                    {
                        Guid cartID = new Guid(CommonLogic.FormCanBeDangerousContent("KitCartID"));
                        preferredComposition.CartID = cartID;
                    }
                    cart.AddItem(ThisCustomer, ShippingAddressID, itemCode, int.Parse(ProductID), Quantity, unitMeasureCode, CartType, preferredComposition, registryCartParam);
                }
                else
                {
                    cart.AddItem(ThisCustomer, ShippingAddressID, itemCode, int.Parse(ProductID), Quantity, unitMeasureCode, CartType, null, registryCartParam);
                }
            }

            string RelatedProducts = CommonLogic.QueryStringCanBeDangerousContent("relatedproducts").Trim();
            string UpsellProducts  = CommonLogic.FormCanBeDangerousContent("UpsellProducts").Trim();
            string combined        = string.Concat(RelatedProducts, UpsellProducts);

            if (combined.Length != 0 && CartType == CartTypeEnum.ShoppingCart)
            {
                string[] arrUpsell = combined.Split(',');
                foreach (string s in arrUpsell)
                {
                    string PID = s.Trim();
                    if (PID.Length == 0)
                    {
                        continue;
                    }

                    int UpsellProductID;
                    try
                    {
                        UpsellProductID = Localization.ParseUSInt(PID);
                        if (UpsellProductID != 0)
                        {
                            string ItemCode        = InterpriseHelper.GetInventoryItemCode(UpsellProductID);
                            string itemUnitMeasure = string.Empty;

                            using (var con = DB.NewSqlConnection())
                            {
                                con.Open();
                                using (var reader = DB.GetRSFormat(con, "SELECT ium.UnitMeasureCode FROM InventoryItem i with (NOLOCK) INNER JOIN InventoryUnitMeasure ium with (NOLOCK) ON i.ItemCode = ium.ItemCode AND IsBase = 1 WHERE i.ItemCode = {0}", DB.SQuote(ItemCode)))
                                {
                                    if (reader.Read())
                                    {
                                        itemUnitMeasure = DB.RSField(reader, "UnitMeasureCode");
                                    }
                                }
                            }

                            cart.AddItem(ThisCustomer, ShippingAddressID, ItemCode, UpsellProductID, 1, itemUnitMeasure, CartType);
                        }
                    }
                    catch { }
                }
            }
        }

        GoNextPage(context, itemIsARegistryItem, CartType, ThisCustomer);
    }
Esempio n. 5
0
        public void ProcessCart(bool DoingFullCheckout)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            ThisCustomer.RequireCustomerRecord();
            CartTypeEnum cte = CartTypeEnum.ShoppingCart;

            if (CommonLogic.QueryStringCanBeDangerousContent("CartType").Length != 0)
            {
                cte = (CartTypeEnum)CommonLogic.QueryStringUSInt("CartType");
            }
            cart = new InterpriseShoppingCart(null, 1, ThisCustomer, cte, string.Empty, false, true);

            if (!Page.IsPostBack)
            {
                string couponCode = string.Empty;
                if (cart.HasCoupon(ref couponCode))
                {
                    CouponCode.Text = couponCode;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(CouponCode.Text))
                {
                    cart.ClearCoupon();
                }
            }

            // check if credit on hold
            if (ThisCustomer.IsCreditOnHold)
            {
                Response.Redirect("shoppingcart.aspx");
            }

            if (cart.IsEmpty())
            {
                // can't have this at this point:
                switch (cte)
                {
                case CartTypeEnum.ShoppingCart:
                    Response.Redirect("shoppingcart.aspx");
                    break;

                case CartTypeEnum.WishCart:
                    Response.Redirect("wishlist.aspx");
                    break;

                case CartTypeEnum.GiftRegistryCart:
                    Response.Redirect("giftregistry.aspx");
                    break;

                default:
                    Response.Redirect("shoppingcart.aspx");
                    break;
                }
            }

            //Make it a method
            UpdateCartItems();

            // save coupon code, no need to reload cart object
            // will update customer record also:
            if (cte == CartTypeEnum.ShoppingCart)
            {
                if (!string.IsNullOrEmpty(CouponCode.Text))
                {
                    string errorMessage = string.Empty;
                    if (cart.IsCouponValid(ThisCustomer, CouponCode.Text, ref errorMessage))
                    {
                        cart.ApplyCoupon(CouponCode.Text);
                    }
                    else
                    {
                        // NULL out the coupon for this cusotmer...
                        InterpriseHelper.ClearCustomerCoupon(ThisCustomer.CustomerCode, ThisCustomer.IsRegistered);

                        ErrorMsgLabel.Text = errorMessage;
                        CouponCode.Text    = string.Empty;
                        return;
                    }
                }

                // check for upsell products
                if (CommonLogic.FormCanBeDangerousContent("Upsell").Length != 0)
                {
                    foreach (string s in CommonLogic.FormCanBeDangerousContent("Upsell").Split(','))
                    {
                        int ProductID = Localization.ParseUSInt(s);
                        if (ProductID == 0)
                        {
                            continue;
                        }

                        string itemCode = InterpriseHelper.GetInventoryItemCode(ProductID);
                        string shippingAddressID;

                        shippingAddressID = CommonLogic.IIF(ThisCustomer.IsNotRegistered, string.Empty, ThisCustomer.PrimaryShippingAddressID);

                        var umInfo = InterpriseHelper.GetItemDefaultUnitMeasure(itemCode);
                        cart.AddItem(ThisCustomer, shippingAddressID, itemCode, ProductID, 1, umInfo.Code, CartTypeEnum.ShoppingCart);
                    }
                }

                bool hasCheckedOptions = false;

                if (pnlOrderOptions.Visible)
                {
                    // Process the Order Options
                    foreach (RepeaterItem ri in OrderOptionsList.Items)
                    {
                        hasCheckedOptions = true;
                        DataCheckBox cbk = (DataCheckBox)ri.FindControl("OrderOptions");
                        if (cbk.Checked)
                        {
                            string      itemCode  = (string)cbk.Data;
                            HiddenField hfCounter = ri.FindControl("hfItemCounter") as HiddenField;
                            TextBox     txtNotes  = ri.FindControl("txtOrderOptionNotes") as TextBox;

                            string strNotes = HttpUtility.HtmlEncode(txtNotes.Text);
                            string notes    = CommonLogic.IIF((strNotes != null), CommonLogic.CleanLevelOne(strNotes), string.Empty);

                            //check the length of order option notes
                            //should not exceed 1000 characters including spaces
                            int maxLen = 1000;
                            if (notes.Length > maxLen)
                            {
                                notes = notes.Substring(0, maxLen);
                            }

                            string unitMeasureCode = string.Empty;

                            // check if the item has only 1 unit measure
                            // hence it's rendered as a label
                            // else it would be rendered as a drop down list
                            Label lblUnitMeasureCode = ri.FindControl("lblUnitMeasureCode") as Label;
                            if (null != lblUnitMeasureCode && lblUnitMeasureCode.Visible)
                            {
                                unitMeasureCode = lblUnitMeasureCode.Text;
                            }
                            else
                            {
                                // it's rendered as combobox because the item has multiple unit measures configured
                                DropDownList cboUnitMeasureCode = ri.FindControl("cboUnitMeasureCode") as DropDownList;
                                if (null != cboUnitMeasureCode && cboUnitMeasureCode.Visible)
                                {
                                    unitMeasureCode = cboUnitMeasureCode.SelectedValue;
                                }
                            }

                            if (CommonLogic.IsStringNullOrEmpty(unitMeasureCode))
                            {
                                throw new ArgumentException("Unit Measure not specified!!!");
                            }

                            //check if this Order Option has Restricted Quantity and Minimum Order Qty set.
                            decimal itemQuantity = 1;

                            using (var con = DB.NewSqlConnection())
                            {
                                con.Open();
                                using (var reader = DB.GetRSFormat(con, "SELECT iw.RestrictedQuantity, iw.MinOrderQuantity FROM InventoryItem i with (NOLOCK) INNER JOIN InventoryItemWebOption iw with (NOLOCK) ON i.ItemCode = iw.ItemCode AND iw.WebsiteCode = {0} WHERE i.ItemCode = {1}", DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode), DB.SQuote(itemCode)))
                                {
                                    if (reader.Read())
                                    {
                                        string  restrictedQuantitiesValue = DB.RSField(reader, "RestrictedQuantity");
                                        decimal minimumOrderQuantity      = Convert.ToDecimal(DB.RSFieldDecimal(reader, "MinOrderQuantity"));
                                        if (!CommonLogic.IsStringNullOrEmpty(restrictedQuantitiesValue))
                                        {
                                            string[] quantityValues = restrictedQuantitiesValue.Split(',');
                                            if (quantityValues.Length > 0)
                                            {
                                                int  ctr  = 0;
                                                bool loop = true;
                                                while (loop)
                                                {
                                                    int    quantity      = 0;
                                                    string quantityValue = quantityValues[ctr];
                                                    if (int.TryParse(quantityValue, out quantity))
                                                    {
                                                        if (quantity >= minimumOrderQuantity)
                                                        {
                                                            itemQuantity = quantity;
                                                            loop         = false;
                                                        }
                                                    }
                                                    ctr++;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (minimumOrderQuantity > 0)
                                            {
                                                itemQuantity = minimumOrderQuantity;
                                            }
                                        }
                                    }
                                }
                            }
                            // Add the selected Order Option....
                            Guid cartItemId = Guid.Empty;
                            cart.AddItem(ThisCustomer, ThisCustomer.PrimaryShippingAddressID, itemCode, int.Parse(hfCounter.Value), itemQuantity, unitMeasureCode, CartTypeEnum.ShoppingCart);
                        }
                    }
                }

                if (hasCheckedOptions)
                {
                    //refresh the option items
                    RenderOrderOptions();
                }

                if (OrderNotes.Visible)
                {
                    string sOrderNotes = CommonLogic.CleanLevelOne(OrderNotes.Text);
                    //check the length of order notes
                    //should not exceed 255 characters including spaces
                    if (sOrderNotes.Length > DomainConstants.ORDER_NOTE_MAX_LENGTH)
                    {
                        sOrderNotes = sOrderNotes.Substring(0, DomainConstants.ORDER_NOTE_MAX_LENGTH);
                    }

                    DB.ExecuteSQL(
                        String.Format("UPDATE Customer SET Notes = {0} WHERE CustomerCode = {1}",
                                      sOrderNotes.ToDbQuote(),
                                      ThisCustomer.CustomerCode.ToDbQuote())
                        );
                }
            }
            bool validated = true;

            if (cart.InventoryTrimmed)
            {
                // inventory got adjusted, send them back to the cart page to confirm the new values!
                ErrorMsgLabel.Text += Server.UrlDecode(AppLogic.GetString("shoppingcart.cs.43", SkinID, ThisCustomer.LocaleSetting));
                validated           = false;
            }
            cart = new InterpriseShoppingCart(base.EntityHelpers, SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, string.Empty, false, true);

            if (AppLogic.AppConfigBool("ShowShipDateInCart") && AppLogic.AppConfigBool("ShowStockHints"))
            {
                cart.BuildSalesOrderDetails();
            }

            if (cte == CartTypeEnum.WishCart)
            {
                Response.Redirect("wishlist.aspx");
            }
            if (cte == CartTypeEnum.GiftRegistryCart)
            {
                Response.Redirect("giftregistry.aspx");
            }

            if (DoingFullCheckout)
            {
                if (!cart.MeetsMinimumOrderAmount(AppLogic.AppConfigUSDecimal("CartMinOrderAmount")))
                {
                    validated = false;
                }

                if (!cart.MeetsMinimumOrderQuantity(AppLogic.AppConfigUSInt("MinCartItemsBeforeCheckout")))
                {
                    validated = false;
                }

                string couponCode         = string.Empty;
                string couponErrorMessage = string.Empty;
                if (cart.HasCoupon(ref couponCode) && !cart.IsCouponValid(ThisCustomer, couponCode, ref couponErrorMessage))
                {
                    validated = false;
                }

                //One page checkout is not implemented in mobile.

                //if (AppLogic.AppConfigBool("Checkout.UseOnePageCheckout") && !cart.HasMultipleShippingAddresses())
                //{
                //    Response.Redirect("checkout1.aspx");
                //}

                if (validated)
                {
                    if (ThisCustomer.IsRegistered && (ThisCustomer.PrimaryBillingAddressID == string.Empty)) // || !ThisCustomer.HasAtLeastOneAddress()
                    {
                        Response.Redirect("selectaddress.aspx?add=true&setPrimary=true&checkout=true&addressType=Billing");
                    }

                    if (ThisCustomer.IsRegistered && (ThisCustomer.PrimaryShippingAddressID == string.Empty)) //  || !ThisCustomer.HasAtLeastOneAddress()
                    {
                        Response.Redirect("selectaddress.aspx?add=true&setPrimary=true&checkout=False&addressType=Shipping");
                    }

                    if (ThisCustomer.IsNotRegistered || ThisCustomer.PrimaryBillingAddressID == string.Empty || ThisCustomer.PrimaryShippingAddressID == string.Empty || !ThisCustomer.HasAtLeastOneAddress())
                    {
                        Response.Redirect("checkoutanon.aspx?checkout=true");
                    }
                    else
                    {
                        if (AppLogic.AppConfigBool("SkipShippingOnCheckout") ||
                            !cart.HasShippableComponents())
                        {
                            cart.MakeShippingNotRequired();
                            Response.Redirect("checkoutpayment.aspx");
                        }

                        if ((cart.HasMultipleShippingAddresses() && cart.NumItems() <= AppLogic.MultiShipMaxNumItemsAllowed() && cart.CartAllowsShippingMethodSelection))
                        {
                            Response.Redirect("checkoutshippingmult.aspx");
                        }
                        else
                        {
                            Response.Redirect("checkoutshipping.aspx");
                        }
                    }
                }
                InitializePageContent();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            productID = CommonLogic.QueryStringUSInt("productId");
            ItemCode  = InterpriseHelper.GetInventoryItemCode(productID);
            EntityHelper CategoryHelper     = AppLogic.LookupHelper(base.EntityHelpers, "Category");
            EntityHelper SectionHelper      = AppLogic.LookupHelper(base.EntityHelpers, "Department");
            EntityHelper ManufacturerHelper = AppLogic.LookupHelper(base.EntityHelpers, "Manufacturer");

            CategoryID     = CommonLogic.QueryStringCanBeDangerousContent("CategoryID");
            DepartmentID   = CommonLogic.QueryStringCanBeDangerousContent("DepartmentID");
            ManufacturerID = CommonLogic.QueryStringCanBeDangerousContent("ManufacturerID");

            String SourceEntity   = "Category";
            String SourceEntityID = String.Empty;

            if (AppLogic.AppConfigBool("GoNonSecureAgain"))
            {
                SkinBase.GoNonSecureAgain();
            }
            // DOS attack prevention:
            if (AppLogic.OnLiveServer() && (Request.UrlReferrer == null || Request.UrlReferrer.Authority != Request.Url.Authority))
            {
                Response.Redirect(SE.MakeDriverLink("EmailError"));
            }
            if (ItemCode == String.Empty)
            {
                Response.Redirect("default.aspx");
            }
            if (AppLogic.ProductHasBeenDeleted(productID))
            {
                Response.Redirect(SE.MakeDriverLink("ProductNotFound"));
            }


            using (SqlConnection con = DB.NewSqlConnection())
            {
                con.Open();
                using (IDataReader rs = DB.GetRSFormat(con, "SELECT * FROM EcommerceViewProduct with (NOLOCK) " +
                                                       " WHERE Counter=" + productID +
                                                       " AND ShortString=" + DB.SQuote(ThisCustomer.LocaleSetting) +
                                                       " AND WebSiteCode=" + DB.SQuote(InterpriseHelper.ConfigInstance.WebSiteCode)))
                {
                    if (!rs.Read())
                    {
                        Response.Redirect("default.aspx");
                    }

                    SEName = SE.MungeName(DB.RSField(rs, "SEName"));
                    if (DB.RSField(rs, "ItemDescription").ToString() != String.Empty)
                    {
                        ProductName = DB.RSField(rs, "ItemDescription");
                    }
                    else
                    {
                        ProductName = DB.RSField(rs, "ItemName");
                    }

                    RequiresReg        = DB.RSFieldBool(rs, "RequiresRegistration");
                    ProductDescription = DB.RSField(rs, "ItemDescription");
                    if (AppLogic.ReplaceImageURLFromAssetMgr)
                    {
                        ProductDescription = ProductDescription.Replace("../images", "images");
                    }
                    String FileDescription = new ProductDescriptionFile(ItemCode, ThisCustomer.LocaleSetting, SkinID).Contents;
                    if (FileDescription.Length != 0)
                    {
                        ProductDescription += "<div align=\"left\">" + FileDescription + "</div>";
                    }
                }
            }

            if (Convert.ToInt32(CategoryID) == 0)
            {
                // no category passed in, pick first one that this product is mapped to:
                String tmpS = CategoryHelper.GetObjectEntities(ItemCode, false);
                if (tmpS.Length != 0)
                {
                    String[] catIDs = tmpS.Split(',');
                    CategoryID = Convert.ToString(Localization.ParseUSInt(catIDs[0]));
                }
            }

            string CategoryName     = CommonLogic.IIF(CategoryHelper.GetEntityField(CategoryID, "Description", ThisCustomer.LocaleSetting) != String.Empty, CategoryHelper.GetEntityField(CategoryID, "Description", ThisCustomer.LocaleSetting), CategoryHelper.GetEntityName(CategoryID, ThisCustomer.LocaleSetting));
            string SectionName      = CommonLogic.IIF(SectionHelper.GetEntityField(DepartmentID, "Description", ThisCustomer.LocaleSetting) != String.Empty, SectionHelper.GetEntityField(DepartmentID, "Description", ThisCustomer.LocaleSetting), SectionHelper.GetEntityName(DepartmentID, ThisCustomer.LocaleSetting));
            string ManufacturerName = CommonLogic.IIF(ManufacturerHelper.GetEntityField(ManufacturerID, "Description", ThisCustomer.LocaleSetting) != String.Empty, ManufacturerHelper.GetEntityField(ManufacturerID, "Description", ThisCustomer.LocaleSetting), ManufacturerHelper.GetEntityName(ManufacturerID, ThisCustomer.LocaleSetting));

            SourceEntity = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityName", true);
            String SourceEntityInstanceName = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityInstanceName", true);

            SourceEntityID = CommonLogic.CookieCanBeDangerousContent("LastViewedEntityInstanceID", true);

            // validate that source entity id is actually valid for this product:
            if (SourceEntityID.Length != 0)
            {
                ArrayList alE = EntityHelper.GetProductEntityList(ItemCode, SourceEntity);
                if (alE.IndexOf(Localization.ParseNativeInt(SourceEntityID)) == -1)
                {
                    SourceEntityID = String.Empty;
                }
            }

            if (SourceEntityID.Length != 0)
            {
                PickupBreadCrumb(ref SourceEntity, ref SourceEntityInstanceName, ref SourceEntityID, false);
            }
            else
            {
                PickupBreadCrumb(ref SourceEntity, ref SourceEntityInstanceName, ref SourceEntityID, true);
            }

            SectionTitle += "<span class=\"SectionTitleText\">";
            SectionTitle += ProductName;
            SectionTitle += "</span>";

            reqToAddress.ErrorMessage     = AppLogic.GetString("emailproduct.aspx.13", SkinID, ThisCustomer.LocaleSetting, true);
            regexToAddress.ErrorMessage   = AppLogic.GetString("emailproduct.aspx.14", SkinID, ThisCustomer.LocaleSetting, true);
            reqFromAddress.ErrorMessage   = AppLogic.GetString("emailproduct.aspx.16", SkinID, ThisCustomer.LocaleSetting, true);
            regexFromAddress.ErrorMessage = AppLogic.GetString("emailproduct.aspx.17", SkinID, ThisCustomer.LocaleSetting, true);

            if (!this.IsPostBack)
            {
                InitializePageContent();
            }
        }