How to create a Products table that has several prices?

Asked

Viewed 98 times

0

Someone would know how to map a Products table, and the product has different prices for each type of parcel the customer chooses. For example I created a table called PRICES and in it there is FK of the PRODUCT, but when creating foreach links and popular the datagrid is necessary that each PRODUCT lists its different prices. To clarify my question:

A PRODUCT can be parceled up to 12x and for each type of parcel the value is different, so there are tables:

PRODUCT TABLE

PRODUTOID, 
DESCRICAO, 
COR, 
TAMANHO, 
TECNOLOGIA, 
FORNECEDOR, 
IMAGEM_NOME, 
IMAGEM_CAMINHO

PRICE TABLE

PRECOID, 
QTD_PARCELAS, 
VALOR, 
PRODUTOID

If anyone can help me how to create the link foreach mapping the various prices relating to various products, I would appreciate it very much!

1 answer

1

Dude, you do a for or foreach picking up the products and another foreach to get every price. Would that be right? Try following this example. Hugs

var produtos = [
  {
    id: 1,
    produto: "Produto 1",
    price: 150
  },
  {
    id: 2,
    produto: "Produto 2",
    price: 600
  }
];

var precos = [
  {
    id: 1,
    qtd: 2
  },
  {
    id: 2,
    qtd: 3
  }
];


for(var i = 0; i < produtos.length; i++){
   console.log("Produto: ", produtos[i].produto, " / Preço total: ", produtos[i].price);
   for(var j = 0; j < precos.length; j++){
      console.log("Parcela: ", precos[j].qtd, " vezes / Preço: ", produtos[i].price / precos[j].qtd, " R$");
   }
}

Browser other questions tagged

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