Hi, Hola,
Here is the complete codebehing of my Minicart
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Commerce.Common;
public partial class Modules_MiniCart : System.Web.UI.UserControl
{
protected Order currentOrder;
protected void Page_Load(object sender, EventArgs e)
{
//currentOrder = OrderController.GetCurrentOrder();
OrderItemCollection orderItemCollection = OrderController.GetCartItems();
//********FIX zero Caddy
///Cart Empty Bug - Call this to check if cart is empty
CheckItems();
///*********
foreach (OrderItem currentItem in orderItemCollection)
{
if ((currentItem.ImageFile == null) || (currentItem.ImageFile.Length == 0))
{
currentItem.ImageFile = "images/ProductImages/no_image_available_small.gif";
}
}
rptMiniBasket.DataSource = orderItemCollection;
rptMiniBasket.DataBind();
decimal dTotal = 0;
foreach (OrderItem item in orderItemCollection)
{
dTotal += item.LineTotal;
}
lblSubtotal.Text = dTotal.ToString("n");
}
///********************************FIX ZERO CADDY
///Cart Empty Bug - Add orderItemCollection variable out of metods
protected OrderItemCollection orderItemCollection;
///Cart Empty Bug - Method called after get currentorder
private void CheckItems()
{
///Cart Empty Bug - Check if cart is empty
//if (orderItemCollection.Count == 0)
//{
///Cart Empty Bug - set current order
currentOrder = OrderController.GetCurrentOrder();
///Cart Empty Bug - set orderitemcollection
orderItemCollection = OrderController.GetCartItems();
///Cart Empty Bug - this variable is used control loop. just 3 times enough
int i = 0;
while (orderItemCollection.Count == 0 && i < 3)
{
///Cart Empty Bug - While item count is 0 we delete currentorder and call GetNewOrder() metod
currentOrder.DeletePermanent();
GetNewOrder();
i += 1;
}
//}
}
protected void GetNewOrder()
{
///Cart Empty Bug - Get new order for authenticated user
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
currentOrder = OrderController.GetCurrentOrder(HttpContext.Current.User.Identity.Name);
}
else
{
currentOrder = OrderController.GetCurrentOrder();
}
///Cart Empty Bug - Get new Cart
orderItemCollection = OrderController.GetCartItems();
}
///***************************************
}
Buena Suerte, Lucky