protected void MoveKitProduct(KitProduct kitProduct, int direction) { //MAKE SURE ALL KIT PRODUCTS ARE IN CORRECT ORDER short orderBy = -1; int index = -1; KitComponent kitComponent = kitProduct.KitComponent; foreach (KitProduct kp in kitComponent.KitProducts) { orderBy += 1; kp.OrderBy = orderBy; if (kp.Id.Equals(kitProduct.Id)) { index = orderBy; } } //LOCATE THE DESIRED ITEM if (index > -1) { KitProduct temp = null; if (direction < 0 && index > 0) { //MOVE UP temp = kitComponent.KitProducts[index]; temp.OrderBy -= 1; kitComponent.KitProducts[index] = kitComponent.KitProducts[index - 1]; kitComponent.KitProducts[index].OrderBy += 1; kitComponent.KitProducts[index - 1] = temp; kitComponent.KitProducts.Save(); } else if (direction > 0 && index < kitComponent.KitProducts.Count - 1) { //MOVEDOWN temp = kitComponent.KitProducts[index]; temp.OrderBy += 1; kitComponent.KitProducts[index] = kitComponent.KitProducts[index + 1]; kitComponent.KitProducts[index].OrderBy -= 1; kitComponent.KitProducts[index + 1] = temp; kitComponent.KitProducts.Save(); } } }
protected void Page_Init(object sender, EventArgs e) { //INITIALIZE VARIABLES _CategoryId = AbleCommerce.Code.PageHelper.GetCategoryId(); _Category = CategoryDataSource.Load(_CategoryId); _ProductId = AlwaysConvert.ToInt(Request.QueryString["ProductId"]); _Product = ProductDataSource.Load(_ProductId); if (_Product == null) { Response.Redirect(AbleCommerce.Code.NavigationHelper.GetAdminUrl("Catalog/Browse.aspx")); } _KitProductId = AlwaysConvert.ToInt(Request.QueryString["KitProductId"]); _KitProduct = KitProductDataSource.Load(_KitProductId); if (_KitProduct == null) { Response.Redirect("EditKit.aspx?CategoryId=" + _CategoryId.ToString() + "&ProductId=" + _ProductId.ToString()); } _KitComponentId = _KitProduct.KitComponentId; _KitComponent = _KitProduct.KitComponent; //INITIALIZE PAGE ELEMENTS Caption.Text = string.Format(Caption.Text, _KitComponent.Name); KitName.Text = _Product.Name; KitComponentName.Text = _KitComponent.Name; SelectedProductName.Text = _KitProduct.Product.Name; DisplayName.Text = _KitProduct.Name; KitQuantity.Text = _KitProduct.Quantity.ToString(); ProductPrice.Text = _KitProduct.Product.Price.LSCurrencyFormat("lc"); PriceMode.SelectedIndex = (int)_KitProduct.PriceMode; PriceMode_SelectedIndexChanged(sender, e); Price.Text = string.Format("{0:F2}", _KitProduct.Price); ProductWeight.Text = string.Format("{0:F2}", _KitProduct.Product.Weight); WeightMode.SelectedIndex = (int)_KitProduct.WeightMode; WeightMode_SelectedIndexChanged(sender, e); Weight.Text = string.Format("{0:F2}", _KitProduct.Weight); phOptions.Controls.Clear(); selectedOptions = AbleCommerce.Code.ProductHelper.BuildProductOptions(_KitProduct, phOptions); IsSelected.Checked = _KitProduct.IsSelected; WeightUnit.Text = AbleContext.Current.Store.WeightUnit.ToString(); }
/// <summary> /// Gets a list of KitProduct objects associated with this BasketItem /// </summary> /// <param name="includeHidden">If true, items in hidden components are included. If false, only items in visible component are included.</param> /// <returns>A list of KitProduct objects</returns> public List <KitProduct> GetKitProducts(bool includeHidden) { // BUILD LIST OF KIT PRODUCTS List <KitProduct> kitProductList = new List <KitProduct>(); int[] kitProductIds = AlwaysConvert.ToIntArray(this.KitList); if (kitProductIds != null && kitProductIds.Length > 0) { for (int i = 0; i < kitProductIds.Length; i++) { KitProduct kp = KitProductDataSource.Load(kitProductIds[i]); if (kp != null) { bool addToList = (includeHidden || (kp.KitComponent.InputType != KitInputType.IncludedHidden)); if (addToList) { kitProductList.Add(kp); } } } } return(kitProductList); }
/// <summary> /// Recalculates all items in the basket, for example price and kit member products /// </summary> internal void Recalculate() { // BUILD A LIST OF ANY CHILD (GENERATED) PRODUCTS List <int> childItemIds = new List <int>(); List <BasketItem> childProducts = new List <BasketItem>(); foreach (BasketItem item in this) { if (item.OrderItemType == OrderItemType.Product && item.IsChildItem) { childItemIds.Add(item.BasketItemId); childProducts.Add(item); } } // MOVE THROUGH THE COLLECTION AND REMOVE ANY ITEMS ASSOCIATED WITH A CHILD ITEM for (int i = this.Count - 1; i >= 0; i--) { BasketItem item = this[i]; List <int> childPath = item.GetPath(); if (IsChildItemInPath(childItemIds, childPath)) { if (item.OrderItemType == OrderItemType.Product) { this.RemoveAt(i); } else { this.DeleteAt(i); } } } // LOOP EACH REMAINING ITEM AND RECALCULATE int currentCount = this.Count; for (int i = 0; i < currentCount; i++) { BasketItem basketItem = this[i]; Basket basket = basketItem.Basket; int userId = (basket == null ? Token.Instance.UserId : basket.UserId); // WE ONLY NEED TO CHECK PRODUCTS, NON-PRODUCT ITEMS HAVE NO RECALCULATION TASKS if (basketItem.OrderItemType == OrderItemType.Product) { // IF WE HAVE A KIT, WE MUST REFRESH ANY CONFIGURED KIT OPTIONS bool isKit = (basketItem.Product.KitStatus == KitStatus.Master); if (isKit) { basketItem.KitList = basketItem.Product.Kit.RefreshKitProducts(basketItem.KitList); } // RECALCULATE THE STARTING SKU/PRICE/WEIGHT FOR THIS ITEM ProductCalculator pcalc = ProductCalculator.LoadForProduct(basketItem.ProductId, basketItem.Quantity, basketItem.OptionList, basketItem.KitList, userId); basketItem.Sku = pcalc.Sku; basketItem.Weight = pcalc.Weight; if (isKit || !basketItem.Product.UseVariablePrice) { // KITS AND NONVARIABLE PRICED PRODUCTS MUST HAVE PRICE RECALCULATED basketItem.Price = pcalc.Price; } basketItem.Save(); // REGENERATE THE KIT ITEMS FOR THIS ITEM if (basket != null && isKit) { // OBTAIN THE KIT PRODUCTS THAT ARE SELECTED RATHER THAN INCLUDED int[] kitProductIds = AlwaysConvert.ToIntArray(basketItem.KitList); if (kitProductIds != null && kitProductIds.Length > 0) { //keep track of the price/weight of the master line item //decrement these values for each line item registered LSDecimal masterPrice = basketItem.Price; LSDecimal masterWeight = basketItem.Weight; foreach (int kitProductId in kitProductIds) { KitProduct kitProduct = KitProductDataSource.Load(kitProductId); if (kitProduct != null && kitProduct.KitComponent.InputType != KitInputType.IncludedHidden) { // WE WANT TO GENERATE BASKET RECORDS FOR ALL ITEMS *EXCEPT* INCLUDED HIDDEN ITEMS // INCLUDED HIDDEN ITEMS ARE TREATED AS PART OF THE MAIN PRODUCT AND ARE NOT GENERATED // UNTIL THE ORDER IS FINALIZED Product product = kitProduct.Product; BasketItem searchItem = new BasketItem(); searchItem.BasketId = basket.BasketId; searchItem.OrderItemType = OrderItemType.Product; searchItem.ParentItemId = basketItem.BasketItemId; searchItem.ProductId = product.ProductId; searchItem.OptionList = kitProduct.OptionList; searchItem.BasketShipmentId = basketItem.BasketShipmentId; // LOOK FOR ITEM BasketItem childItem = FindChildProduct(childProducts, searchItem); // UPDATE CALCULATED PROPERTIES childItem.Name = kitProduct.DisplayName; childItem.Quantity = (short)(kitProduct.Quantity * basketItem.Quantity); childItem.TaxCodeId = product.TaxCodeId; childItem.Shippable = product.Shippable; childItem.Price = kitProduct.CalculatedPrice / kitProduct.Quantity;; childItem.Weight = kitProduct.CalculatedWeight / kitProduct.Quantity; // CALCULATE SKU ProductCalculator childCalc = ProductCalculator.LoadForProduct(childItem.ProductId, childItem.Quantity, childItem.OptionList, childItem.KitList, basket.UserId); childItem.Sku = childCalc.Sku; basket.Items.Add(childItem); childItem.Save(); masterPrice -= kitProduct.CalculatedPrice; masterWeight -= kitProduct.CalculatedWeight; } } // UPDATE MASTER PRICE, FACTORING IN CHILD ITEMS basketItem.Price = masterPrice; basketItem.Weight = masterWeight; basketItem.Save(); } } } } // DELETE ANY CHILD PRODUCTS THAT WERE NOT PRESERVED foreach (BasketItem bi in childProducts) { bi.Delete(); } }
public static List <AbleCommerce.Code.ProductAssetWrapper> GetAssets(Page page, Product product, string optionList, string kitList, string returnUrl) { // BUILD LIST OF ASSETS List <string> assetTracker = new List <string>(); string encodedReturnUrl; if (!string.IsNullOrEmpty(returnUrl)) { encodedReturnUrl = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(returnUrl)); } else { encodedReturnUrl = string.Empty; } List <AbleCommerce.Code.ProductAssetWrapper> assetList = new List <AbleCommerce.Code.ProductAssetWrapper>(); string agreeUrl = page.ResolveUrl("~/ViewLicenseAgreement.aspx") + "?id={0}&ReturnUrl=" + encodedReturnUrl; string agreePopup = agreeUrl + "\" onclick=\"" + AbleCommerce.Code.PageHelper.GetPopUpScript(agreeUrl, "license", 640, 480, "resizable=1,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no") + ";return false"; string readmeUrl = page.ResolveUrl("~/ViewReadme.aspx") + "?ReadmeId={0}&ReturnUrl=" + encodedReturnUrl; string readmePopup = readmeUrl + "\" onclick=\"" + AbleCommerce.Code.PageHelper.GetPopUpScript(readmeUrl, "readme", 640, 480, "resizable=1,scrollbars=yes,toolbar=no,menubar=no,location=no,directories=no") + ";return false"; List <ProductAndOptionList> products = new List <ProductAndOptionList>(); products.Add(new ProductAndOptionList(product, optionList)); // IF IT IS A KIT LOOK FOR CHILD PRODUCTS AS WELL if (!String.IsNullOrEmpty(kitList)) { if (product.IsKit) { bool kitIsBundled = !product.Kit.ItemizeDisplay; int[] kitProductIds = AlwaysConvert.ToIntArray(kitList); if (kitProductIds != null && kitProductIds.Length > 0) { foreach (int kitProductId in kitProductIds) { KitProduct kitProduct = KitProductDataSource.Load(kitProductId); if ((kitProduct != null) && (kitProduct.KitComponent.InputType == KitInputType.IncludedHidden || kitIsBundled)) { products.Add(new ProductAndOptionList(kitProduct.Product, kitProduct.OptionList)); } } } } } foreach (ProductAndOptionList pol in products) { foreach (ProductDigitalGood pdg in pol.Product.DigitalGoods) { if ((string.IsNullOrEmpty(pdg.OptionList)) || (pol.OptionList == pdg.OptionList)) { DigitalGood digitalGood = pdg.DigitalGood; Readme readme = digitalGood.Readme; if (readme != null && assetTracker.IndexOf("R" + readme.Id.ToString()) < 0) { assetList.Add(new AbleCommerce.Code.ProductAssetWrapper(string.Format(readmePopup, readme.Id), readme.DisplayName)); assetTracker.Add("R" + readme.Id.ToString()); } LicenseAgreement agreement = digitalGood.LicenseAgreement; if (agreement != null && assetTracker.IndexOf("L" + agreement.Id.ToString()) < 0) { assetList.Add(new AbleCommerce.Code.ProductAssetWrapper(string.Format(agreePopup, agreement.Id), agreement.DisplayName)); assetTracker.Add("L" + agreement.Id.ToString()); } } } } return(assetList); }
public static Dictionary <int, int> BuildProductOptions(KitProduct kitProduct, PlaceHolder phOptions) { if (kitProduct == null) { return(null); } Product product = kitProduct.Product; Dictionary <int, int> selectedChoices = new Dictionary <int, int>(); if ((product.ProductOptions.Count > 0)) { Page page = phOptions.Page; HttpRequest request = HttpContext.Current.Request; for (int i = 0; i < product.ProductOptions.Count; i++) { Option option = product.ProductOptions[i].Option; // CREATE A LABEL FOR THE ATTRIBUTE phOptions.Controls.Add(new LiteralControl("<tr><th class=\"rowHeader\"" + (option.ShowThumbnails ? " valign=\"top\"" : string.Empty) + ">" + option.Name + ":</th>")); phOptions.Controls.Add(new LiteralControl("<td align=\"left\">")); // CREATE A DROPDOWN FOR THE OPTIONS DropDownList aspOptions = new DropDownList(); RequiredFieldValidator aspOptionsValidator = new RequiredFieldValidator(); aspOptions.ID = "option" + i; aspOptionsValidator.ID = "optionValidator" + i; aspOptionsValidator.ControlToValidate = aspOptions.ID; aspOptionsValidator.ValidationGroup = "AddToBasket"; aspOptionsValidator.Text = string.Empty; aspOptionsValidator.ErrorMessage = string.Empty; aspOptions.Items.Add(option.HeaderText); // GET THE COLLECTION OF CHOICES THAT ARE AVAILABLE FOR THE CURRENT SELECTIONS IList <OptionChoice> availableOptions; if (i < ProductVariant.MAXIMUM_ATTRIBUTES) { availableOptions = OptionChoiceDataSource.GetAvailableChoices(product.Id, option.Id, selectedChoices); } else { availableOptions = option.Choices; } // ADD AVAILABLE CHOICES TO THE LIST foreach (OptionChoice choice in availableOptions) { aspOptions.Items.Add(new ListItem(choice.Name, choice.Id.ToString())); } // ADD THE CONTROL TO THE PLACEHOLDER phOptions.Controls.Add(aspOptions); phOptions.Controls.Add(aspOptionsValidator); string selectedValue = request.Form[aspOptions.UniqueID]; if (!string.IsNullOrEmpty(selectedValue)) { ListItem selectedItem = aspOptions.Items.FindByValue(selectedValue); if (selectedItem != null) { int val = AlwaysConvert.ToInt(selectedValue); if (val != 0) { selectedChoices.Add(option.Id, val); selectedItem.Selected = true; } } } else { ProductVariant productVariant = kitProduct.ProductVariant; int optionChoiceId = 0; switch (i) { case 0: optionChoiceId = (productVariant.Option1 > 0) ? productVariant.Option1 : 0; break; case 1: optionChoiceId = (productVariant.Option2 > 0) ? productVariant.Option2 : 0; break; case 2: optionChoiceId = (productVariant.Option3 > 0) ? productVariant.Option3 : 0; break; case 3: optionChoiceId = (productVariant.Option4 > 0) ? productVariant.Option4 : 0; break; case 4: optionChoiceId = (productVariant.Option5 > 0) ? productVariant.Option5 : 0; break; case 5: optionChoiceId = (productVariant.Option6 > 0) ? productVariant.Option6 : 0; break; case 6: optionChoiceId = (productVariant.Option7 > 0) ? productVariant.Option7 : 0; break; case 7: optionChoiceId = (productVariant.Option8 > 0) ? productVariant.Option8 : 0; break; default: //FIND OPTION CHOICE ID TO HANDLE SELECTIONS FOR MORE THEN 8 OPTIONS if (!string.IsNullOrEmpty(productVariant.OptionList)) { string[] options = productVariant.OptionList.Split(','); if (options != null && options.Length > 8 && i > 7) { optionChoiceId = AlwaysConvert.ToInt(options[i]); } } break; } if (optionChoiceId > 0) { ListItem listItem = aspOptions.Items.FindByValue(optionChoiceId.ToString()); if (listItem != null) { listItem.Selected = true; } } } phOptions.Controls.Add(new LiteralControl("</td></tr>")); // KEEP LOOPING UNTIL WE REACH THE END OR WE COME TO AN OPTION THAT IS NOT SELECTED } } return(selectedChoices); }
protected string GetEditKitProductLink(object dataItem) { KitProduct kp = (KitProduct)dataItem; return(string.Format("EditKitProduct.aspx?CategoryId={0}&ProductId={1}&KitComponentId={2}&KitProductId={3}", _CategoryId, _ProductId, kp.KitComponentId, kp.Id)); }
/// <summary> /// Gets the order items that would result from the addition of the given product to an order. /// </summary> /// <param name="productId">The id of the product to add.</param> /// <param name="quantity">The quantity of the product to add.</param> /// <param name="optionList">List of option choice ids if this is a variant</param> /// <param name="kitList">List of kit products if it is a Kit</param> /// <returns>The order items that would result from the addition of the given product to an order</returns> public static List <OrderItem> CreateForProduct(int productId, short quantity, string optionList, string kitList) { List <OrderItem> orderItems = new List <OrderItem>(); Product product = ProductDataSource.Load(productId); if (product != null) { //CREATE THE BASE ORDER ITEM OrderItem baseItem = new OrderItem(); baseItem.Name = product.Name; baseItem.OrderItemType = OrderItemType.Product; baseItem.ProductId = productId; baseItem.TaxCodeId = product.TaxCodeId; baseItem.Quantity = quantity; baseItem.ShippableId = product.ShippableId; //CALCULATE THE PRICE OF THE PRODUCT ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, quantity, optionList, kitList); baseItem.Sku = pcalc.Sku; baseItem.Price = pcalc.Price; baseItem.Weight = pcalc.Weight; //CHECK PRODUCT VARIANT ProductVariant variant = ProductVariantDataSource.LoadForOptionList(productId, optionList); if (variant != null) { baseItem.OptionList = optionList; baseItem.VariantName = variant.VariantName; } //CHECK FOR DIGITAL GOODS foreach (ProductDigitalGood dg in product.DigitalGoods) { if (dg.DigitalGood != null && (String.IsNullOrEmpty(baseItem.OptionList) || baseItem.OptionList == dg.OptionList)) { OrderItemDigitalGood oidg = new OrderItemDigitalGood(); oidg.OrderItemId = baseItem.OrderItemId; oidg.DigitalGoodId = dg.DigitalGoodId; oidg.Name = dg.DigitalGood.Name; baseItem.DigitalGoods.Add(oidg); } } orderItems.Add(baseItem); //CHECK FOR KIT ITEMS int[] kitProductIds = AlwaysConvert.ToIntArray(kitList); if (kitProductIds != null && kitProductIds.Length > 0) { LSDecimal baseItemPrice = baseItem.Price; LSDecimal baseItemWeight = baseItem.Weight; foreach (int kitProductId in kitProductIds) { KitProduct kitProduct = KitProductDataSource.Load(kitProductId); if (kitProduct != null) { OrderItem kitItem = new OrderItem(); kitItem.Name = kitProduct.DisplayName; kitItem.OrderItemType = OrderItemType.Product; kitItem.ParentItemId = baseItem.OrderItemId; kitItem.ProductId = kitProduct.ProductId; kitItem.OptionList = kitProduct.OptionList; kitItem.Quantity = (short)(kitProduct.Quantity * baseItem.Quantity); kitItem.Sku = kitProduct.Product.Sku; kitItem.TaxCodeId = kitProduct.Product.TaxCodeId; kitItem.Price = kitProduct.CalculatedPrice / kitProduct.Quantity; kitItem.Weight = kitProduct.CalculatedWeight / kitProduct.Quantity; //CHECK FOR DIGITAL GOODS foreach (DigitalGood dg in kitItem.Product.DigitalGoods) { OrderItemDigitalGood oidg = new OrderItemDigitalGood(); oidg.OrderItemId = kitItem.OrderItemId; oidg.DigitalGoodId = dg.DigitalGoodId; kitItem.DigitalGoods.Add(oidg); } baseItemPrice -= kitProduct.CalculatedPrice; baseItemWeight -= kitProduct.CalculatedWeight; orderItems.Add(kitItem); } } baseItem.Price = baseItemPrice; baseItem.Weight = baseItemWeight; } } return(orderItems); }
public ActionResult CreateKit(ProductSelection KitBuild, Product products, Kit Kits, KitProduct KitProducts) { bool successful = false; var kitList = db.Kits.ToList(); var kitId = 0; if (kitList.FirstOrDefault().Id != null) { kitId = kitList.Max(r => r.Id) + 1; Kits.KitName = KitBuild.KitName; Kits.LastEditDateTime = DateTime.Now; Kits.LastEditUser = HDUtilities.UserInformation.GetCurrentUserName(); } else { kitId = 1; Kits.KitName = KitBuild.KitName; Kits.LastEditDateTime = DateTime.Now; Kits.LastEditUser = HDUtilities.UserInformation.GetCurrentUserName(); } db.Kits.Add(Kits); db.SaveChanges(); for (var x = 0; x < KitBuild.productList.Length; x++) { KitProducts.KitId = kitId; KitProducts.ProductId = Convert.ToInt32(KitBuild.productList[x]); KitProducts.Quantity = Convert.ToInt32(KitBuild.orderQty[x]); KitProducts.LastEditDateTime = DateTime.Now; KitProducts.LastEditUser = HDUtilities.UserInformation.GetCurrentUserName(); //decimal prodPrice = db.Products.Where(r => r.Id == KitProducts.ProductId).FirstOrDefault().SellPrice; //kitPrice += Convert.ToDecimal(KitBuild.orderQty[x]) * prodPrice; try { db.KitProducts.Add(KitProducts); db.SaveChanges(); successful = true; } catch (Exception ex) { throw ex; } } products.ProductName = KitBuild.KitName; products.SKU = "kit"; //products.SellPrice = kitPrice; products.Weight = 0; products.WeightUnit = "lbs"; products.PackageWeight = 0; products.PackageLength = 0; products.PackageHeight = 0; products.PackageUnits = "lbs"; products.CategoryId = 1; products.QtyPerPackage = 0; products.DefaultOrderSize = 0; products.VendorId = 1; products.OnOrder = 0; products.StockLevel = 20; products.ReorderThreshold = 0; products.IsKit = true; products.KitId = kitId; products.Active = true; products.LastOrderedDate = DateTime.Now; products.LastEditDateTime = DateTime.Now; products.LastEditUser = HDUtilities.UserInformation.GetCurrentUserName(); try { db.Products.Add(products); db.SaveChanges(); successful = true; } catch (Exception ex) { throw ex; } return(Json(new { Result = successful }, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Converts kit product assoications into order line items for a basket that is /// being finalized. /// </summary> /// <param name="basket">The basket checking out</param> /// <param name="order">The order being created</param> /// <param name="idLookup">A translation table to map basket ids to order ids</param> internal static void GenerateKitProducts(Basket basket, Order order, Dictionary <string, int> idLookup) { foreach (BasketItem basketItem in basket.Items) { if (basketItem.OrderItemType == OrderItemType.Product) { int[] kitProductIds = AlwaysConvert.ToIntArray(basketItem.KitList); if (kitProductIds != null && kitProductIds.Length > 0) { //keep track of the price/weight of the master line item //decrement these values for each line item registered LSDecimal masterPrice = basketItem.Price; LSDecimal masterWeight = basketItem.Weight; foreach (int kitProductId in kitProductIds) { // WE ONLY NEED TO GENERATE RECORDS FOR THE HIDDEN ITEMS // VISIBLE KIT MBMER PRODUCTS ARE GENERATED DURING THE BASKET RECALCULATION KitProduct kp = KitProductDataSource.Load(kitProductId); if (kp.KitComponent.InputType == KitInputType.IncludedHidden) { Product p = kp.Product; ProductVariant pv = kp.ProductVariant; OrderItem item = new OrderItem(); item.OrderId = order.OrderId; // SET THE PARENT ITEM ID FOR THIS ITEM if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { item.ParentItemId = idLookup["I" + basketItem.BasketItemId]; } item.OrderItemType = OrderItemType.Product; if (idLookup.ContainsKey("S" + basketItem.BasketShipmentId)) { item.OrderShipmentId = idLookup["S" + basketItem.BasketShipmentId]; } if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { item.ParentItemId = idLookup["I" + basketItem.BasketItemId]; } item.ProductId = kp.ProductId; item.Name = kp.DisplayName; item.OptionList = kp.OptionList; if (pv != null) { item.VariantName = pv.VariantName; item.Sku = pv.Sku; } else { item.Sku = p.Sku; } item.Quantity = (short)(kp.Quantity * basketItem.Quantity); item.TaxCodeId = p.TaxCodeId; //THE CALCULATED PRICE IS FOR ALL ITEMS (EXT PRICE) //TO GET A LINE ITEM PRICE WE MUST DIVIDE BY QUANTITY item.Price = kp.CalculatedPrice / kp.Quantity; item.Weight = kp.CalculatedWeight / kp.Quantity; item.CostOfGoods = p.CostOfGoods; item.WishlistItemId = basketItem.WishlistItemId; item.WrapStyleId = basketItem.WrapStyleId; item.IsHidden = (kp.KitComponent.InputType == KitInputType.IncludedHidden); //USE PARENT SHIPPABLE STATUS FOR HIDDEN KITTED PRODUCTS item.Shippable = basketItem.Shippable; item.Save(); order.Items.Add(item); masterPrice -= kp.CalculatedPrice; masterWeight -= kp.CalculatedWeight; } } //UPDATE THE PRICE OF THE KIT LINE ITEM (BASE PRICE OF PRODUCT LESS KIT PARTS) if (idLookup.ContainsKey("I" + basketItem.BasketItemId)) { int index = order.Items.IndexOf(idLookup["I" + basketItem.BasketItemId]); if (index > -1) { order.Items[index].Price = masterPrice; order.Items[index].Weight = masterWeight; order.Items[index].Save(); } } } } } }
protected void FinishButton_Click(object sender, EventArgs e) { foreach (RepeaterItem ri in SelectedProductRepeater.Items) { HiddenField pid = (HiddenField)ri.FindControl("PID"); int productId = AlwaysConvert.ToInt(pid.Value); Product product = ProductDataSource.Load(productId); if (product == null) { return; } if (!AllProductOptionsSelected(product, ri)) { return; } TextBox KitQuantity = (TextBox)ri.FindControl("KitQuantity"); short quantity = AlwaysConvert.ToInt16(KitQuantity.Text); if (quantity > 0) { ProductVariant productVariant = null; string optionList = string.Empty; if (product.ProductOptions.Count > 0) { Dictionary <int, int> selectedOptions = GetSelectedOptions(ri.ItemIndex); productVariant = ProductVariantDataSource.LoadForOptionList(productId, selectedOptions); optionList = ProductVariantDataSource.GetOptionList(productId, selectedOptions, true); } TextBox NameFormat = (TextBox)ri.FindControl("NameFormat"); DropDownList PriceMode = (DropDownList)ri.FindControl("PriceMode"); TextBox Price = (TextBox)ri.FindControl("Price"); DropDownList WeightMode = (DropDownList)ri.FindControl("WeightMode"); TextBox Weight = (TextBox)ri.FindControl("Weight"); CheckBox IsSelected = (CheckBox)ri.FindControl("IsSelected"); KitProduct kitProduct = new KitProduct(); kitProduct.ProductId = productId; kitProduct.KitComponent = _KitComponent; if (productVariant != null) { kitProduct.OptionList = productVariant.OptionList; } kitProduct.Name = NameFormat.Text; kitProduct.Quantity = quantity; ProductCalculator pcalc = ProductCalculator.LoadForProduct(productId, 1, optionList, string.Empty); kitProduct.PriceModeId = AlwaysConvert.ToByte(PriceMode.SelectedIndex); if (kitProduct.PriceMode == InheritanceMode.Inherit) { kitProduct.Price = pcalc.Price; } else { kitProduct.Price = AlwaysConvert.ToDecimal(Price.Text); } kitProduct.WeightModeId = AlwaysConvert.ToByte(WeightMode.SelectedIndex); if (kitProduct.WeightMode == InheritanceMode.Inherit) { kitProduct.Weight = pcalc.Weight; } else { kitProduct.Weight = AlwaysConvert.ToDecimal(Weight.Text); } kitProduct.IsSelected = IsSelected.Checked; kitProduct.Save(); } } Response.Redirect(string.Format("EditKit.aspx?CategoryId={0}&ProductId={1}", _CategoryId, _ProductId)); }
public static Basket GetAcBasket(AutoGen.ShoppingCart shoppingcart, bool clearShipNTax) { TraceContext trace = WebTrace.GetTraceContext(); string traceKey = "GoogleCheckout.AC.AcHelper"; trace.Write(traceKey, "Begin AcHelper.GetAcBasket"); int basketId = AcHelper.GetAcBasketId(shoppingcart); trace.Write(traceKey, "Look for basket ID " + basketId.ToString()); Basket basket = BasketDataSource.Load(basketId, false); if (basket == null) { trace.Write(traceKey, "Basket not found. Creating New Basket."); basket = new Basket(); } else { //basket found. check if content hash matches string contentHash = GetReportedBasketHash(shoppingcart); if (contentHash.Equals(GetAcBasketHash(basket))) { //hash matched. basket has not changed. if (clearShipNTax) { ClearShippingAndTaxes(basket); } return(basket); } } trace.Write(traceKey, "Clear existing Basket contents and populate with Google Input."); basket.Clear(); if (shoppingcart.items != null) { trace.Write(traceKey, "Looping " + shoppingcart.items.Length.ToString() + " items in Google cart"); } foreach (Item thisItem in shoppingcart.items) { trace.Write(traceKey, "itemName: " + thisItem.itemname); BasketItem basketItem = new BasketItem(); basketItem.Name = thisItem.itemname; basketItem.Quantity = (short)thisItem.quantity; basketItem.Price = thisItem.unitprice.Value; XmlNode[] privateNodes = thisItem.merchantprivateitemdata.Any; foreach (XmlNode privateNode in privateNodes) { trace.Write(traceKey, "privateNode.Name: " + privateNode.Name); switch (privateNode.Name) { case "productId": basketItem.ProductId = AlwaysConvert.ToInt(privateNode.InnerText); break; case "orderItemType": basketItem.OrderItemType = (OrderItemType)AlwaysConvert.ToEnum(typeof(OrderItemType), privateNode.InnerText, OrderItemType.Product, true); break; case "shippable": basketItem.Shippable = (Shippable)AlwaysConvert.ToEnum(typeof(Shippable), privateNode.InnerText, Shippable.Yes, true); break; case "taxCodeId": basketItem.TaxCodeId = AlwaysConvert.ToInt(privateNode.InnerText); break; case "weight": basketItem.Weight = AlwaysConvert.ToDecimal(privateNode.InnerText); break; case "wrapStyleId": basketItem.WrapStyleId = AlwaysConvert.ToInt(privateNode.InnerText); break; case "optionList": basketItem.OptionList = privateNode.InnerText; break; case "giftMessage": basketItem.GiftMessage = privateNode.InnerText; break; case "lineMessage": basketItem.LineMessage = privateNode.InnerText; break; case "lastModifiedDate": basketItem.LastModifiedDate = AlwaysConvert.ToDateTime(privateNode.InnerText, LocaleHelper.LocalNow); break; case "orderBy": basketItem.OrderBy = AlwaysConvert.ToInt16(privateNode.InnerText); break; case "parentItemId": basketItem.ParentItemId = AlwaysConvert.ToInt(privateNode.InnerText); break; case "sku": basketItem.Sku = privateNode.InnerText; break; case "wishlistItemId": basketItem.WishlistItemId = AlwaysConvert.ToInt(privateNode.InnerText); break; case "basketItemKitProducts": List <string> kitList = new List <string>(); foreach (XmlNode subNode in privateNode.ChildNodes) { if (subNode.Name.Equals("kitProductId")) { int kitProductId = AlwaysConvert.ToInt(subNode.InnerText); KitProduct kitProd = KitProductDataSource.Load(kitProductId); if (kitProd != null) { kitList.Add(kitProductId.ToString()); } } } if (kitList.Count > 0) { basketItem.KitList = string.Join(",", kitList.ToArray()); } break; case "inputs": foreach (XmlNode subNode in privateNode.ChildNodes) { if (subNode.Name.Equals("itemInput")) { int inputFieldId = 0; foreach (XmlAttribute attr in subNode.Attributes) { if (attr.Name.Equals("inputFieldId")) { inputFieldId = AlwaysConvert.ToInt(attr.InnerText); break; } } InputField inputField = InputFieldDataSource.Load(inputFieldId); if (inputField != null) { BasketItemInput bInput = new BasketItemInput(); bInput.InputFieldId = inputFieldId; bInput.InputValue = subNode.InnerText; basketItem.Inputs.Add(bInput); } } } break; case "couponCode": basketItem.Sku = privateNode.InnerText; break; } } basket.Items.Add(basketItem); } trace.Write(traceKey, "Saving basket"); basket.Save(); string key = "Basket_" + basket.BasketId.ToString(); ContextCache.SetObject(key, basket); trace.Write(traceKey, "Basket created, returning to caller (End GetAcBasket)"); return(basket); }