1
I wanted to group the products by sellers in my shopping cart. Currently it displays a single list without this separation.
Example:
Pedro and Maria advertise on my website and each one has their products offered and when the customer clicks to buy Pedro’s product list in group form only Pedro’s products and if Maria also buys it in group. As below:
Salesman(to) (Peter)
*Produto 1 2 R$ 45,00 R$ 90,00
*Produto 2 1 R$ 25,00 R$ 25,00
Enviar Pedido de Compra
Salesman(to) (Maria)
*Produto 1 1 R$ 45,00 R$ 45,00
*Produto 2 1 R$ 25,00 R$ 25,00
Enviar Pedido de Compra
Note that the customer will have to send the purchase order to the two buyers.
The loading of the products I already made, I’m just not able to group by sellers.
The part of the cart query and display is below:
foreach ($_SESSION['carrinho'] as $id => $qtd) {
$sql_vendedor = "SELECT * FROM produtos WHERE id='$id'";
$qr_vendedor = mysql_query($sql_vendedor) or die(mysql_error());
$ln_vendedor = mysql_fetch_assoc($qr_vendedor);
$vendedor = $ln_vendedor['vendedor_id'];
$sql = "
SELECT produtos.id, produtos.nome as descricao,produtos.preco,
produtos.imagem, produtos.vendedor_id, vendedores.nome as nomevendedor
FROM produtos
INNER JOIN vendedores ON produtos.vendedor_id = vendedores.vendedor_id
WHERE id='$id' AND produtos.vendedor_id=$vendedor
GROUP BY " . $vendedor;
$qr = mysql_query($sql) or die(mysql_error());
$ln = mysql_fetch_assoc($qr);
$imagem = $ln['imagem'];
$nome = $ln['descricao'];
$preco = number_format($ln['preco'], 2, ',', '.');
$sub = number_format($ln['preco'] * $qtd, 2, ',', '.');
$vendedor_id = $ln['vendedor_id'];
$id_produto = $ln['id'];
$total += $ln['preco'] * $qtd;
$nomevendedor = $ln['nomevendedor'];
echo '<tr>';
echo '<td class="shopping-cart-image">';
echo '<a href="#"><img src="assets/temp/products/' . $imagem . '" alt="Berry Lace Dress"></a>';
echo '</td>';
echo '<td class="shopping-cart-description">';
echo '<h3><a href="#">' . $nome . '</a></h3>';
echo '<p><strong>Item ' . $id_produto . '</strong> - Colocar mais alguma descrição aqui...</p>';
echo '<em>Mais Informações</em>';
echo '</td>';
echo '<td class="shopping-cart-ref-no">' . $vendedor_id . ' - ' . $nomevendedor . '</td>';
echo '<td class="shopping-cart-quantity">';
echo '<div class="product-quantity">';
echo '<input id="product-quantity" type="text" name="prod[' . $id . ']" value="' . $qtd . '" readonly class="form-control input-sm">';
echo '</div>';
echo '</td>';
echo '<td class="shopping-cart-price">';
echo '<strong><span>R$ </span>' . $preco . '</strong>';
echo '</td>';
echo '<td class="shopping-cart-total">';
echo '<strong><span>R$ </span>' . $sub . '</strong>';
echo '</td>';
echo '<td class="del-goods-col">';
echo '<a class="del-goods" href="?acao=del&id=' . $id . '"><i class="fa fa-times"></i></a>';
echo '</td>';
echo '</tr>';
}
It was not very clear where the problem is. Is it in the visualization? In the consultation to the bank?
– Lucas
Thank you so much for answering... so I can bring the products from the database without error, however I am not able to group by seller. Like this image: http://s16.postimg.org/m7snp72bp/Screenshot_8.jpg
– Carlos Henrique
Got it. Post the part that you perform the query to the bank (with the name of the fields)
– Lucas
The download link is: http://www.mediafire.com/view/edqx5glxg34946r/codigo.txt
– Carlos Henrique
I edited your question with part of the code. The more useful information, the better for the staff to help you
– Lucas
Thank you so much for the way Lucas....
– Carlos Henrique