Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

eggplantSword's avatar

Setup DB for when a product is on sale

What would you do to handle products and when these products have a sale?

Should I add a field to Product to indicate a sale or should Sales be a different model and use it with like a one to many relationship?

One Sale has Many Products One Product has One Sale

0 likes
3 replies
jlrdw's avatar

Just flag products on sale via a boolean field and perhaps an extra field for amount off. Record any sales normally with sale price.

Depending on how complex, you may need a related table to track what percent something is marked down.

But I try to keep as simple as possible.

Example: widget for a week is 50% off, ok for that week sell them record the invoices, etc.

But somewhere, have the boolean to change to now not on sale.

eggplantSword's avatar

@jlrdw I did it that way for another online store I did it had a discount field that was a %, when empty it's not on sale. I was just wondering if that was the best way.

jlrdw's avatar

It's one way. But really the best way, that can be a very subjective.

Please or to participate in this conversation.