A
A
Alex-19172018-09-19 23:14:18
MySQL
Alex-1917, 2018-09-19 23:14:18

How to organize the preservation of the product option when editing it?

The question arose - an idea flowed)))
I'm picking one self-written note here, there were goods without an option, and options suddenly became needed.
An option is a combination of size and color , similar to trading offers in Bitrix. Or, similarly to product modifications in opencart ...
Ok, I added the options. And how to save them now, if you need to add a couple more options? Or if we delete some option as unnecessary?
Here are the details:
The product is a Hawaiian shirt.
Options:
50 size, color blue for 230 rubles in a quantity of 200 pcs 52 size,
color blue for 240 rubles in a quantity of 240 pcs
50 size, color yellow for 250 rubles in a quantity of 320 pcs
52 size, color blue for 180 rubles in a quantity of 120 pcs.
For example, I opened such a product and delete one line.
And then I add a new line or two.
How to fix these movements and transfer them to the database when saving the goods?
Option 1 - when editing a product, delete all its options in the database and write new options. But this will swell the index in the option table.
Option 2 - keep an array of options for the current item in the session.
What do you suggest, experts?
Here is the DB schema:
5ba2ae183be8c958072948.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyrkmod, 2018-09-20
@vyrkmod

It is not necessary to delete everything at once, the user does not ask for this from the interface. Accordingly, we hold the "delete" buttons for each option and the form for the new one. We know how - send ajax-s and edit html when they are answered. We do not know how - we wrap each button in our form, clicking on them the user will "leave" the page. Well, having accepted and removed the desired option, we again send the user to the product page.
Z.Y. you shouldn't remove price from product, otherwise products without these options will be unrealistic to "rate", it's better to just write null there and process accordingly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question