/// <summary> /// On BtnAdd click event. /// </summary> protected void BtnAdd_Click(object sender, EventArgs e) { // Check 'EcommerceModify' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } string allUnits = null; string allSkuId = null; foreach (KeyValuePair <int, TextBox> item in quantityControls) { // Get params int skuId = item.Key; TextBox txtUnits = item.Value; // Get unit count int units = ValidationHelper.GetInteger(txtUnits.Text, 0); if (units > 0) { // Get product and localized name SKUInfo product = SKUInfoProvider.GetSKUInfo(skuId); if (product != null) { string skuName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(product.SKUName)); // Abort inserting products to the shopping cart ifIf product has some product options if (!DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(skuId, true))) { // Show error message ShowError(string.Format(GetString("Order_Edit_AddItems.ProductOptionsRequired"), skuName)); return; } // If selected product is a donation if ((product != null) && (product.SKUProductType == SKUProductTypeEnum.Donation)) { // If donation is customizable if (product.SKUPrivateDonation || !((product.SKUMinPrice == product.SKUPrice) && (product.SKUMaxPrice == product.SKUPrice))) { // Show error message ShowError(string.Format(GetString("order_edit_additems.donationpropertiesrequired"), skuName)); return; } } // Create strings with SKU IDs and units separated by ';' allSkuId += skuId.ToString() + ";"; allUnits += units.ToString() + ";"; } } } // Close this modal window and refresh parent values in window CloseWindow(allSkuId, allUnits); }
protected void btnAddOneUnit_Click(object sender, EventArgs e) { // Get SKU ID int skuId = ValidationHelper.GetInteger(((LinkButton)sender).CommandArgument, 0); // Get product SKUInfo skui = SKUInfoProvider.GetSKUInfo(skuId); bool hasProductOptions = !DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(skuId, true)); bool isCustomizableDonation = ((skui != null) && (skui.SKUProductType == SKUProductTypeEnum.Donation)) && (skui.SKUPrivateDonation || !((skui.SKUMinPrice == skui.SKUPrice) && (skui.SKUMaxPrice == skui.SKUPrice))); // If product has product options or product is a customizable donation // -> abort inserting products to the shopping cart if (hasProductOptions || isCustomizableDonation) { // Hide products this.plcProducts.Visible = false; // Set title message per specific case if (hasProductOptions && isCustomizableDonation) { this.lblTitle.ResourceString = "order_edit_additems.donationpropertiesproductoptions"; } else if (hasProductOptions) { this.lblTitle.ResourceString = "order_edit_additems.productoptions"; } else if (isCustomizableDonation) { this.lblTitle.ResourceString = "order_edit_additems.donationproperties"; } // Save SKU ID to the viewstate this.SKUID = skuId; // Initialize shopping cart item selector this.cartItemSelector.SKUID = this.SKUID; this.cartItemSelector.ShowProductOptions = hasProductOptions; this.cartItemSelector.ShowDonationProperties = isCustomizableDonation; this.cartItemSelector.ReloadData(); // Show shopping cart item selector this.plcSelector.Visible = true; } else { // Add product to shopping cart and close dialog window ScriptHelper.RegisterClientScriptBlock(this.Page, typeof(string), "addproduct", ScriptHelper.GetScript("AddProducts(" + skuId + ", 1);")); } }
protected void Page_Load(object sender, EventArgs e) { lblAvailable.Text = GetString("com.sku.categoriesavailable"); if (ProductID > 0) { // Get the active users DataSet ds = OptionCategoryInfoProvider.GetSKUOptionCategories(ProductID, false); if (!DataHelper.DataSourceIsEmpty(ds)) { currentValues = TextHelper.Join(";", SqlHelperClass.GetStringValues(ds.Tables[0], "CategoryID")); } this.uniSelector.WhereCondition = GetWhereCondition(currentValues); if (!RequestHelper.IsPostBack()) { this.uniSelector.Value = currentValues; } } this.uniSelector.IconPath = GetObjectIconUrl("ecommerce.optioncategory", "object.png"); }
/// <summary> /// Adds product to the shopping cart. /// </summary> private void AddProductToShoppingCart() { // Validate input data if (!IsValid() || (this.SKU == null)) { // Do not proces return; } if (this.RedirectToDetailsEnabled) { if (!this.ShowProductOptions && !this.ShowDonationProperties) { // Does product have some enabled product option categories? bool hasOptions = !DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true)); // Is product a customizable donation? bool isCustomizableDonation = ((this.SKU != null) && (this.SKU.SKUProductType == SKUProductTypeEnum.Donation) && (!((this.SKU.SKUPrice == this.SKU.SKUMinPrice) && (this.SKU.SKUPrice == this.SKU.SKUMaxPrice)) || this.SKU.SKUPrivateDonation)); if (hasOptions || isCustomizableDonation) { // Redirect to product details URLHelper.Redirect("~/CMSPages/GetProduct.aspx?productid=" + this.SKUID); } } } // Get cart item parameters ShoppingCartItemParameters cartItemParams = this.GetShoppingCartItemParameters(); // Check if it is possible to add this item to shopping cart if (!ShoppingCartInfoProvider.CheckNewShoppingCartItems(this.ShoppingCart, cartItemParams)) { // Show error message and cancel adding the product to shopping cart string error = String.Format(this.GetString("ecommerce.cartcontent.productdisabled"), this.SKU.SKUName); ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartAddItemErrorAlert", ScriptHelper.GetAlertScript(error)); return; } // If donation properties are used and donation properties form is not valid if (this.donationProperties.Visible && !String.IsNullOrEmpty(this.donationProperties.Validate())) { return; } // Fire on add to shopping cart event CancelEventArgs eventArgs = new CancelEventArgs(); if (this.OnAddToShoppingCart != null) { this.OnAddToShoppingCart(this, eventArgs); } // If adding to shopping cart was cancelled if (eventArgs.Cancel) { return; } // Get cart item parameters in case something changed cartItemParams = this.GetShoppingCartItemParameters(); // Log activity LogProductAddedToSCActivity(this.SKUID, this.SKU.SKUName, this.Quantity); if (this.ShoppingCart != null) { bool updateCart = false; // Assign current shopping cart to current user CurrentUserInfo ui = CMSContext.CurrentUser; if (!ui.IsPublic()) { this.ShoppingCart.UserInfoObj = ui; updateCart = true; } // Shopping cart is not saved yet if (this.ShoppingCart.ShoppingCartID == 0) { updateCart = true; } // Update shopping cart when required if (updateCart) { ShoppingCartInfoProvider.SetShoppingCartInfo(this.ShoppingCart); } // Add item to shopping cart ShoppingCartItemInfo addedItem = this.ShoppingCart.SetShoppingCartItem(cartItemParams); if (addedItem != null) { // Update shopping cart item in database ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(addedItem); // Update product options in database foreach (ShoppingCartItemInfo option in addedItem.ProductOptions) { ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(option); } // Update bundle items in database foreach (ShoppingCartItemInfo bundleItem in addedItem.BundleItems) { ShoppingCartItemInfoProvider.SetShoppingCartItemInfo(bundleItem); } // Track 'Add to shopping cart' conversion ECommerceHelper.TrackAddToShoppingCartConversion(addedItem); // If user has to be redirected to shopping cart if (this.RedirectToShoppingCart) { // Set shopping cart referrer SessionHelper.SetValue("ShoppingCartUrlReferrer", URLHelper.CurrentURL); // Ensure shopping cart update SessionHelper.SetValue("checkinventory", true); // Redirect to shopping cart URLHelper.Redirect(this.ShoppingCartUrl); } else { // Localize SKU name string skuName = (addedItem.SKUObj != null) ? ResHelper.LocalizeString(addedItem.SKUObj.SKUName) : ""; // Check inventory string checkInventoryMessage = ShoppingCartInfoProvider.CheckShoppingCart(this.ShoppingCart).Replace(";", "\n"); // Get prodcut added message string message = String.Format(this.GetString("com.productadded"), skuName); // Add inventory check message if (!String.IsNullOrEmpty(checkInventoryMessage)) { message += "\n\n" + checkInventoryMessage; } // Count and show total price with options CalculateTotalPrice(); // Register the call of JS handler informing about added product ScriptHelper.RegisterStartupScript(this.Page, typeof(string), "ShoppingCartItemAddedHandler", "if (typeof ShoppingCartItemAddedHandler == 'function') { ShoppingCartItemAddedHandler(" + ScriptHelper.GetString(message) + "); }", true); } } } }
/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { DataSet dsCategories = null; if (this.IsLiveSite) { // Get cache minutes int cacheMinutes = SettingsKeyProvider.GetIntValue(CMSContext.CurrentSiteName + ".CMSCacheMinutes"); // Try to get data from cache using (CachedSection <DataSet> cs = new CachedSection <DataSet>(ref dsCategories, cacheMinutes, true, null, "skuproductoptions", this.SKUID)) { if (cs.LoadData) { // Get the data dsCategories = OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true); // Save to the cache if (cs.Cached) { cs.CacheDependency = CacheHelper.GetCacheDependency("ecommerce.sku|byid|" + this.SKUID); cs.Data = dsCategories; } } } } else { // Get the data dsCategories = OptionCategoryInfoProvider.GetSKUOptionCategories(this.SKUID, true); } // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { this.mProductOptions = new Hashtable(); foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); selector.ID = "opt" + ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.LocalShoppingCartObj = this.ShoppingCart; selector.ShowPriceIncludingTax = this.ShowPriceIncludingTax; // Set option category data to the selector selector.OptionCategory = new OptionCategoryInfo(dr); // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { this.mProductOptions[entry.Key] = entry.Value; } if (this.ShowTotalPrice) { ListControl lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; lc.SelectedIndexChanged += new EventHandler(Selector_SelectedIndexChanged); } } // Add control to the collection this.pnlSelectors.Controls.Add(selector); } catch { } } } }
/// <summary> /// On BtnAdd click event. /// </summary> protected void BtnAdd_Click(object sender, EventArgs e) { // Check 'EcommerceModify' permission if (!ECommerceContext.IsUserAuthorizedForPermission("ModifyOrders")) { RedirectToAccessDenied("CMS.Ecommerce", "EcommerceModify OR ModifyOrders"); } Label lblSkuId; TextBox txtUnits; int units = 0; int skuId = 0; string allUnits = null; string allSkuId = null; for (int i = 0; i < GridViewProducts.Rows.Count; i++) { lblSkuId = (Label)GridViewProducts.Rows[i].Cells[5].Controls[0]; skuId = ValidationHelper.GetInteger(lblSkuId.Text, 0); if (skuId > 0) { txtUnits = (TextBox)GridViewProducts.Rows[i].Cells[3].Controls[1]; txtUnits.ID = "txtTaxValue" + skuId.ToString(); units = ValidationHelper.GetInteger(txtUnits.Text, 0); if (units > 0) { // If product has some product options // -> abort inserting products to the shopping cart if (!DataHelper.DataSourceIsEmpty(OptionCategoryInfoProvider.GetSKUOptionCategories(skuId, true))) { string skuName = ((LinkButton)GridViewProducts.Rows[i].Cells[0].Controls[1]).Text; lblError.Visible = true; lblError.Text = string.Format(GetString("Order_Edit_AddItems.ProductOptionsRequired"), skuName); return; } // Get product SKUInfo skui = SKUInfoProvider.GetSKUInfo(skuId); // If selected product is a donation if ((skui != null) && (skui.SKUProductType == SKUProductTypeEnum.Donation)) { // If donation is customizable if (skui.SKUPrivateDonation || !((skui.SKUMinPrice == skui.SKUPrice) && (skui.SKUMaxPrice == skui.SKUPrice))) { string skuName = ((LinkButton)this.GridViewProducts.Rows[i].Cells[0].Controls[1]).Text; this.lblError.Text = string.Format(this.GetString("order_edit_additems.donationpropertiesrequired"), skuName); this.lblError.Visible = true; return; } } // Create strings with SKU IDs and units separated by ';' allSkuId += skuId.ToString() + ";"; allUnits += units.ToString() + ";"; } } } // Close this modal window and refresh parent values in window CloseWindow(allSkuId, allUnits); }