示例#1
0
        private void ProcessCartItemAddresses()
        {
            var itemsPerAddress = new Dictionary <string, List <CartItem> >();
            var individualItems = rptCartItems.DataSource as List <CartItem>;

            for (int ctr = 0; ctr < individualItems.Count; ctr++)
            {
                var item = individualItems[ctr];

                if (item.IsDownload || item.IsService)
                {
                    // ship this to primary if not yet set..
                    _cart.SetItemAddress(item.m_ShoppingCartRecordID, ThisCustomer.PrimaryShippingAddress.AddressID);
                }
                else
                {
                    var ctrlAddressSelector = rptCartItems.Items[ctr].FindControl("ctrlAddressSelector") as AddressSelectorControl;

                    string preferredAddress = ctrlAddressSelector.SelectedAddress.AddressID;

                    if (item.m_ShippingAddressID != ctrlAddressSelector.SelectedAddress.AddressID)
                    {
                        if (!itemsPerAddress.ContainsKey(preferredAddress))
                        {
                            itemsPerAddress.Add(preferredAddress, new List <CartItem>());
                        }

                        var itemsInThisAddress = itemsPerAddress[preferredAddress];


                        // check if we have dups for this item
                        if (!itemsInThisAddress.Any(itemPerAddress => itemPerAddress.ItemCode == item.ItemCode))
                        {
                            itemsInThisAddress.Add(item);
                            item.MoveableQuantity = 1;
                        }
                        else
                        {
                            var savedCartItem = itemsInThisAddress.First(i => i.ItemCode == item.ItemCode);
                            savedCartItem.MoveableQuantity = savedCartItem.MoveableQuantity + 1;
                        }
                    }
                }
            }

            var lstRecAndTotalItems = _cart.CartItems.Select(i => new EcommerceCartRecordPerQuantity()
            {
                CartRecId = i.m_ShoppingCartRecordID,
                Total     = i.m_Quantity
            }).ToList();

            foreach (string preferredAddress in itemsPerAddress.Keys)
            {
                foreach (CartItem item in itemsPerAddress[preferredAddress])
                {
                    if (item.ItemType == Interprise.Framework.Base.Shared.Const.ITEM_TYPE_KIT)
                    {
                        var composition = KitComposition.FromCart(ThisCustomer, CartTypeEnum.ShoppingCart, item.ItemCode, item.Id);

                        var cartRecord = lstRecAndTotalItems.Single(ri => ri.CartRecId == item.m_ShoppingCartRecordID);

                        cartRecord.Total = cartRecord.Total - item.MoveableQuantity;

                        _cart.SetItemQuantity(cartRecord.CartRecId, cartRecord.Total);
                        _cart.AddItem(ThisCustomer, preferredAddress, item.ItemCode, item.ItemCounter, item.MoveableQuantity, item.UnitMeasureCode, CartTypeEnum.ShoppingCart, composition);
                        InitializeShoppingCart();
                    }
                    else
                    {
                        var cartRecord = lstRecAndTotalItems.Single(ri => ri.CartRecId == item.m_ShoppingCartRecordID);

                        cartRecord.Total = cartRecord.Total - item.MoveableQuantity;

                        _cart.SetItemQuantity(cartRecord.CartRecId, cartRecord.Total);
                        _cart.AddItem(ThisCustomer, preferredAddress, item.ItemCode, item.ItemCounter, item.MoveableQuantity, item.UnitMeasureCode, CartTypeEnum.ShoppingCart);
                        InitializeShoppingCart();
                    }
                }
            }
        }
示例#2
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();
            }
        }
示例#3
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            this.RequireCustomerRecord();

            SectionTitle = AppLogic.GetString("wishlist.aspx.1", SkinID, ThisCustomer.LocaleSetting);

            int?moveToCartId = "MoveToCartID".ToQueryString().TryParseIntUsLocalization();

            if (moveToCartId.HasValue)
            {
                int     cartId   = moveToCartId.Value;
                decimal?quantity = "MoveToCartQty".ToQueryString().TryParseDecimalUsLocalization();

                bool   cartItemExisting  = false;
                string itemCode          = string.Empty;
                string itemType          = string.Empty;
                string unitMeasureCode   = string.Empty;
                string shippingAddressID = string.Empty;
                Guid   cartGuid          = Guid.Empty;
                int    counter           = 0;
                // NOTE :
                // Move this logic on the Shopping Cart Form

                using (var con = DB.NewSqlConnection())
                {
                    con.Open();
                    using (var reader = DB.GetRSFormat(con, "SELECT wsc.ShoppingCartRecGuid, i.Counter, i.ItemCode, i.ItemType, wsc.UnitMeasureCode, wsc.ShippingAddressID FROM EcommerceShoppingCart wsc with (NOLOCK) INNER JOIN InventoryItem i with (NOLOCK) ON i.ItemCode = wsc.ItemCode WHERE wsc.ShoppingCartRecID = {0}", cartId))
                    {
                        cartItemExisting = reader.Read();
                        if (cartItemExisting)
                        {
                            cartGuid          = DB.RSFieldGUID2(reader, "ShoppingCartRecGuid");
                            counter           = DB.RSFieldInt(reader, "Counter");
                            itemCode          = DB.RSField(reader, "ItemCode");
                            itemType          = DB.RSField(reader, "ItemType");
                            unitMeasureCode   = DB.RSField(reader, "UnitMeasureCode");
                            shippingAddressID = DB.RSField(reader, "ShippingAddressID");
                        }
                    }
                }

                if (cartItemExisting)
                {
                    var kitCartWishListComposition = KitComposition.FromCart(ThisCustomer, CartTypeEnum.WishCart, itemCode, cartGuid);
                    cart = new InterpriseShoppingCart(base.EntityHelpers, SkinID, ThisCustomer, CartTypeEnum.ShoppingCart, String.Empty, false, true);

                    if (itemType == Interprise.Framework.Base.Shared.Const.ITEM_TYPE_KIT)
                    {
                        cart.AddItem(ThisCustomer,
                                     shippingAddressID,
                                     itemCode,
                                     counter,
                                     quantity.Value,
                                     unitMeasureCode,
                                     CartTypeEnum.ShoppingCart,
                                     kitCartWishListComposition);
                    }
                    else
                    {
                        cart.AddItem(ThisCustomer,
                                     shippingAddressID,
                                     itemCode,
                                     counter,
                                     quantity.Value,
                                     unitMeasureCode,
                                     CartTypeEnum.ShoppingCart);
                    }

                    ServiceFactory.GetInstance <IShoppingCartService>()
                    .ClearLineItemsAndKitComposition(new String[] { cartGuid.ToString() });
                }
                Response.Redirect("ShoppingCart.aspx");
            }

            cart = new InterpriseShoppingCart(base.EntityHelpers, SkinID, ThisCustomer, CartTypeEnum.WishCart, String.Empty, false, true);

            ProcessDelete();

            if (!IsPostBack)
            {
                string returnurl = CommonLogic.QueryStringCanBeDangerousContent("ReturnUrl");

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

                ViewState["returnurl"] = returnurl;
                InitializePageContent();
            }
            TopicWishListPageHeader.SetContext = this;
            TopicWishListPageFooter.SetContext = this;
        }
示例#4
0
        protected void Page_Load(object sender, System.EventArgs e)
        {
            Response.CacheControl = "private";
            Response.Expires      = 0;
            Response.AddHeader("pragma", "no-cache");

            Customer ThisCustomer = ((InterpriseSuiteEcommercePrincipal)Context.User).ThisCustomer;

            ThisCustomer.RequireCustomerRecord();

            InterpriseShoppingCart cart = new InterpriseShoppingCart(null, 1, ThisCustomer, CartTypeEnum.ShoppingCart, String.Empty, false, true);

            bool redirectToWishList = false;

            foreach (string key in Request.Form.AllKeys)
            {
                try
                {
                    if (!key.StartsWith("ProductID"))
                    {
                        continue;
                    }

                    // retrieve the item counter
                    // This may look obvious 4 but we want to make it expressive
                    string itemCounterValue     = Request.Form[key];
                    string quantityOrderedValue = Request.Form["Quantity"];

                    if (string.IsNullOrEmpty(quantityOrderedValue))
                    {
                        quantityOrderedValue = Request.Form["Quantity_" + itemCounterValue];

                        if (!string.IsNullOrEmpty(quantityOrderedValue))
                        {
                            quantityOrderedValue = quantityOrderedValue.Split(',')[0];
                        }
                    }

                    int counter         = 0;
                    int quantityOrdered = 0;
                    if (!string.IsNullOrEmpty(itemCounterValue) &&
                        int.TryParse(itemCounterValue, out counter) &&
                        !string.IsNullOrEmpty(quantityOrderedValue) &&
                        int.TryParse(quantityOrderedValue, out quantityOrdered) &&
                        quantityOrdered > 0)
                    {
                        string unitMeasureFieldKey   = "UnitMeasureCode_" + counter.ToString();
                        bool   useDefaultUnitMeasure = string.IsNullOrEmpty(Request.Form[unitMeasureFieldKey]);

                        string isWishListFieldKey = "IsWishList_" + counter.ToString();
                        bool   isWishList         = !string.IsNullOrEmpty(Request.Form[isWishListFieldKey]);
                        redirectToWishList = isWishList;

                        // we've got a valid counter
                        string itemCode = string.Empty;

                        using (var con = DB.NewSqlConnection())
                        {
                            con.Open();
                            using (var reader = DB.GetRSFormat(con, "SELECT ItemCode FROM InventoryItem with (NOLOCK) WHERE Counter = {0}", counter))
                            {
                                if (reader.Read())
                                {
                                    itemCode = DB.RSField(reader, "ItemCode");
                                }
                            }
                        }

                        if (!string.IsNullOrEmpty(itemCode))
                        {
                            UnitMeasureInfo?umInfo = null;

                            if (!useDefaultUnitMeasure)
                            {
                                umInfo = InterpriseHelper.GetItemUnitMeasure(itemCode, Request.Form[unitMeasureFieldKey]);
                            }

                            if (null == umInfo && useDefaultUnitMeasure)
                            {
                                umInfo = InterpriseHelper.GetItemDefaultUnitMeasure(itemCode);
                            }

                            if (null != umInfo && umInfo.HasValue)
                            {
                                if (isWishList)
                                {
                                    cart.CartType = CartTypeEnum.WishCart;
                                }
                                cart.AddItem(ThisCustomer, ThisCustomer.PrimaryShippingAddressID, itemCode, counter, quantityOrdered, umInfo.Value.Code, CartTypeEnum.ShoppingCart); //, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, CartTypeEnum.ShoppingCart, false, false, string.Empty, decimal.Zero);
                            }
                        }
                    }
                }
                catch
                {
                    // do nothing, add the items that we can
                }
            }

            if (redirectToWishList)
            {
                Response.Redirect("WishList.aspx");
            }
            else
            {
                Response.Redirect("ShoppingCart.aspx?add=true");
            }
        }