how to model discount on items in a database?

前端 未结 4 2068
离开以前
离开以前 2021-02-05 23:30

I am building an ecommerce site and would like to offer discounts on certain items for a limited time.

My Product table (MySQL) looks like this:

Product
    -         


        
4条回答
  •  长情又很酷
    2021-02-06 00:10

    Another thing to consider would be, how do you model situation when there is no discount for a given item? You might use a Null Object pattern here - basically, when a product is created, you also add a deal on that product with 0% discount and unlimited time. That way, you could simplify your product retrieval logic (no outer joins in query, no if for calculating price).

提交回复
热议问题