suppose you have table 'users'
with id, name, email, password, lastvisit, lastaction, etc..
what you could do, is to add new field in 'users' record:
user_shopping_basket ( or current_cart, or current_order )
which stores this users' cart, as long as have NOT yet sent in his order.
When he comes back, he can continue picking thing into, or out of cart
and maybe send his order. Start making a new 'cart'
you do not have to empty this field: 'cart_contents',
you can have an extra field: cart_status:
with options:
empty, order_not_sent, order_awaiting_delivery, order_delivered, new_cart
you may even for any user have an automatically
creation of a 'table' named: 'user_id+_order
where user_id, is id number of each user.
This is a typical 'Database'-forum issue, but as you started
asking about how to make a 'cart-script', this place is okay.
====
Regarding making this cart application:
add item, remove item, show cart, empty cart, order cart, set item color, set item attribute, save cart, delete cart ......
This is the kind of app that is well suited to write a Class. Object Oriented Program. OOP:
A Class is a collection of functions, that all deals with some kindsame kind of object(s)
where 'object' may be a shopping cart, member-of-website, user, forum-posts, and even object can be a no-thing
like a collection of functions that all do similiar things, actions:
display templates in diferent styles-colors, send different kind of emails using different email transporting ways,
handling website security authentication
=======================
Vampirev Cart Class.
- main object to handle is 'cart', each one belonging to a user with id='x' at my website
- functions I need to add to my class (my collection of funcs dealing with cart and cart-items )
new_cart
delete_cart
empty_cart
add_item
remove_item
set_item_attribute ( color, size, quality, text-label )
change_item_attribute
set_item_quantity ( how many t-shirts of this sort to order )
check_item_available ( do you have these items ready to deliver to custumer? )
display_cart_contents
order_cart_contents
order_status
Well, you know better what functions you need.
within your class, all functions use same name for things:
cart_id_num
cart_user_id_num
cart_user_name
curr_cart = current cart
cart_contents
total_items_in_cart
so these functions can interact in a smooth way,
they all use same labels to refer to objects.
you get the picture, Vampirev.
now only up to you and your imagination how you create your class
It depends on what you need and want.
you can also add more functions to this Class: Vampirev Cart Class
in future to add new things that can be handled by it.
But try to keep this Cart Class
only to deal with same objects: 'cart, item, item-attribute'
to handle objects: 'users, members', you should Create another class: Vampirev Users Class
🆒