Skip to content

Commit

Permalink
tentando editar os pedidos
Browse files Browse the repository at this point in the history
  • Loading branch information
valdiney committed Sep 4, 2020
1 parent 09a7824 commit 8eac230
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion App/Controllers/PedidoController.php
Expand Up @@ -130,7 +130,9 @@ public function modalFormulario($idPedido = false)
$produtoPedido = new ProdutoPedido();
$produtosSelecionadosNaEdicao = $produtoPedido->produtosPorIdPedido($pedido->id);

dd($produtosSelecionadosNaEdicao);
foreach ($produtosSelecionadosNaEdicao as $produto) {
$this->vendasEmSessaoRepository->colocarProdutosVindosDoBancoDeDadosNaMesa($produto);
}
}

$usuario = new Usuario();
Expand Down
8 changes: 6 additions & 2 deletions App/Models/ProdutoPedido.php
Expand Up @@ -22,8 +22,12 @@ public function produtos($idEmpresa = false)

public function produtosPorIdPedido($idPedido = false)
{
return $this->query(
"SELECT * FROM produtos_pedidos WHERE id_pedido = {$idPedido}"
return (object) $this->query(
"SELECT p.id, p.nome AS produto, p.preco, p.imagem,
pd.quantidade, pd.subtotal AS total
FROM produtos_pedidos AS pd
INNER JOIN produtos AS p ON pd.id_produto = p.id
WHERE pd.id_pedido = {$idPedido}"
);
}
}
12 changes: 12 additions & 0 deletions App/Repositories/VendasEmSessaoRepository.php
Expand Up @@ -95,4 +95,16 @@ public function limparSessao()
{
unset($_SESSION['venda']);
}

function colocarProdutosVindosDoBancoDeDadosNaMesa($produto)
{
$_SESSION['venda'][$produto->id] = [
'id' => $produto->id,
'produto' => $produto->produto,
'preco' => $produto->preco,
'imagem' => $produto->imagem,
'quantidade' => $produto->quantidade,
'total' => $produto->total
];
}
}
7 changes: 6 additions & 1 deletion App/Views/pedido/formulario.php
Expand Up @@ -420,7 +420,12 @@ function produtosAdicionados() {
}*/

function savePedidos() {
var rota = getDomain()+"/pedido/save";
<?php if (isset($pedido->id)):?>
var rota = getDomain()+"/pedido/update";
<?php else:?>
var rota = getDomain()+"/pedido/save";
<?php endif;?>

$.post(rota, {
'_token': '<?php echo TOKEN; ?>',
'id_vendedor': $("#id_vendedor").val(),
Expand Down
1 change: 1 addition & 0 deletions routes/routes.php
Expand Up @@ -96,6 +96,7 @@
$route->get('pedido/obterAQuantidadeDoProdutoNoPedido/{idProduto}', 'PedidoController@obterAQuantidadeDoProdutoNoPedido');
$route->get('pedido/obterValorTotalDoPedido', 'PedidoController@obterValorTotalDoPedido');
$route->post('pedido/save', 'PedidoController@save');
$route->post('pedido/update', 'PedidoController@update');

$route->get('pedido/teste', 'PedidoController@teste');

Expand Down

0 comments on commit 8eac230

Please sign in to comment.