Chud37
Chud37

Reputation: 5007

How to record discounts in a shop?

I've been thinking about this for a while now, but I am still not sure as the best way to go about it.

So basically, in my online shop I have an order table:

+------+-------+---------+-------------+----------------+--------------+--------+
|  id  | name  |  email  | grand-total | shipping-costs |   address    | status |
+------+-------+---------+-------------+----------------+--------------+--------+
| 4312 | Roger | [email protected] | 5.99        |              1 | 22 Road Lane |      1 |
+------+-------+---------+-------------+----------------+--------------+--------+

And linked to that table is the cart table:

+-----+---------+-----------+---------------+-------+----------+--------+
| id  | orderID | productID |     name      | price | quantity | status |
+-----+---------+-----------+---------------+-------+----------+--------+
| 234 |    4312 | G55Sd     | Super Product | 5.99  |        1 |      1 |
+-----+---------+-----------+---------------+-------+----------+--------+

This all works correctly. However, the problem comes when I want to start adding discounts. I want to be able to look at a past order, and know exactly what discount was applied, how much etc. But I don't know where to save it. And what if the customer has multiple discounts? I can't just add another column in the orders table for discount, or discount amount, as that wouldn't help future me look over it at all.

I was thinking maybe I could add a line in the cart table for that order, and apply it like a product, just with a minus amount. I could do with some advice please.

Upvotes: 0

Views: 57

Answers (1)

P.Salmon
P.Salmon

Reputation: 17615

Be careful you don't over-normalise. Disk is cheap - I would consider holding discount details in the order table and the cart table. The business logic could be every product might accrue a discount and the order itself might have a discount on top of the product discount(s).

Upvotes: 1

Related Questions