Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 5, 2019 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/13309131d3096efd01384b66ee7f63d6 to your computer and use it in GitHub Desktop.
Save parzibyte/13309131d3096efd01384b66ee7f63d6 to your computer and use it in GitHub Desktop.
#<?php
public function nueva($productosVendidos){
# Primero registramos la venta
$detalleDeVenta = array("fecha" => date("Y-m-d H:i:s"));
$this->db->insert("ventas", $detalleDeVenta);
# Ahora tomamos su ID
# Ver: https://parzibyte.me/blog/2018/03/20/ultimo-id-insertado-codeigniter/
$idVenta = $this->db->insert_id();
# Recorrer el carrito
foreach($productosVendidos as $producto){
# El producto que insertamos es diferente al del carrito, sólo necesitamos algunas cosas:
$detalleDeProductoVendido = array(
"id_producto" => $producto->id,
"cantidad" => $producto->cantidad,
"precio" => $producto->precioVenta,
"id_venta" => $idVenta,
);
$this->db->insert("productos_vendidos", $detalleDeProductoVendido);
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment