private KitComposition ComposeAddToCart() { KitComposition composition = new KitComposition(0); foreach (KitItemData selectedItem in KitData.SelectedItems) { KitCartItem kcItem = new KitCartItem(); kcItem.ProductID = KitData.Id; kcItem.VariantID = KitData.VariantId; kcItem.KitGroupID = selectedItem.Group.Id; kcItem.KitItemID = selectedItem.Id; kcItem.CustomerID = ThisCustomer.CustomerID; kcItem.TextOption = selectedItem.TextOption; int qty = 1; if (selectedItem.HasMappedVariant && selectedItem.InventoryQuantityDelta > 1) { qty = selectedItem.InventoryQuantityDelta; } kcItem.Quantity = qty; composition.Compositions.Add(kcItem); } return(composition); }
static KitComposition BuildCompositionFromModel(KitAddToCartPostModel model, KitProductData kitData, int customerId) { // Build up the kit selections from the model var selectedItems = model.GetSelectedItems(kitData); // Now build the composition var composition = new KitComposition(0); foreach (var selectedItem in selectedItems) { KitCartItem kcItem = new KitCartItem(); kcItem.ProductID = model.ProductId; kcItem.VariantID = model.VariantId; kcItem.KitGroupID = selectedItem.Group.Id; kcItem.KitItemID = selectedItem.Id; kcItem.CustomerID = customerId; kcItem.TextOption = selectedItem.TextOption; int qty = 1; if (selectedItem.HasMappedVariant && selectedItem.InventoryQuantityDelta > 1) { qty = selectedItem.InventoryQuantityDelta; } kcItem.Quantity = qty; composition.Compositions.Add(kcItem); } return(composition); }
static KitComposition BuildCompositionFromModel(KitAddToCartPostModel model, KitProductData kitData, int customerId) { // Build up the kit selections from the model var selectedItems = model.GetSelectedItems(kitData); // Validate Kit options if (kitData.HasRequiredGroups) { foreach (var requiredGroup in kitData.Groups.Where(g => g.IsRequired)) { var requirementIsMet = requiredGroup .Items .Intersect(selectedItems) .Any(); if (!requirementIsMet) { return(null); } } } // Now build the composition var composition = new KitComposition(0); foreach (var selectedItem in selectedItems) { KitCartItem kcItem = new KitCartItem(); kcItem.ProductID = model.ProductId; kcItem.VariantID = model.VariantId; kcItem.KitGroupID = selectedItem.Group.Id; kcItem.KitItemID = selectedItem.Id; kcItem.CustomerID = customerId; kcItem.TextOption = selectedItem.TextOption; int qty = 1; if (selectedItem.HasMappedVariant && selectedItem.InventoryQuantityDelta > 1) { qty = selectedItem.InventoryQuantityDelta; } kcItem.Quantity = qty; composition.Compositions.Add(kcItem); } return(composition); }
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(); } } } }
/// <summary> /// Processes individual line items in the address select list and reconciles it with the ShoppingCart line items /// </summary> private void ProcessCartItemAddresses() { /******************************************************************************* * 1. CartItem and address not modified * - Leave as is * 2. CartItem and address are modified * - Find out if this is the only CartItem * - Qty = 1 : only modify the shipping address * - Qty > 1 : Add another line item cloning the original line item *******************************************************************************/ // Data-Structure that will hold all shippingAddress selected for a particular shipping address // Key = The address id // Value = Collection of CartItems marked to ship to that Address Dictionary <int, CartItemCollection> itemsPerAddress = new Dictionary <int, CartItemCollection>(); CartItemCollection individualBoundItems = ctrlCartItemAddresses.DataSource as CartItemCollection; Dictionary <int, KitComposition> Compositions = new Dictionary <int, KitComposition>(); for (int ctr = 0; ctr < individualBoundItems.Count; ctr++) { CartItem boundItem = individualBoundItems[ctr]; //gather compositions so that we can reference the original later if (boundItem.IsAKit && !Compositions.ContainsKey(boundItem.ShoppingCartRecordID)) { Compositions.Add(boundItem.ShoppingCartRecordID, KitComposition.FromCart(ThisCustomer, CartTypeEnum.ShoppingCart, boundItem.ShoppingCartRecordID)); } if (boundItem.Shippable) { // get the selected address id from the address drop down int preferredAddress = 0; DropDownList cboShipToAddress = ctrlCartItemAddresses.Items[ctr].FindControl("cboShipToAddress") as DropDownList; HtmlInputHidden ihiddenAddressOption = ctrlCartItemAddresses.Items[ctr].FindControl("ShipAddressOption") as HtmlInputHidden; if (!Boolean.Parse(ihiddenAddressOption.Value)) { preferredAddress = AppLogic.GiftRegistryShippingAddressID(boundItem.GiftRegistryForCustomerID); } else { if (cboShipToAddress != null) { if (int.TryParse(cboShipToAddress.SelectedValue, out preferredAddress)) { // check to see if the address was modified if (boundItem.ShippingAddressID != preferredAddress) { if (!itemsPerAddress.ContainsKey(preferredAddress)) { itemsPerAddress.Add(preferredAddress, new CartItemCollection()); } CartItemCollection itemsInThisAddress = itemsPerAddress[preferredAddress]; // check if we duplicates if (!itemsInThisAddress.Contains(boundItem)) { // first line item found for this address itemsInThisAddress.Add(boundItem); boundItem.MoveableQuantity = 1; } else { // we have multiple line items that are marked // to ship to this address, increment boundItem.MoveableQuantity++; } } } } } } else { // non-shippable item // ship this to primary if not yet set.. // get the original cartItem from the ShoppingCart line items CartItem originalCartItem = cart.CartItems.Find(boundItem.ShoppingCartRecordID); if (originalCartItem != null) { cart.SetItemAddress(originalCartItem.ShoppingCartRecordID, ThisCustomer.PrimaryShippingAddressID); } } } foreach (int preferredAddress in itemsPerAddress.Keys) { foreach (CartItem item in itemsPerAddress[preferredAddress]) { // get the original cartItem from the ShoppingCart line items CartItem originalCartItem = cart.CartItems.Find(item.ShoppingCartRecordID); if (originalCartItem == null) { continue; } // reset the quantity for the original line item that got sliced int resetQuantity = originalCartItem.Quantity - item.MoveableQuantity; KitComposition itemKitComposition = null; if (item.IsAKit && Compositions.ContainsKey(item.ShoppingCartRecordID)) { itemKitComposition = Compositions[item.ShoppingCartRecordID]; } if (resetQuantity == 0 || item.IsGift) { cart.SetItemAddress(originalCartItem.ShoppingCartRecordID, preferredAddress); } else { cart.SetItemQuantity(originalCartItem.ShoppingCartRecordID, resetQuantity); // now duplicate the line item but for this shipping address cart.AddItem(ThisCustomer, preferredAddress, item.ProductID, item.VariantID, item.MoveableQuantity, item.ChosenColor, item.ChosenColorSKUModifier, item.ChosenSize, item.ChosenSizeSKUModifier, item.TextOption, CartTypeEnum.ShoppingCart, false, false, item.GiftRegistryForCustomerID, item.CustomerEntersPrice ? item.Price : decimal.Zero, itemKitComposition, item.IsGift); } } } }
protected void Page_Load(object sender, System.EventArgs e) { Response.CacheControl = "private"; Response.Expires = 0; Response.AddHeader("pragma", "no-cache"); ThisCustomer.RequireCustomerRecord(); String ReturnURL = CommonLogic.QueryStringCanBeDangerousContent("ReturnURL"); AppLogic.CheckForScriptTag(ReturnURL); CartTypeEnum CartType = CartTypeEnum.ShoppingCart; if (CommonLogic.FormNativeInt("IsWishList") == 1 || CommonLogic.QueryStringUSInt("IsWishList") == 1) { CartType = CartTypeEnum.WishCart; } if (CommonLogic.FormNativeInt("IsGiftRegistry") == 1 || CommonLogic.QueryStringUSInt("IsGiftRegistry") == 1) { CartType = CartTypeEnum.GiftRegistryCart; } if (AppLogic.HideForWholesaleSite(ThisCustomer.CustomerLevelID)) { Response.Redirect("Default.aspx"); } if (!ThisCustomer.IsRegistered && AppLogic.AppConfigBool("DisallowAnonCustomerToCreateWishlist") && AppLogic.ProductIsMLExpress() == false) { string ErrMsg = string.Empty; ErrorMessage er; if (CommonLogic.FormNativeInt("IsWishList") == 1 || CommonLogic.QueryStringUSInt("IsWishList") == 1) { ErrMsg = AppLogic.GetString("signin.aspx.27", 1, ThisCustomer.LocaleSetting); er = new ErrorMessage(ErrMsg); Response.Redirect("signin.aspx?ErrorMsg=" + er.MessageId + "&ReturnUrl=" + Security.UrlEncode(ReturnURL)); } if (CommonLogic.FormNativeInt("IsGiftRegistry") == 1 || CommonLogic.QueryStringUSInt("IsGiftRegistry") == 1) { ErrMsg = AppLogic.GetString("signin.aspx.28", 1, ThisCustomer.LocaleSetting); er = new ErrorMessage(ErrMsg); Response.Redirect("signin.aspx?ErrorMsg=" + er.MessageId + "&ReturnUrl=" + Security.UrlEncode(ReturnURL)); } } // if editing, nuke what was there, it will be replaced from what was submitted now from the product page. // NOTE. if a kit or pack was "edited", you don't have to do this, and ShoppingCartRecID is not material (and should not be in the form post) // kits and packs are "moved" from active cart to temp cart records, so they won't have a cart record id to begin with. They are built in the KitCart and CustomCart tables instead int ShoppingCartRecID = CommonLogic.FormUSInt("CartRecID"); // only used for (non kit or pack) product/order edits from prior cart record if (ShoppingCartRecID == 0) { ShoppingCartRecID = CommonLogic.QueryStringUSInt("CartRecID"); } if (ShoppingCartRecID != 0) { DB.ExecuteSQL("delete from ShoppingCart where ShoppingCartRecID=" + ShoppingCartRecID.ToString() + " and CustomerID=" + ThisCustomer.CustomerID.ToString() + " and CartType=" + ((int)CartType).ToString() + " and StoreID = " + AppLogic.StoreID()); } int ShippingAddressID = CommonLogic.QueryStringUSInt("ShippingAddressID"); // only used for multi-ship if (ShippingAddressID == 0) { ShippingAddressID = CommonLogic.FormNativeInt("ShippingAddressID"); } if ((ShippingAddressID == 0 || !ThisCustomer.OwnsThisAddress(ShippingAddressID)) && ThisCustomer.PrimaryShippingAddressID != 0) { ShippingAddressID = ThisCustomer.PrimaryShippingAddressID; } int ProductID = CommonLogic.QueryStringUSInt("ProductID"); if (ProductID == 0) { ProductID = CommonLogic.FormUSInt("ProductID"); } int VariantID = CommonLogic.QueryStringUSInt("VariantID"); if (VariantID == 0) { VariantID = CommonLogic.FormUSInt("VariantID"); } if (ProductID == 0) { ProductID = AppLogic.GetVariantProductID(VariantID); } // if no VariantID is located, get the default variantID for the product if (VariantID == 0) { VariantID = AppLogic.GetDefaultProductVariant(ProductID); } int Quantity = CommonLogic.QueryStringUSInt("Quantity"); if (Quantity == 0) { Quantity = CommonLogic.FormNativeInt("Quantity"); } if (Quantity == 0) { Quantity = 1; } VariantStyleEnum VariantStyle = (VariantStyleEnum)CommonLogic.QueryStringUSInt("VariantStyle"); if (CommonLogic.QueryStringCanBeDangerousContent("VariantStyle").Length == 0) { VariantStyle = (VariantStyleEnum)CommonLogic.FormNativeInt("VariantStyle"); } decimal CustomerEnteredPrice = CommonLogic.FormNativeDecimal("Price"); if (CustomerEnteredPrice == System.Decimal.Zero) { CustomerEnteredPrice = CommonLogic.QueryStringNativeDecimal("Price"); } if (!AppLogic.VariantAllowsCustomerPricing(VariantID)) { CustomerEnteredPrice = System.Decimal.Zero; } if (CustomerEnteredPrice < System.Decimal.Zero) { CustomerEnteredPrice = -CustomerEnteredPrice; } int CustomerID = ThisCustomer.CustomerID; if (Currency.GetDefaultCurrency() != ThisCustomer.CurrencySetting && CustomerEnteredPrice != 0) { CustomerEnteredPrice = Currency.Convert(CustomerEnteredPrice, ThisCustomer.CurrencySetting, Localization.StoreCurrency()); } // QueryString params override Form Params! String ChosenColor = String.Empty; String ChosenColorSKUModifier = String.Empty; String ChosenSize = String.Empty; String ChosenSizeSKUModifier = String.Empty; String TextOption = CommonLogic.FormCanBeDangerousContent("TextOption"); if (CommonLogic.QueryStringCanBeDangerousContent("TextOption").Length != 0) { TextOption = Security.HtmlEncode(CommonLogic.QueryStringCanBeDangerousContent("TextOption")); } // the color & sizes coming in here are MUST be in the Master WebConfig Locale ALWAYS! if (CommonLogic.QueryStringCanBeDangerousContent("Color").Length != 0) { String[] ColorSel = CommonLogic.QueryStringCanBeDangerousContent("Color").Split(','); try { ChosenColor = Security.HtmlEncode(ColorSel[0]); } catch { } try { ChosenColorSKUModifier = Security.HtmlEncode(ColorSel[1]); } catch { } } if (ChosenColor.Length == 0 && CommonLogic.FormCanBeDangerousContent("Color").Length != 0) { String[] ColorSel = CommonLogic.FormCanBeDangerousContent("Color").Split(','); try { ChosenColor = Security.HtmlEncode(ColorSel[0]).Trim(); } catch { } try { ChosenColorSKUModifier = Security.HtmlEncode(ColorSel[1]); } catch { } } if (CommonLogic.QueryStringCanBeDangerousContent("Size").Length != 0) { String[] SizeSel = CommonLogic.QueryStringCanBeDangerousContent("Size").Split(','); try { ChosenSize = Security.HtmlEncode(SizeSel[0]).Trim(); } catch { } try { ChosenSizeSKUModifier = Security.HtmlEncode(SizeSel[1]); } catch { } } if (ChosenSize.Length == 0 && CommonLogic.FormCanBeDangerousContent("Size").Length != 0) { String[] SizeSel = CommonLogic.FormCanBeDangerousContent("Size").Split(','); try { ChosenSize = Security.HtmlEncode(SizeSel[0]).Trim(); } catch { } try { ChosenSizeSKUModifier = Security.HtmlEncode(SizeSel[1]); } catch { } } if (VariantStyle == VariantStyleEnum.ERPWithRollupAttributes) { String match = "<GroupAttributes></GroupAttributes>"; String match2 = "<GroupAttributes></GroupAttributes>"; if (ChosenSize.Trim().Length != 0 && ChosenColor.Trim().Length != 0) { match = "<GroupAttributes><GroupAttributeName=\"Attr1\"Value=\"" + ChosenSize + "\"/><GroupAttributeName=\"Attr2\"Value=\"" + ChosenColor + "\"/></GroupAttributes>"; match2 = "<GroupAttributes><GroupAttributeName=\"Attr1\"Value=\"" + ChosenColor + "\"/><GroupAttributeName=\"Attr2\"Value=\"" + ChosenSize + "\"/></GroupAttributes>"; } else if (ChosenSize.Trim().Length != 0 && ChosenColor.Trim().Length == 0) { match = "<GroupAttributes><GroupAttributeName=\"Attr1\"Value=\"" + ChosenSize + "\"/></GroupAttributes>"; } else if (ChosenSize.Trim().Length == 0 && ChosenColor.Trim().Length != 0) { match = "<GroupAttributes><GroupAttributeName=\"Attr1\"Value=\"" + ChosenColor + "\"/></GroupAttributes>"; } // reset variant id to the proper attribute match! using (SqlConnection con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (IDataReader rsERP = DB.GetRS("select VariantID,ExtensionData2 from ProductVariant with (NOLOCK) where VariantID=" + VariantID.ToString(), con)) { while (rsERP.Read()) { String thisVariantMatch = DB.RSField(rsERP, "ExtensionData2").Replace(" ", "").Trim(); match = Regex.Replace(match, "\\s+", "", RegexOptions.Compiled); match2 = Regex.Replace(match2, "\\s+", "", RegexOptions.Compiled); thisVariantMatch = Regex.Replace(thisVariantMatch, "\\s+", "", RegexOptions.Compiled); if (match.Equals(thisVariantMatch, StringComparison.InvariantCultureIgnoreCase) || match2.Equals(thisVariantMatch, StringComparison.InvariantCultureIgnoreCase)) { VariantID = DB.RSFieldInt(rsERP, "VariantID"); break; } } } } } ShoppingCart cart = new ShoppingCart(1, ThisCustomer, CartType, 0, false); if (Quantity > 0) { if (AppLogic.IsAKit(ProductID)) { // -- new kit format -- // bool productIsUsingKit2XmlPackage = !CommonLogic.IsStringNullOrEmpty(CommonLogic.FormCanBeDangerousContent("KitItems")); if (productIsUsingKit2XmlPackage) { if (CommonLogic.FormBool("IsEditKit") && CommonLogic.FormUSInt("CartRecID") > 0) { int cartId = CommonLogic.FormUSInt("CartRecID"); AppLogic.ClearKitItems(ThisCustomer, ProductID, VariantID, cartId); } KitComposition preferredComposition = KitComposition.FromForm(ThisCustomer, ProductID, VariantID); String tmp = DB.GetNewGUID(); int NewRecID = cart.AddItem(ThisCustomer, ShippingAddressID, ProductID, VariantID, Quantity, string.Empty, ChosenColorSKUModifier, ChosenSize, ChosenSizeSKUModifier, TextOption, CartType, false, false, 0, System.Decimal.Zero, preferredComposition); } else { String tmp = DB.GetNewGUID(); int NewRecID = cart.AddItem(ThisCustomer, ShippingAddressID, ProductID, VariantID, Quantity, ChosenColor, ChosenColorSKUModifier, ChosenSize, ChosenSizeSKUModifier, TextOption, CartType, false, false, 0, System.Decimal.Zero); } } else { cart.AddItem(ThisCustomer, ShippingAddressID, ProductID, VariantID, Quantity, ChosenColor, ChosenColorSKUModifier, ChosenSize, ChosenSizeSKUModifier, TextOption, CartType, false, false, 0, CustomerEnteredPrice); } } // handle upsell products: String UpsellProducts = CommonLogic.FormCanBeDangerousContent("UpsellProducts").Trim(); if (UpsellProducts.Length != 0 && CartType == CartTypeEnum.ShoppingCart) { foreach (String s in UpsellProducts.Split(',')) { String PID = s.Trim(); if (PID.Length != 0) { int UpsellProductID = 0; try { UpsellProductID = Localization.ParseUSInt(PID); if (UpsellProductID != 0) { int UpsellVariantID = AppLogic.GetProductsFirstVariantID(UpsellProductID); if (UpsellVariantID != 0) { // this variant COULD have one size or color, so set it up like that: String Sizes = String.Empty; String SizeSKUModifiers = String.Empty; String Colors = String.Empty; String ColorSKUModifiers = String.Empty; using (SqlConnection con = new SqlConnection(DB.GetDBConn())) { con.Open(); using (IDataReader rs = DB.GetRS("select Sizes,SizeSKUModifiers,Colors,ColorSKUModifiers from ProductVariant with (NOLOCK) where VariantID=" + UpsellVariantID.ToString(), con)) { if (rs.Read()) { Sizes = DB.RSFieldByLocale(rs, "Sizes", Localization.GetDefaultLocale()); SizeSKUModifiers = DB.RSFieldByLocale(rs, "SizeSKUModifiers", Localization.GetDefaultLocale()); Colors = DB.RSFieldByLocale(rs, "Colors", Localization.GetDefaultLocale()); ColorSKUModifiers = DB.RSFieldByLocale(rs, "ColorSKUModifiers", Localization.GetDefaultLocale()); } } } // safety check: if (Sizes.IndexOf(',') != -1) { Sizes = String.Empty; SizeSKUModifiers = String.Empty; } // safety check: if (Colors.IndexOf(',') != -1) { Colors = String.Empty; ColorSKUModifiers = String.Empty; } cart.AddItem(ThisCustomer, ShippingAddressID, UpsellProductID, UpsellVariantID, 1, Colors, ColorSKUModifiers, Sizes, SizeSKUModifiers, String.Empty, CartType, false, false, 0, System.Decimal.Zero); Decimal PR = AppLogic.GetUpsellProductPrice(ProductID, UpsellProductID, ThisCustomer.CustomerLevelID); DB.ExecuteSQL("update shoppingcart set IsUpsell=1, ProductPrice=" + Localization.CurrencyStringForDBWithoutExchangeRate(PR) + " where CartType=" + ((int)CartType).ToString() + " and CustomerID=" + ThisCustomer.CustomerID.ToString() + " and ProductID=" + UpsellProductID.ToString() + " and VariantID=" + UpsellVariantID.ToString() + " and convert(nvarchar(1000),ChosenColor)='' and convert(nvarchar(1000),ChosenSize)='' and convert(nvarchar(1000),TextOption)=''"); } } } catch { } } } } cart = null; AppLogic.eventHandler("AddToCart").CallEvent("&AddToCart=true&VariantID=" + VariantID.ToString() + "&ProductID=" + ProductID.ToString() + "&ChosenColor=" + ChosenColor + "&ChosenSize=" + ChosenSize); if (AppLogic.AppConfig("AddToCartAction").Equals("STAY", StringComparison.InvariantCultureIgnoreCase) && ReturnURL.Length != 0) { Response.Redirect(ReturnURL); } else { if (ReturnURL.Length == 0) { ReturnURL = String.Empty; if (Request.UrlReferrer != null) { ReturnURL = Request.UrlReferrer.AbsoluteUri; // could be null } if (ReturnURL == null) { ReturnURL = String.Empty; } } if (CartType == CartTypeEnum.WishCart) { Response.Redirect("wishlist.aspx?ReturnUrl=" + Security.UrlEncode(ReturnURL)); } if (CartType == CartTypeEnum.GiftRegistryCart) { Response.Redirect("giftregistry.aspx?ReturnUrl=" + Security.UrlEncode(ReturnURL)); } Response.Redirect("ShoppingCart.aspx?add=true&ReturnUrl=" + Security.UrlEncode(ReturnURL)); } }
protected void AddToCart(CartTypeEnum cartType) { try { if (KitData.HasFileUploadGroup) { KitData.MoveAllTempImagesToOrdered(); } KitComposition composition = ComposeAddToCart(); if (KitData.HasRequiredGroups) { List <String> RequiredGroupNames = new List <String>(); foreach (KitGroupData requiredGroup in KitData.Groups) { if (requiredGroup.IsRequired) { int hasBeenSelected = composition.Compositions.Where(kci => kci.KitGroupID.Equals(requiredGroup.Id)).Count(); if (hasBeenSelected == 0) { RequiredGroupNames.Add(requiredGroup.Name); } } } if (RequiredGroupNames.Count > 0) { StringBuilder sb = new StringBuilder(1000); sb.Append(AppLogic.GetString("product.kit2product.xml.config.16", ThisCustomer.LocaleSetting)); sb.Append("<ul data-role=\"listview\">"); foreach (String requiredGroup in RequiredGroupNames) { sb.Append("<li>" + requiredGroup + "</li>"); } sb.Append("</ul>"); ShowError(sb.ToString()); return; } } String tmp = DB.GetNewGUID(); ShoppingCart cart = new ShoppingCart(1, ThisCustomer, cartType, 0, false); int qty = GetQuantity(); if (KitData.HasCartMapping) { AppLogic.ClearKitItems(ThisCustomer, KitData.Id, KitData.VariantId, KitData.ShoppingCartRecordId); CartItem lineItem = cart.CartItems.FirstOrDefault(item => item.ShoppingCartRecordID == KitData.ShoppingCartRecordId); cart.SetItemQuantity(lineItem.ShoppingCartRecordID, qty); cart.ProcessKitComposition(composition, KitData.Id, KitData.VariantId, KitData.ShoppingCartRecordId); } else { //GFS - If customer a session has been cleared and no cookies are available, we must create a customer record to associate the new cart ID to. //If this is not done, adding a kit product within the said environment will render an empty shopping cart. ThisCustomer.RequireCustomerRecord(); int shipId = ThisCustomer.PrimaryShippingAddressID; int NewRecID = cart.AddItem(ThisCustomer, ThisCustomer.PrimaryShippingAddressID, KitData.Id, KitData.VariantId, qty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, cartType, false, false, 0, System.Decimal.Zero, composition); } } catch { } bool stayOnThisPage = AppLogic.AppConfig("AddToCartAction").Equals("STAY", StringComparison.InvariantCultureIgnoreCase); if (stayOnThisPage) { // some tokens like the shoppingcart qty may already be rendered // we therefore need to re-display the page to display the correct qty Response.Redirect(this.Request.Url.ToString()); } else { string returnUrl = CommonLogic.GetThisPageName(false) + "?" + CommonLogic.ServerVariables("QUERY_STRING"); switch (cartType) { case CartTypeEnum.ShoppingCart: Response.Redirect(ResolveClientUrl("~/ShoppingCart.aspx?add=true&ReturnUrl=" + Security.UrlEncode(returnUrl))); break; case CartTypeEnum.GiftRegistryCart: Response.Redirect(ResolveClientUrl("~/giftregistry.aspx?ReturnUrl=" + Security.UrlEncode(returnUrl))); break; case CartTypeEnum.WishCart: Response.Redirect(ResolveClientUrl("~/wishlist.aspx?ReturnUrl=" + Security.UrlEncode(returnUrl))); break; } } }
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; }
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); }