session_start(); require_once("inc/conexion.php"); require_once("inc/SQLManager.php"); require_once("inc/funciones.php"); if ( $_GET["accion"] == "borrar" ) { foreach ( $_SESSION["carro"] as $value => $key ) { if ( $_SESSION["carro"][$value]["idProducto"] == $_GET["idProducto"] ) unset($_SESSION["carro"][$value]); } recalcula(); } if ( $_GET["accion"] == "agregaralcarro" ) { $existe = false; for ( $i=0; $i < count($_SESSION["carro"]); $i++ ) { if ( $_SESSION["carro"][$i]["idProducto"] == $_GET["idProducto"] ) { $existe = true; } } if(!$existe) { $sql = "SELECT * FROM productos WHERE idProducto = " .$_GET["idProducto"]; $prod_carro = $conn->unique($sql); $arr = array(); $arr["idProducto"] = $prod_carro["idProducto"]; $arr["idCategoria"] = $prod_carro["idCategoria"]; $arr["idTipotienda"] = $prod_carro["idTipotienda"]; $arr["codprod"] = $prod_carro["codprod"]; $arr["nombre"] = utf8_encode($prod_carro["nombre"]); $arr["marca"] = utf8_encode($prod_carro["marca"]); $arr["tipo"] = utf8_encode($prod_carro["tipo"]); //$arr["descripcion"] = utf8_encode($prod_carro["descripcion"]); $arr["precio"] = $prod_carro["precio"]; $arr["preciooferta"] = $prod_carro["preciooferta"]; $arr["foto"] = $prod_carro["foto"]; $arr["stock"] = $prod_carro["stock"]; $arr["pdf"] = $prod_carro["pdf"]; $arr["coorporativo"] = $prod_carro["coorporativo"]; $arr["posicion"] = $prod_carro["posicion"]; $arr["oferta"] = $prod_carro["oferta"]; $arr["cantidad"] = 1; $arr['subtotal'] = $prod_carro["precio"]; $_SESSION["carro"][] = $arr; recalcula(); } } if ( $_GET["accion"] == "recalcula" ) { recalcula(); } function recalcula () { foreach ( $_POST as $value => $key ) { //echo "busca: " . $value; foreach ( $_SESSION["carro"] as $value2 => $key2 ) { if ( $key2['idProducto'] == $value ) { $_SESSION["carro"][$value2]['cantidad'] = $key; $_SESSION["carro"][$value2]['subtotal'] = $_SESSION["carro"][$value2]['cantidad'] * $_SESSION["carro"][$value2]['precio']; } } } $_SESSION["total"] = 0; foreach ( $_SESSION["carro"] as $value => $key ) { $_SESSION["total"] = $_SESSION["carro"][$value]['subtotal'] + $_SESSION["total"]; } } ?>
|