Stock control

Asked

Viewed 532 times

2

Guys I’m developing a shopping cart...

I arrived at a part that ended up gone wrong... the next cart consists of product recipe is additional and removal of ingredients

tabela produtos
id     nome      id_lanche    preço
1     X-egg       1            7.00
2     X-tudo      2            9.00

tabela receita
id     nome      id_lanche    preço     quantidade (quantiodade no caso e quanto o produto tem de cada item)
1     alface      1            1.00      1
2     bacon       1            2.00      2
3     Cheddar     1            2.00      2
4     Bife        1            3.00      1
5     alface      2            1.00      1
6     bacon       2            2.00      2
7     Ovo         2            2.00      1
8     Bife        2            3.00      1

Tabela estoque
id     nome      quantidade
1     alface      10
2     bacon       5

turns out there’s one lettuce with id 1 and one with id 2... He can’t identify the item to drop... in stock I thought by name I just don’t think it’s 100% effective... if the name I spelled wrong it won’t work...

you could help me develop an effective way?

  • 1

    Another improvement, by your modeling shown here, I do not see the need for the field id_lanche on the table produtos, once the fields id e id_lanche are equal. So you could relate only to the id, being like this: receita.id_lanche = produtos.id, unless you have another table called lanche that is not being shown in the example, there can ignore everything I said.

  • @Kaduamaral, thanks for the advice. I’ve used it in the project, I had even other things kind of duplicated tbm

1 answer

7


you have to store the lettuce id in the recipe table, as in the stock the lettuce is id = 1, so instead of the name "lettuce" in the recipe table, you save the id, your tables would look like this:

tabela produtos
id     nome      id_lanche    preço
1     X-egg       1            7.00
2     X-tudo      2            9.00

tabela receita
id    id_produto  id_lanche    preço     quantidade (quantiodade no caso e quanto o produto tem de cada item)
1     1           1            1.00      1
2     2           1            2.00      2
3     3           1            2.00      2
4     4           1            3.00      1
5     1           2            1.00      1
6     2           2            2.00      2
7     5           2            2.00      1
8     4           2            3.00      1

Tabela estoque
id     nome      quantidade
1     alface      10
2     bacon       5
3     Cheddar     6
4     Bife        8
5     Ovo         12

This way, you can update the item stock without conflicts.

  • thank you very much worked perfect! :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.