I highly recommend using off-the-shelf software for shopping carts. Why make your own when others already did the work for you?
A quick search came up with many options: https://duckduckgo.com/?q=shopping+cart+software&t=ffab&ia=web
A tip: no one here will write your code for you. You'll need to make a serious attempt to research and start writing your code, then we'll be able to help you with your code when you get stuck and ask.