Code: Select all
Basket basket = new Basket();
basket.UserId = this.Order.UserId;
basket.Save();
int i = 0;
foreach (OrderShipment shipment in this.Order.Shipments)
{
GridView itemsGrid = OrderShipments.Items[i].FindControl("ShipmentItems") as GridView;
BasketShipment basketShipment = new BasketShipment();
basketShipment.BasketId = basket.BasketId;
basketShipment.SetAddress(shipment.Address);
basketShipment.WarehouseId = shipment.WarehouseId;
basket.Shipments.Add(basketShipment);
basketShipment.Save();
for (int j = 0; j < shipment.OrderItems.Cast<OrderItem>().Count(item => item.OrderItemType == OrderItemType.Product); j++)
{
TextBox quantityText = itemsGrid.Rows[j].Cells[0].FindControl("Quantity") as TextBox;
DropDownList productDropDown = itemsGrid.Rows[j].Cells[0].FindControl("Product") as DropDownList;
short quantity;
int productId;
string optionList;
if (short.TryParse(quantityText.Text, out quantity) &&
ProductOptionContainer.TryParse(productDropDown.SelectedValue, out productId, out optionList))
{
BasketItem basketItem = BasketItemDataSource.CreateForProduct(productId, quantity, optionList, string.Empty);
basketItem.BasketId = basket.BasketId;
basketItem.BasketShipmentId = basketShipment.BasketShipmentId;
basketItem.Save();
basketShipment.Items.Add(basketItem);
}
}
basketShipment.ApplyShipMethod(shipment.ShipMethodId);
i++;
}
basket.Recalculate();
basket.Save();
// Do checkout and delete old order here...
Code: Select all
basketShipment.Items.Add(basketItem);
The basketitems are inserted in to the database and appear fine there, but refuse to show up in the basketshipment's basketitem collection. This also leads to an invalid shipMethod error on the line:
Code: Select all
basketShipment.ApplyShipMethod(shipment.ShipMethodId);
Does anybody know why this is happening?