In general, there is a section Promotions and discounts to which promotions are added. You can attach different products to each stock together with the promotional price, at least all several thousand items.

The field for the selection of goods and the promotional price of the goods is cloned into js, ​​for each product there are separate fields.

Under the goods attached to the action created a separate table:

action_goods ------------ id action_id (id акции) good_id (id товара) good_name (Имя товара) action_price 

One to many relationship is obtained. So, when creating / editing a stock, every time I bang all the goods attached to the stock and re-record those products that are in shape.

I understand that if several thousand products are added to the stock, it’s not very healthy to overwrite them each time.

Otherwise, do not overwrite everything again, the promotional price may change and each time you will have to check whether this product is attached to the stock or not and, accordingly, select insert or update for each product.

That last option looks even worse.

Please advise how best to implement.

    1 answer 1

    If I understand correctly, then on the page you will see all the products from the promotion. And you can edit any. Then the solution:

    1. For each product on the form add an action field with possible values.
      • Nothing
      • Added
      • Updated
      • Deleted
    2. Upon arrival of the form to the server, check this field and perform the appropriate action.
    3. Do not get confused with the logic of field modification
      • Added + Updated = Added
      • Added + Deleted = Nothing
      • Updated + Deleted = Deleted
    • great idea! thank. and on the server, when making a request to the database, I think to group products by actions. - md5hash
    • @ md5hash Not necessary. You can create three prepared requests and execute the necessary one for each item - Anton Shchyrov