My suggestion would be to build a shopping cart class.
The class could include the following
1) an associative array with the product_id as key and the quantity for that product as the value
2) an associative array with the product_id as key and the price of the product when it was added to the cart as the value
3) class method to calculate the total value of the cart from the arrays in 1)
4) class methods to add/delete/change quantitiies for items in the cart
5) class method to empty the cart
6) class methods to retrieve the cart contents for display purposes.
If you post the code you have so far, it will be easier to help you.