I am using the prototype js library! So I brought this information. If you don't know proto, you can go to the garden to find relevant information!
First, add the shopping cart stuff to store the shopping cart. I used session to store the Arraylist in it. Because you don't know how many things the customer wants to buy. Therefore, you cannot use an array.
Considerations:
1. If purchasing a car is added
2. If repeated items are accumulated together (for example, if I buy a bottle of shampoo, I need to accumulate another bottle to 2)
3. How to interact with the database in real time to determine whether the inventory is sufficient. (Using ajax)
In fact, all operations use ajax!
We use Session ["orders"] to store the shopping cart.
How to get the shopping cart:/** /// <summary>
/// Get the product in the shopping cart
/// Author: jake
/// Bt: 080313
/// </Summary>
/// <Param name = "pName"> product name </param>
/// <Param name = "pId"> product ID </param>
/// <Param name = "mPrice"> market price </param>
/// <Param name = "sPrice"> event manager price </param>
/// <Param name = "pNum"> product quantity </param>
/// <Returns> shopping cart array </returns>
/// Set to [product ID, product name, market price, website price, quantity]
/// Session form: set form
Public ArrayList getCart (string orders)
{
ArrayList cartal = new ArrayList ();
If (Session ["orders"]! = Null)
{
Cartal = (ArrayList) Session ["orders"];
}
Else
{
Cartal. Clear ();
}
String [] ss = orders. Split (',');
If (cartal. Count = 0)
{
Cartal. Add (orders );
}
Else
{
Bool r = false;
For (int I = 0; I <cartal. Count; I ++)
{
String [] SC = cartal [I]. ToString (). Split (',');
If (ss [0]. ToString () = SC [0]. ToString () // judge whether the order is repeated
{
SC [4] = Convert. ToString (int. Parse (SC [4]. ToString () + int. Parse (ss [4]. ToString ()));
Cartal [I] = SC [0] + "," + SC [1] + "," + SC [2] + "," + SC [3] + ", "+ SC [4];
R = false;
Break;
}
Else
{
R = true;
}
}
If (r)
{
Cartal. Add (orders );
}
}
Return cartal;
}