How to create a table Products that have different prices?

0

Someone would know how to map a Products table, and the product has different prices for each type of parcel that the customer chooses. For example I created a table called PRECOS and there is FK of the PRODUCT, but at the time of creating the foreach loops and popular datagrid it is necessary that each PRODUCT lists their different prices. To make my question more clear:

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

PRODUCT Table

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

PRICE Table

PRECOID, 
QTD_PARCELAS, 
VALOR, 
PRODUTOID

If someone can help me how to create the foreach loop mapping the various prices for various products, I appreciate it!

    
asked by anonymous 12.08.2016 / 02:29

1 answer

1

Dude, you make a for or foreach by picking up the products and another foreach to get each price. Is that right? Try to follow 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$");
   }
}
    
12.08.2016 / 03:05