/// <summary> /// Delete this basket shipment object from database /// </summary> /// <returns><b>true</b> if delete successful, <b>false</b> otherwise</returns> public virtual bool Delete() { //DELETE ANY BASKET ITEMS IN THIS SHIPMENT BasketItemCollection itemCollection = this.Basket.Items; for (int i = (itemCollection.Count - 1); i >= 0; i--) { BasketItem item = itemCollection[i]; if (item.BasketShipmentId.Equals(this.BasketShipmentId)) { itemCollection.DeleteAt(i); } } return this.BaseDelete(); }
/// <summary> /// Apply a ship method to this basket shipment /// </summary> /// <param name="shipMethod">The ship method to apply</param> public void ApplyShipMethod(ShipMethod shipMethod) { if (shipMethod == null) throw new ArgumentNullException("shipMethod"); //WIPE OUT ANY SHIPPING CHARGES CURRENTLY IN THIS SHIPMENT this.ShipMethodId = shipMethod.ShipMethodId; this._ShipMethod = shipMethod; BasketItem item; BasketItemCollection basketItems = this.Basket.Items; for (int i = basketItems.Count - 1; i >= 0; i--) { item = basketItems[i]; if (item.BasketShipmentId.Equals(this.BasketShipmentId) && ((item.OrderItemType == OrderItemType.Shipping || item.OrderItemType == OrderItemType.Handling))) { basketItems.DeleteAt(i); } } ShipRateQuote quote = shipMethod.GetShipRateQuote(this); if (quote == null) throw new ArgumentException("The specified shipping method is not valid for these items.", "shipMethod"); item = new BasketItem(); item.BasketId = this.BasketId; item.BasketShipmentId = this.BasketShipmentId; item.Name = quote.ShipMethod.Name; item.OrderItemType = OrderItemType.Shipping; item.Price = quote.Rate; item.Weight = 0; item.Quantity = 1; basketItems.Add(item); if (quote.Surcharge > 0) { item = new BasketItem(); item.BasketId = this.BasketId; item.BasketShipmentId = this.BasketShipmentId; item.Name = quote.ShipMethod.Name; item.OrderItemType = OrderItemType.Handling; item.Price = quote.Surcharge; item.Weight = 0; item.Quantity = 1; basketItems.Add(item); } basketItems.Save(); this.Save(); }