-
-
Save parzibyte/13309131d3096efd01384b66ee7f63d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#<?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