0

I am new to database design and having a trouble on the database design for shopping cart for an online shopping system.

The system will have 3 catagories, Book, Videos, Games.The shopping cart are able to store these items and check out.

For the ERD, my idea was: 1 Cart can have 1 or many Products 1 or many products are in 1 Catagory.

My question is,for example, the book has an ISBN attribute while Video does not, thus I cannot put them into the single "Product" entity, but if I seperate them into three..

1 Cart can have 0 or many Books. 1 Cart can have 0 or many Videos. 1 Cart can have 0 or many Games.

So there is a situation that there may have all "0" situation, but it does not make senses as the cart must have at least one product inside.

Sorry for my pool english~Thanks.

user1056416
  • 9
  • 1
  • 2

1 Answers1

1

Firstly I can't see what's the problem with having 0 items in a shopping cart. When you go to a real shop and you collect a cart it initially has 0 items. So this makes perfect sense.

I am not sure what the proper notation/language is for an ERD, but in terms of software classes I think you should have.

Shopping cart - contains 0 or more Products

Product

  • Id ~ a field you auto-generate
  • List item
  • Name
  • Description
  • Price
  • etc.

Which has subclasses

Book

  • ISBN
  • Author
  • Publisher
  • etc.
  • List item

Video

  • Length
  • Actor
  • Director
  • etc.
  • List item

Game

  • Genre
  • List item
  • Platform
  • etc.

Even if you keep the three different product types (book, video, game) as entirely separate it doesn't mean you cart can't contain 0 objects.

Ankur
  • 50,282
  • 110
  • 242
  • 312