vendredi 14 janvier 2022

How to represent/store/handle data when when there are multiple input and one output in backend and frontend?

I am building an E-commerce type application where I need to show the price of an item based on multiple option selection like:

packet size concentration Color Price
250ml 100 white 100
250ml 100 Gray 90
250ml 50 white 80
250ml 50 Gray 70
100ml 100 white 50
100ml 100 Gray 40
100ml 50 white 30
100ml 50 Gray 20

So Options would look something like this:
PackSize: | 250ml | 100ml |
Concentration: | 100 | 50 |
Color: | white | Gray |

Based on user selection of options from all three category, I intend to get the final price.

How should I store this data in RDBMS, as currently all possible combination is stored with a unique id and its price, but how should I share this data to the frontend for the selection of option through the checkbox.

I could think of a nested Map with pack size as a key like:
Map<packSize,Map<concentration,Map<color,Price>>> and refresh all options as an option get selected and so on.

But it doesn't feel right, as if the user selects the options in any other order like going from child to parent (color->concentration->packsize) rather than the parent to child (packSize->concentration->color) i am not sure how to track each selection and show the corresponding price.

Is there any better approach, can Hashing(taking all three inputs along with unique id and creating a one-to-one mapping with hash and price) work here? What is the best convention?

A nudge to the right path would be very helpful, else i could end up doing a lot of unnecessary, complex, and inefficient coding.

Aucun commentaire:

Enregistrer un commentaire