I am attempting to build an Ecomerce thingymajig and I was wondering what the best way is to store the items being purchased.
If a user goes to a page that has a shirt on it
Red Shirt
Sizes | Price | Qty
small 15.00 3
med 20.00 0
Lrg 25.00 1
Then they hit add to cart, how would I store this info in the session? Would I add it to a string then store the string in the session?
For example say the user has already added a couple blue shirts
My string would look like this, in this order
ItemName-Size-Price-Qty
SessionRegister[Items];
$Items="BlueShirt-S-15.00-3/BlueShirt-L-25.00-5/"
Then when they went to add the red shirts I would add to the string
$Items.="RedShirt-S-15.00-3/RedShirt-L-25.00-1/"
So I would end up with a string like this
"BlueShirt-S-15.00-3/BlueShirt-L-25.00-5/RedShirt-S-15.00-3/RedShirt-L-25.00-1/"
Then when I wanted to get the items I would create an array by using explode
TheItems = explode("/",$Items)
Then to get the individual stats of each item I would use another array
TheStats = explode("-",TheItems[0])
So then I could say
$ItemName = $TheStats[0]
$ItemSize = $TheStats[1]
$ItemPrice = $TheStats[2]
$ItemQty = $TheStats[3]
Is that how this is done? I;ve never done it before so I am not sure this is the best way to go... Any input would be great!
Thanks!😃 😃