E
E
ErikHabr2022-03-23 13:51:56
Django
ErikHabr, 2022-03-23 13:51:56

How to correctly implement adding a product with options to the cart on Django Rest Framework?

Need help, I'm confused.
I am writing an analogue of Yandex food and other platforms. I am currently writing an API on the django rest framework.
At me the basket through a DB is implemented. I save it with the session key if the user is a guest or bind it to the user if he is authorized. Everything works for me through the database: the use of promotional codes, bonuses, min. order amount, etc.
So now, as they say, the final touch. Products have modifiers and additives. For example, when choosing a pizza, you can choose its size (modifier) ​​and add mushrooms and peppers (additives). I implemented this through a session, as a result I have an array with data if some options were added to the product and there are baskets that are in the database.

And then I got confused, if I just add a product to the cart (without options), it will appear there, but if there is the same product with options in the session, then I look for this case by id and put the product and options in the basket from the session. But I can't put the same product with different options as different products because the product is checked by id. I cannot put products that were added before the session or just products without options if there are products from the session in the cart. In short, complete nonsense is obtained. Of course, I can zakolhoz how it goes on, but everything is not working as it should.

Who can help or who has experience and knowledge in the implementation of such baskets and goods. It is desirable to do everything on the backend. Do I need to rewrite the entire basket now and not save it to the database, but only work in the session?
I am ready to pay for this problem, if someone can take up the implementation. I am ready to pay for Skype consultation and assistance in writing code.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dr. Bacon, 2022-03-23
@bacon

Products have modifiers and additives... I implemented it via session
why everything before was through a DB, and it suddenly became through session?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question