Update BasketItem Shipping
Posted: Wed Aug 25, 2010 8:17 am
I am trying to update the Price of a BasketItem of type OrderItemType.Shipping. In other words, when looping through the BasketItems of the current Basket, when the OrderItemType is Shipping, I need to update the Price. When I try to do this, the Price is updated, but it doesn't seem to "stick" when I display the same BasketItem on another page. For instance, in the PaymentPage UserControl, in the ShipmentItemsGrid_RowDataBound Event, I can find the BasketItem I am looking for. I update the Price and this change is reflected on the screen. Now, when I go to the ShipMethodPage UserControl, the Price of said BasketItem is reverted back to what it was before I updated it. It looks to me that the BasketItemId is changing from page to page. Furthermore, the updated Price is not reflected in the BasketTotalSummary UserControl either.
Basically, what I need to do is update the Price of the BasketItem that corresponds to Shipping and have the value "stick" from screen to screen. Aslo, why does the BasketItemId change from screen to screen - it's like the BasketItems are always being deleted and re-added as you move from screen to screen - is this true?
My custom code in PaymentPage.ascx.cs. This will actually update the Price and display the updated Price on the screen.
My custom code in ShipMethod.ascx.cs. The BasketItem Price is back to what it was prior to updating.
Thanks for the help!
Basically, what I need to do is update the Price of the BasketItem that corresponds to Shipping and have the value "stick" from screen to screen. Aslo, why does the BasketItemId change from screen to screen - it's like the BasketItems are always being deleted and re-added as you move from screen to screen - is this true?
My custom code in PaymentPage.ascx.cs. This will actually update the Price and display the updated Price on the screen.
Code: Select all
protected void ShipmentItemsGrid_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
BasketItem currentItem = (BasketItem)e.Row.DataItem;
// Are we reading the shipping Line Item. If so, then adjust the Price.
if (currentItem.OrderItemType == OrderItemType.Shipping) {
Label priceLabel = (Label)e.Row.FindControl("Price");
Basket basket = Token.Instance.User.Basket;
BasketItem basketItem = currentItem;
basket.DeleteItem(currentItem.BasketItemId);
basketItem.Price = CalculateShippingCost(currentItem.Price);
basket.Items.Add(basketItem);
basket.Save();
basket.Recalculate();
priceLabel.Text = basketItem.Price.ToString("ulc");
}
}
} // End ShipmentItemsGrid_RowDataBound Event.
My custom code in ShipMethod.ascx.cs. The BasketItem Price is back to what it was prior to updating.
Code: Select all
protected void ShipmentItemsGrid_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
BasketItem currentItem = (BasketItem)e.Row.DataItem;
// Are we reading the shipping Line Item. If so, then adjust the Price.
if (currentItem.OrderItemType == OrderItemType.Shipping) {
Label priceLabel = (Label)e.Row.FindControl("Price");
Basket basket = Token.Instance.User.Basket;
BasketItem basketItem = basket.Items.Find(delegate(BasketItem i) { return i.BasketItemId == currentItem.BasketItemId; });
priceLabel.Text = basketItem.Price.ToString("ulc");
}
}
} // End ShipmentItemsGrid_RowDataBound Event.