protected override void OnInit(EventArgs e) { int productId = Request.QueryStringNativeInt("productId"); int groupId = Request.QueryStringNativeInt("groupId"); int kitItemId = Request.QueryStringNativeInt("itemId"); KitProductData kitProduct = KitProductData.Find(productId, Customer.Current); KitData = kitProduct; if (kitProduct != null) { KitGroupData kitGroup = kitProduct.GetGroup(groupId); if (kitGroup != null) { KitItemData item = kitGroup.GetItem(kitItemId); if (item != null) { KitItem = item; kitProduct.TempFileStub = Request.QueryStringCanBeDangerousContent("stub"); } } } base.OnInit(e); }
protected void rptItems_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { RadioButton rbItem = e.Item.FindControl <RadioButton>("rbItem"); KitItemData kitItem = e.Item.DataItemAs <KitItemData>(); rbItem.Attributes["onclick"] = string.Format("SetUniqueRadioButton('{0}', '{1}',this)", rptItems.UniqueID, rbItem.GroupName); if (kitItem.HasMappedVariant && !kitItem.VariantHasStock && AppLogic.AppConfigBool("KitInventory.DisableItemSelection")) { rbItem.Checked = false; rbItem.Enabled = false; kitItem.IsSelected = false; } else { bool isSetTrue = false; foreach (var kitItem1 in KitGroup.SelectableItems) { if (kitItem1.IsSelected == true) { isSetTrue = true; } } if (isSetTrue == false) { kitItem.IsSelected = true; } } rbItem.Checked = kitItem.IsSelected; } }
public string StockHint(KitItemData item) { string html = string.Empty; if (AppLogic.AppConfigBool("KitInventory.ShowStockHint")) { if (item.HasMappedVariant) { bool hasStock = item.VariantHasStock; string stockCssClass = string.Empty; string stockHintMessage = string.Empty; if (hasStock) { stockCssClass = "in-stock-hint"; stockHintMessage = AppLogic.GetString("OutofStock.DisplayInStockOnProductPage", ThisCustomer.SkinID, ThisCustomer.LocaleSetting); } else { stockCssClass = "out-stock-hint"; stockHintMessage = AppLogic.GetString("OutofStock.DisplayOutOfStockOnProductPage", ThisCustomer.SkinID, ThisCustomer.LocaleSetting); } html = string.Format(" <span class=\"{0}\">[{1}{2}]</span>", stockCssClass, stockHintMessage, ThisCustomer.IsAdminUser ? " (" + item.MappedVariant.InventoryCount.ToString() + ")" : string.Empty); } } return(html); }
private void ReconcilePricingGroupChanges(DataListItem container, KitItemData kitItem) { TextBox txtPriceDelta = container.FindControl <TextBox>("txtPriceDelta"); TextBox txtWeightDelta = container.FindControl <TextBox>("txtWeightDelta"); kitItem.PriceDelta = txtPriceDelta.Text.ToNativeDecimal(); kitItem.WeightDelta = txtWeightDelta.Text.ToNativeDecimal(); }
private void RepeaterItemIterator(RepeaterItem item) { HiddenField hdfKitItemId = item.FindControl <HiddenField>("hdfKitItemId"); int kitItemId = hdfKitItemId.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitItemId); kitItem.IsSelected = kitItem.HasCustomerUploadedImage; }
private void RepeaterItemIterator(RepeaterItem item) { HiddenField hdfKitItemId = item.FindControl <HiddenField>("hdfKitItemId"); CheckBox chkItem = item.FindControl <CheckBox>("chkItem"); int kitItemId = hdfKitItemId.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitItemId); kitItem.IsSelected = chkItem.Checked; }
public override void ResolveSelection() { foreach (ListItem lItem in cboKitItems.Items) { int kitId = lItem.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitId); kitItem.IsSelected = lItem.Selected; } }
protected void rptItems_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { RadioButton rbItem = e.Item.FindControl <RadioButton>("rbItem"); KitItemData kitItem = e.Item.DataItemAs <KitItemData>(); rbItem.Attributes["onclick"] = string.Format("SetUniqueRadioButton('{0}', '{1}',this)", rptItems.UniqueID, rbItem.GroupName); } }
private void RepeaterItemIterator(RepeaterItem item) { HiddenField hdfKitItemId = item.FindControl <HiddenField>("hdfKitItemId"); RadioButton rbItem = item.FindControl <RadioButton>("rbItem"); int kitItemId = hdfKitItemId.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitItemId); kitItem.IsSelected = rbItem.Checked; }
private void RepeaterItemIterator(RepeaterItem item) { HiddenField hdfKitItemId = item.FindControl <HiddenField>("hdfKitItemId"); TextBox txtKitItemText = item.FindControl <TextBox>("txtKitItemText"); int kitItemId = hdfKitItemId.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitItemId); kitItem.IsSelected = !string.IsNullOrEmpty(txtKitItemText.Text); kitItem.TextOption = txtKitItemText.Text; }
private void ReconcileInventoryGroupChanges(DataListItem container, KitItemData kitItem) { TextBox txtInventoryVariantId = container.FindControl <TextBox>("txtInventoryVariantId"); TextBox txtInventoryQuantityDelta = container.FindControl <TextBox>("txtInventoryQuantityDelta"); TextBox txtInventoryVariantColor = container.FindControl <TextBox>("txtInventoryVariantColor"); TextBox txtInventoryVariantSize = container.FindControl <TextBox>("txtInventoryVariantSize"); kitItem.InventoryVariantId = txtInventoryVariantId.Text.ToNativeInt(); kitItem.InventoryQuantityDelta = txtInventoryQuantityDelta.Text.ToNativeInt(); kitItem.InventoryVariantColor = txtInventoryVariantColor.Text; kitItem.InventoryVariantSize = txtInventoryVariantSize.Text; }
private void ReconcileGeneralGroupChanges(DataListItem container, KitItemData kitItem) { TextBox txtKitItemDisplayOrder = container.FindControl <TextBox>("txtKitItemDisplayOrder"); TextBox txtKitItemName = container.FindControl <TextBox>("txtKitItemName"); TextBox txtKitItemDescription = container.FindControl <TextBox>("txtKitItemDescription"); CheckBox chkKitItemDefault = container.FindControl <CheckBox>("chkKitItemDefault"); kitItem.Name = txtKitItemName.Text; kitItem.Description = txtKitItemDescription.Text; kitItem.DisplayOrder = txtKitItemDisplayOrder.Text.ToNativeInt(); kitItem.IsDefault = chkKitItemDefault.Checked; }
public override void ResolveSelection() { foreach (ListItem lItem in cboKitItems.Items) { int kitId = lItem.Value.ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitId); kitItem.IsSelected = lItem.Selected; } //KitGroup.ResolveRelativeDeltas(); //PopulateDropDown(); }
protected void rptItemImages_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName == "DeleteKitItemImage") { int kitItemId = e.CommandArgument.ToString().ToNativeInt(); KitItemData kitItem = KitGroup.GetItem(kitItemId); if (kitItem != null) { kitItem.DeleteImage(); } } BindData(); }
private void DeleteKitItem(DataListCommandEventArgs e) { var hdfGroupId = e.Item.FindControl <HiddenField>("hdfGroupId"); int groupId = hdfGroupId.Value.ToNativeInt(); KitGroupData kitGroup = this.Kit.GetGroup(groupId); int id = e.CommandArgument.ToString().ToNativeInt(); KitItemData toBeDeleted = kitGroup.GetItem(id); if (toBeDeleted != null) { kitGroup.DeleteItem(toBeDeleted); } }
public string KitItemRelativePriceDeltaDisplayText(KitItemData item, string currencySetting, bool isTaxable, KitProductData kitData) { if (item.IsSelected) { return(null); } var deltaText = item.RelativePriceDeltaIsAdd ? "Add" : "Subtract"; var customer = HttpContext.GetCustomer(); var deltaDisplayFormat = string.Empty; var vatSuffix = customer.VATSettingReconciled == VATSettingEnum.ShowPricesInclusiveOfVAT ? "inc vat" // Vat inclusive : "Excluding VAT"; // Vat exclusive var priceDelta = item.PriceDelta; if (item.Group.SelectionControl == KitGroupData.SINGLE_SELECT_DROPDOWN_LIST || item.Group.SelectionControl == KitGroupData.SINGLE_SELECT_RADIO_LIST) { priceDelta = item.RelativePriceDelta; } if (priceDelta == 0) { return(null); } if (kitData.ShowTaxInclusive) { var taxMultiplier = 1M + (kitData.TaxRate / 100M); priceDelta *= taxMultiplier; } deltaDisplayFormat = Localization.CurrencyStringForDisplayWithExchangeRate(Math.Abs(priceDelta), currencySetting); var displayText = string.Format("{0} {1}", deltaText, deltaDisplayFormat); if (AppLogic.AppConfigBool("VAT.Enabled") && isTaxable) { displayText = string.Format("{0} {1}", displayText, vatSuffix); } return(displayText); }
private void ResolveKitGroupChanges(DataListItem dataItem) { var hdfGroupId = dataItem.FindControl <HiddenField>("hdfGroupId"); int groupId = hdfGroupId.Value.ToNativeInt(); KitGroupData kitGroup = this.Kit.GetGroup(groupId); if (kitGroup != null) { bool wasNew = kitGroup.IsNew; ResolveKitItemChanges(dataItem, kitGroup); KitItemData newItem = kitGroup.Items.Find(item => item.IsNew); // if name was provided allow name, otherwise don't save if (newItem != null && string.IsNullOrEmpty(newItem.Name)) { // kick it out kitGroup.Items.Remove(newItem); } // validate this group and all it's items kitGroup.Validate(); if (kitGroup.IsValid) { string locale = GetCurrentLocale(); kitGroup.Save(locale); kitGroup.IsModified = true; } kitGroup.ProvideNewKitItem(); if (wasNew) { // previous group was a new kit group // allow for a new kit group for input var newGroup = kitGroup.Kit.ProvideNewGroup(); newGroup.ProvideNewKitItem(); // force the update of the whole groups pnlUpdateAllGroups.Update(); } } }
private void ReconcileInventoryGroupChanges(DataListItem container, KitItemData kitItem) { var txtInventoryVariantId = container.FindControl <TextBox>("txtInventoryVariantId"); var txtInventoryQuantityDelta = container.FindControl <TextBox>("txtInventoryQuantityDelta"); var txtInventoryVariantColor = container.FindControl <TextBox>("txtInventoryVariantColor"); var txtInventoryVariantSize = container.FindControl <TextBox>("txtInventoryVariantSize"); var variantId = txtInventoryVariantId.Text.ToNativeInt(); if (variantId == 0) { //Nothing was entered for the variantId so it doesn't make sense to save any of the other values that might have been entered. //Clear everything out in case they're de-coupling this item from a variant that had been saved previously kitItem.InventoryVariantId = 0; kitItem.InventoryQuantityDelta = 0; kitItem.InventoryVariantColor = string.Empty; kitItem.InventoryVariantSize = string.Empty; return; } var variant = new ProductVariant(variantId); if (variant.CreatedOn == DateTime.MinValue) { return; //The variant doesn't exist, so don't save anything } var color = txtInventoryVariantColor.Text; if (!variant.Colors.ContainsIgnoreCase(color)) { color = string.Empty; //This isn't a valid color for this variant } var size = txtInventoryVariantSize.Text; if (!variant.Sizes.ContainsIgnoreCase(size)) { size = string.Empty; //This isn't a valid size for this variant } kitItem.InventoryVariantId = variantId; kitItem.InventoryQuantityDelta = txtInventoryQuantityDelta.Text.ToNativeInt(); kitItem.InventoryVariantColor = color; kitItem.InventoryVariantSize = size; }
public override void RenderControl(HtmlTextWriter writer) { StringBuilder script = new StringBuilder(); script.Append("<script type=\"text/javascript\" language=\"Javascript\">\n"); script.Append(" Sys.Application.add_load(function() {\n"); Func <DataListItem, string, string> extractClientId = (item, controlName) => { return(item.FindControl(controlName).ClientID); }; for (int ctr = 0; ctr < this.KitGroup.Items.Count; ctr++) { KitItemData kitItem = this.KitGroup.Items[ctr]; string txtNameClientId = extractClientId(dlItemsGeneralGroup.Items[ctr], "txtKitItemName"); string txtDescriptionClientId = extractClientId(dlItemsGeneralGroup.Items[ctr], "txtKitItemDescription"); string lnkSelectClientId = extractClientId(dltemsInventoryVariantGroup.Items[ctr], "lnkSelect"); string txtVariantIdClientId = extractClientId(dltemsInventoryVariantGroup.Items[ctr], "txtInventoryVariantId"); string txtPriceClientId = extractClientId(dlItemsPricingGroup.Items[ctr], "txtPriceDelta"); string txtWeightClientId = extractClientId(dlItemsPricingGroup.Items[ctr], "txtWeightDelta"); script.AppendFormat("aspdnsf.Pages.EditKit.addKitItemLineControl( new aspdnsf.Controls.KitItemLineControl('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}') );\n", kitItem.Id, lnkSelectClientId, txtNameClientId, txtDescriptionClientId, txtVariantIdClientId, txtPriceClientId, txtWeightClientId); } script.Append(" });\n"); script.Append("</script>\n"); ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), script.ToString(), false); base.RenderControl(writer); }
private void ExtractEditTemplate(DataList ctrlList, Action <DataListItem, KitItemData> extractAndReconcileRoutine) { foreach (DataListItem item in ctrlList.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { var hdfKitItemId = item.FindControl <HiddenField>("hdfKitItemId"); if (hdfKitItemId != null) { int id = hdfKitItemId.Value.ToNativeInt(); // find the associated kit item KitItemData kitItem = KitGroup.GetItem(id); if (kitItem != null) { // determine if this is a new one extractAndReconcileRoutine(item, kitItem); } } } } }
public string KitItemDisplayText(KitItemData item, int maxCharLength) { string text = string.Empty; string displayName = item.Name; if (displayName.Length > maxCharLength) { displayName = CommonLogic.Ellipses(displayName, maxCharLength, true); } if (item.IsSelected) { // just return the name text = displayName; } else { text = string.Format("{0} [{1}]", displayName, KitItemRelativePriceDeltaDisplayText(item)); } return(text); }
public string KitItemRelativePriceDeltaDisplayText(KitItemData item) { if (item.IsSelected) { // Included in total price return(AppLogic.GetString("kitproduct.aspx.10", ThisCustomer.SkinID, ThisCustomer.LocaleSetting)); } else { string deltaText = string.Empty; if (item.RelativePriceDeltaIsAdd) { // Add deltaText = AppLogic.GetString("kitproduct.aspx.11", ThisCustomer.SkinID, ThisCustomer.LocaleSetting); } else { // Subtract deltaText = AppLogic.GetString("kitproduct.aspx.12", ThisCustomer.SkinID, ThisCustomer.LocaleSetting); } String deltaDisplayFormat = String.Empty; if (item.Group.SelectionControl == MULTI_SELECT_RADIO_LIST || item.Group.SelectionControl == TEXT_OPTION || item.Group.SelectionControl == TEXT_AREA) { deltaDisplayFormat = Localization.CurrencyStringForDisplayWithoutExchangeRate(item.PriceDelta, this.ThisCustomer.CurrencySetting); } else { deltaDisplayFormat = Localization.CurrencyStringForDisplayWithoutExchangeRate(item.RelativePriceDelta, this.ThisCustomer.CurrencySetting); } return(string.Format("{0} {1}", deltaText, deltaDisplayFormat.Replace("-", String.Empty))); } }
private void UpdateKitItems(bool updateAll) { foreach (RepeaterItem rptItemKit in dlMappedKits.Items) { if (rptItemKit.ItemType == ListItemType.Item || rptItemKit.ItemType == ListItemType.AlternatingItem) { HiddenField hdfKitProductId = rptItemKit.FindControl <HiddenField>("hdfKitProductId"); int kitId = hdfKitProductId.Value.ToNativeInt(); KitProductData kit = MappedKitProducts.Find(k => k.Id == kitId); if (kit != null) { Repeater rptKitGroups = rptItemKit.FindControl <Repeater>("rptKitGroups"); foreach (RepeaterItem rptItemGroup in rptKitGroups.Items) { if (rptItemGroup.ItemType == ListItemType.Item || rptItemGroup.ItemType == ListItemType.AlternatingItem) { HiddenField hdfGroupId = rptItemGroup.FindControl <HiddenField>("hdfGroupId"); int groupId = hdfGroupId.Value.ToNativeInt(); KitGroupData group = kit.GetGroup(groupId); if (group != null) { Repeater rptKitItems = rptItemGroup.FindControl <Repeater>("rptKitItems"); foreach (RepeaterItem rptKitItem in rptKitItems.Items) { if (rptKitItem.ItemType == ListItemType.Item || rptKitItem.ItemType == ListItemType.AlternatingItem) { HiddenField hdfKitItemtId = rptKitItem.FindControl <HiddenField>("hdfKitItemtId"); int kitItemId = hdfKitItemtId.Value.ToNativeInt(); CheckBox chkUpdate = rptKitItem.FindControl <CheckBox>("chkUpdate"); if (chkUpdate.Checked) { KitItemData kitItem = group.GetItem(kitItemId); if (kitItem != null) { kitItem.Name = XmlCommon.GetLocaleEntry(Variant.Name, LocaleSetting, false); kitItem.Description = XmlCommon.GetLocaleEntry(Variant.Description, LocaleSetting, false); if (updateAll) { kitItem.PriceDelta = Variant.SalePrice > decimal.Zero ? Variant.SalePrice : Variant.Price; kitItem.WeightDelta = Variant.Weight; } kitItem.Save(LocaleSetting); } } } } } } } } } } BindData(); }
public string KitItemDisplayText(KitItemData item) { return(KitItemDisplayText(item, 999)); }
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); }