private List <int> RepackageBasketItem(BasketItem originalBasketItem, List <int> parentItemIds, ShippableItem shippableItem, int quantityMultiplier, Product kitMasterProduct) { List <int> newBasketItemIds = new List <int>(); int i = 0; foreach (int addressId in shippableItem.Destinations.Keys) { int warehouseId; if (kitMasterProduct != null && !kitMasterProduct.Kit.ItemizeDisplay) { warehouseId = kitMasterProduct.Warehouse.Id; } else { warehouseId = originalBasketItem.Product.Warehouse.Id; } BasketShipment shipment = GetShipment(warehouseId, addressId, true); if (i == 0) { //ADJUST THE FIRST ITEM originalBasketItem.Shipment = shipment; originalBasketItem.Quantity = (short)(shippableItem.Destinations[addressId] * quantityMultiplier); if (parentItemIds != null) { originalBasketItem.ParentItemId = GetParentItemId(parentItemIds, addressId, originalBasketItem.ParentItemId); } originalBasketItem.Save(); newBasketItemIds.Add(originalBasketItem.Id); } else { //CREATE ADDITIONAL ITEMS TO SPLIT DESTINATIONS BasketItem splitBasketItem = originalBasketItem.Copy(); splitBasketItem.Basket = _Basket; splitBasketItem.Quantity = (short)(shippableItem.Destinations[addressId] * quantityMultiplier); splitBasketItem.Shipment = shipment; if (parentItemIds != null) { splitBasketItem.ParentItemId = GetParentItemId(parentItemIds, addressId, splitBasketItem.ParentItemId); } _Basket.Items.Add(splitBasketItem); splitBasketItem.Save(); if (splitBasketItem.ParentItemId == 0) { splitBasketItem.ParentItemId = splitBasketItem.Id; splitBasketItem.Save(); } newBasketItemIds.Add(splitBasketItem.Id); } i++; } return(newBasketItemIds); }
protected void ContinueButton_Click(object sender, EventArgs e) { BasketItem basketItem = BasketItemDataSource.Load(AlwaysConvert.ToInt(GiftOptionsBasketItemId.Value)); // LOOP EACH ITEM ROW TO DETERMINE GIFT OPTIONS List <BasketItemGiftOption> giftOptions = new List <BasketItemGiftOption>(); foreach (GridViewRow row in GiftItemsGrid.Rows) { GiftWrapChoices wrapOptions = (GiftWrapChoices)row.FindControl("GiftWrapChoices"); wrapOptions.BasketItemId = basketItem.Id; int wrapStyleId = wrapOptions.WrapStyleId; string giftMessage = wrapOptions.GiftMessage; BasketItemGiftOption optionItem = new BasketItemGiftOption(basketItem, wrapStyleId, giftMessage); int existingIndex = giftOptions.IndexOf(optionItem); if (existingIndex > -1) { giftOptions[existingIndex].Quantity++; } else { giftOptions.Add(optionItem); } } // LOOP THROUGH GIFT OPTIONS AND UPDATE BASKET ITEMS Basket basket = AbleContext.Current.User.Basket; for (int i = 0; i < giftOptions.Count; i++) { BasketItemGiftOption giftOptionItem = giftOptions[i]; if (i == 0) { // FOR FIRST GIFT OPTION, UPDATE THE ORIGINAL BASKET ITEM basketItem.Quantity = giftOptionItem.Quantity; basketItem.WrapStyleId = giftOptionItem.WrapStyleId; basketItem.GiftMessage = giftOptionItem.GiftMessage; } else { // FOR ADDTIONAL GIFT OPTIONS, CREATE COPIES OF THE ORIGINAL BASKET ITEM BasketItem newItem = basketItem.Copy(); newItem.Quantity = giftOptionItem.Quantity; newItem.GiftMessage = giftOptionItem.GiftMessage; newItem.WrapStyleId = giftOptionItem.WrapStyleId; basket.Items.Add(newItem); } } // SAVE, COMBINE basket.Save(); IBasketService basketService = AbleContext.Resolve <IBasketService>(); basketService.Combine(basket); CartSummary.DataSource = GetBasketItems(); CartSummary.DataBind(); // NOW HIDE THE POPUP phGiftOptions.Visible = false; GiftOptionsPopup.Hide(); }