Пример #1
0
    function select_by_user($idUsuario, $tipoDePago, $IVA)
    {
        //incluye classes necesarias
        include_once "class.categorias.php";
        include_once "class.productos.php";
        include_once "class.compras.php";
        include_once "class.usuarios.php";
        include_once "class.talles_productos.php";
        include_once "class.colores_productos.php";
        include_once "class.talles.php";
        include_once "class.colores.php";
        include_once "class.historiales.php";
        include_once "class.historiales.php";
        require_once 'control/resources/pdo.php';
        require_once "control/productos/classes/class.tallesColores.php";
        //variables de la sumas de valores, tanto de precios como total
        $total = 0;
        $total_general = 0;
        $totales[] = 0;
        $sql = "SELECT * FROM carrito WHERE idUsuario = {$idUsuario};";
        $result = $this->database->query($sql);
        $result = $this->database->result;
        $detalle_productos = "";
        while ($row = mysql_fetch_array($result)) {
            $intContador = $row['intContador'];
            $idUsuario = $row['idUsuario'];
            $idProducto = $row['idProducto'];
            $intCantidad = $row['intCantidad'];
            $intTransaccion = $row['intTransaccion'];
            $id_talle = $row['talle'];
            $id_color = $row['color'];
            //Traigo precio de los productos
            $productos = new productos();
            $productos->select($idProducto);
            $dblPrecio = $productos->getdblPrecio();
            $strNombre = $productos->getstrNombre();
            $strDetalle = $productos->getstrDetalle();
            $intCategoria = $productos->getintCategoria();
            $strintStock = $productos->getintStock();
            $estado_producto = 1;
            $cat = new categorias();
            $cat->select($intCategoria);
            $requiere_talles = $cat->gettalles();
            if ($requiere_talles == 1) {
                try {
                    $stock = new TempStock();
                    echo $stock->removeTempStock($row['idUsuario'], $row['idProducto'], $row['talle'], null, $requiere_talles);
                } catch (Exception $e) {
                    echo $e->getMessage();
                }
                #############################################
                // REQUIERE TALLES
                #############################################
                //compruebo que haya producto en stock
                //traigo el stock del producto desde talles_productos
                $tall_prod = new talles_productos();
                $tall_prod->select_by_producto($idProducto, $id_talle);
                $cantidad_stock_con_talles = $tall_prod->getcantidad();
                if ($cantidad_stock_con_talles >= $intCantidad) {
                    $nom_talle = new talles();
                    $nom_talle->select($id_talle);
                    $nombre_de_talle = $nom_talle->getnombre_talle();
                    $detalle_productos .= '
				<div class="purchase">
				<img src="http://nufarm-maxx.com/imagenes/marketingnet-mail_FLECHITA-04.jpg" width="8" height="11">
				<span class="tit22"> ' . $strNombre . '</span><br>
				<span class="cant"> Cant: ' . $intCantidad . ' </span><br>
				<span class="cant"> Talle: ' . $nombre_de_talle . ' </span><br>
				<span class="tot_1"> ' . $dblPrecio . '</span><br>
				<span class="tot_2"> Total: ' . $intCantidad * $dblPrecio . '</span></div>';
                    //quito del stock
                    $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'talle' => $nombre_de_talle, 'estado_producto' => $estado_producto, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => $intCantidad * $dblPrecio);
                    // $taproductos= new talles_productos();
                    // $taproductos->select_by_producto($idProducto,$id_talle);
                    // $id_talle_producto = $taproductos->getid();
                    // $upcantidad = new talles_productos();
                    // $upcantidad->select($id_talle_producto);
                    // $upcantidad->cantidad = $cantidad_stock_con_talles - $intCantidad;
                    // $upcantidad->update($id_talle_producto);
                    $total = $dblPrecio * $intCantidad;
                } else {
                    $detalle_productos .= '<p>&#8226; <span style="font-size:10px"> ID:' . $idProducto . '</span> ' . $strNombre . '<br> Cantidad solicitada:' . $intCantidad . ',  NO DISPONIBLE -  0.00 </p>';
                    $total = 0;
                    $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => 0);
                }
            } else {
                if ($requiere_talles == 2) {
                    try {
                        $stock = new TempStock();
                        echo $stock->removeTempStock($row['idUsuario'], $row['idProducto'], null, $row['color'], $requiere_talles);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    #############################################
                    // REQUIERE COLORES
                    #############################################
                    //compruebo que haya producto en stock
                    //traigo el stock del producto desde talles_productos
                    $col_prod = new colores_productos();
                    $col_prod->select_by_producto($idProducto, $id_color);
                    $cantidad_stock_con_colores = $col_prod->getcantidad();
                    if ($cantidad_stock_con_colores >= $intCantidad) {
                        $nom_color = new colores();
                        $nom_color->select($id_color);
                        $nombre_de_color = $nom_color->getnombre_color();
                        $detalle_productos .= '
				<div class="purchase">
				<img src="http://nufarm-maxx.com/imagenes/marketingnet-mail_FLECHITA-04.jpg" width="8" height="11">
				<span class="tit22"> ' . $strNombre . '</span><br>
				<span class="cant"> Cant: ' . $intCantidad . ' </span><br>
				<span class="cant"> Color: ' . $nombre_de_color . ' </span><br>
				<span class="tot_1"> ' . $dblPrecio . '</span><br>
				<span class="tot_2"> Total:  ' . $intCantidad * $dblPrecio . '</span></div>';
                        //quito del stock
                        $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'color' => $nombre_de_color, 'estado_producto' => $estado_producto, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => $intCantidad * $dblPrecio);
                        // $taproductos= new colores_productos();
                        // $taproductos->select_by_producto($idProducto,$id_color);
                        // $id_color_producto = $taproductos->getid();
                        // $upcantidad = new colores_productos();
                        // $upcantidad->select($id_color_producto);
                        // $upcantidad->cantidad = $cantidad_stock_con_colores - $intCantidad;
                        // $upcantidad->update($id_color_producto);
                        $total = $dblPrecio * $intCantidad;
                    } else {
                        $detalle_productos .= '<p>&#8226; <span style="font-size:10px"> ID:' . $idProducto . '</span> ' . $strNombre . '<br> Cantidad solicitada:' . $intCantidad . ',  NO DISPONIBLE -  0.00 </p>';
                        $total = 0;
                        $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => 0);
                    }
                } elseif ($requiere_talles == 3) {
                    $x = new tallesColores();
                    /**
                     * example of basic @ TempStock
                     * @param userid 
                     * @param product_id 
                     * @param talle 
                     * @param color 
                     * @return nothing on success, throw on error 
                     */
                    try {
                        $stock = new TempStock();
                        echo $stock->removeTempStock($row['idUsuario'], $row['idProducto'], $row['talle'], $row['color'], $requiere_talles);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    $talles = $x->talles();
                    $colores = $x->colores();
                    $nom_talle = $talles[$row['talle']];
                    $nom_color = $colores[$row['color']];
                    $detalle_productos .= '
		<div class="purchase">
		<img src="http://nufarm-maxx.com/imagenes/marketingnet-mail_FLECHITA-04.jpg" width="8" height="11">
		<span class="tit22"> ' . $strNombre . '</span><br>
		<span class="cant"> Cant: ' . $intCantidad . ' </span><br>
		<span class="cant"> Color: ' . $nom_color . ' </span><br>
		<span class="cant"> Talle: ' . $nom_talle . ' </span><br>
		<span class="tot_1"> ' . $dblPrecio . '</span><br>
		<span class="tot_2"> Total:  ' . $intCantidad * $dblPrecio . '</span></div>';
                    //quito del stock
                    $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'color' => $nom_color, 'talle' => $nom_talle, 'estado_producto' => $estado_producto, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => $intCantidad * $dblPrecio);
                    $total = $dblPrecio * $intCantidad;
                } else {
                    try {
                        $stock = new TempStock();
                        echo $stock->removeTempStock($row['idUsuario'], $row['idProducto'], null, null, 0);
                    } catch (Exception $e) {
                        echo $e->getMessage();
                    }
                    #############################################
                    //NO REQUIERE TALLES
                    #############################################
                    //compruebo que haya producto en stock
                    if ($strintStock >= 1) {
                        $detalle_productos .= '<div class="purchase">
		<img src="http://nufarm-maxx.com/imagenes/marketingnet-mail_FLECHITA-04.jpg" width="8" height="11">
		<span class="tit22"> ' . $strNombre . '</span><br>
		<span class="cant"> Cant: ' . $intCantidad . ' </span><br>
		<span class="cant"> </span><br>
		<span class="tot_1"> ' . $dblPrecio . '</span><br>
		<span class="tot_2"> Total:  ' . $intCantidad * $dblPrecio . '</span></div>';
                        $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'estado_producto' => $estado_producto, 'precio_pagado' => $intCantidad * $dblPrecio);
                        //quito del stock
                        // $productos= new productos();
                        // $productos->select($idProducto);
                        // $productos->intStock=$strintStock - $intCantidad;
                        // $productos->update($idProducto);
                        $total = $dblPrecio * $intCantidad;
                    } else {
                        $detalle_productos .= '<p>&#8226; <span style="font-size:10px">  ID:' . $idProducto . '</span> ' . $strNombre . ', <br> Cant: NO DISPONIBLE -  0.00 </p>';
                        $total = 0;
                        $detalle_para_guardar_por_id[] = array('id_producto' => $idProducto, 'nombre' => $strNombre, 'detalle' => $strDetalle, 'cantidad' => $intCantidad, 'precio_pagado' => $intCantidad * $dblPrecio);
                    }
                }
            }
            //Voy sumando los precios de los productos
            $totales[] = $total;
        }
        //Total sin IVA
        $valor_general = array_sum($totales);
        //Total con IVA
        $final_con_iva = $valor_general + $valor_general * $IVA / 100;
        if ($valor_general >= 1) {
            $detalle_titulo = "<div class='purchase_container'><h2 class='finalizado'>Su canje se realizo de forma exitosa!</h2>";
            $detalle_productos .= '</div>
	<div class="purchase_end">Total final: ' . $valor_general . '</div> 
	
	<!--<span style="font-size:10px; text-transform:uppercase;">Con IVA:</span> 
	$' . $final_con_iva . '</p>-->
	
	<a class="btn-micuenta77" href="mi_cuenta.php?activo=2">
		<span>VOLVER A MI CUENTA</span>
	</a>
	</div>
	
	';
        } else {
            $detalle_titulo = "<p>Error al procesar pago. importe: {$valor_general}</p> ";
        }
        if ($valor_general >= 1) {
            //Guardo compra en tabla "compras"
            $compra = new compras();
            $compra->idUsuario = $idUsuario;
            $compra->intTipoPago = $tipoDePago;
            $compra->fthCompra = date("Y-m-d H:i:s");
            $compra->dblTotal = $final_con_iva;
            #$compra->idCredito=$idCredito;
            $compra->detalle = $detalle_productos;
            $compra->estado = 1;
            $last_compra = $compra->insert();
            //Actualizo el credito del usuario
            #Primero traigo el monto actual de credito del usuario
            $usuarios = new usuarios();
            $usuarios->select($idUsuario);
            $creditoActual = $usuarios->getdblCredito();
            /* Realizo el UPDATE */
            $usuarios = new usuarios();
            $usuarios->select($idUsuario);
            $usuarios->dblCredito = $creditoActual - $final_con_iva;
            $usuarios->update($idUsuario);
            //Guardo la modificacion en historial de credito
            $monto_quedo_en = $creditoActual - $final_con_iva;
            $hist = new historiales();
            $hist->id_usuario = $idUsuario;
            $hist->fecha = date("Y-m-d");
            $hist->realizado_por = "Compra realizada";
            $hist->tipo_modificacion = $modificacion = "Compra de \${$final_con_iva}";
            $hist->monto_modificado = $monto_quedo_en;
            $hist->insert();
            //guardo el detalle de cada producto en detalles_compra para poder mostrar la img del producto comprado
            foreach ($detalle_para_guardar_por_id as $item_to_save) {
                $compra = new compras();
                $compra->insert_detalle_productos($last_compra, $item_to_save['id_producto'], $item_to_save['nombre'], $item_to_save['detalle'], $item_to_save['cantidad'], $item_to_save['precio_pagado'], $item_to_save['estado_producto'], $item_to_save['talle'], $item_to_save['color']);
                $k++;
            }
            /* borro del carrito del usuario los items*/
            $this->delete($idUsuario);
            return $detalle_titulo . '' . $detalle_productos;
        } else {
        }
    }
Пример #2
0
         $_SESSION["notification"] = "Disculpe, no se encuentra disponible la cantidad seleccionada.";
         @header('location: carrito.php');
         exit;
     }
     $tempMaxCompra->storeSum($id_producto, $canTotal);
     try {
         $stock = new TempStock();
         $stock->setTallesColores($id_producto, $_POST['pedido'], $_SESSION['MM_IdUsuario']);
     } catch (Exception $e) {
         echo $e->getMessage();
     }
     $id_usuario = $_SESSION['MM_IdUsuario'];
     //primero chequeo si el producto ya existe en el carrito del usuario.
     include_once "includes/class.carrito.php";
     // $carr =  new carrito();
     $x = new tallesColores();
     foreach ($pedido as $k => $v) {
         foreach ($v['talle'] as $kt => $vt) {
             if ((int) $vt > 0) {
                 $x->usuario = $_SESSION['MM_IdUsuario'];
                 $x->producto = $id_producto;
                 $x->color = $k;
                 $x->talle = $kt;
                 $x->cantidad = $vt;
                 $x->insert();
             }
         }
     }
     @header('location: carrito.php');
     exit;
 } else {
Пример #3
0
                $x = new TempStock();
                $x->liberarStockComunes($_GET['recordID'], $_SESSION['MM_IdUsuario']);
                $tempMaxCompra->storeRemains($_GET['recordID']);
            } catch (Exception $e) {
                echo $e->getMessage();
            }
            break;
    }
}
if ($cond) {
    $deleteSQL = sprintf("DELETE FROM carrito WHERE intContador=%s LIMIT 1", GetSQLValueString($_GET['recordID'], "int"));
    mysql_select_db($database_conexion, $conexion);
    $Result1 = mysql_query($deleteSQL, $conexion) or die(mysql_error());
    //Reintegro al stock el producto.
    include_once "includes/class.productos.php";
    //Traigo stock actual
    // $productos= new productos();
    // $productos->select($_GET['recordID']);
    // $StockActual=$productos->getintStock();
    //actualizo el stock
    // $productos= new productos();
    // $productos->select($_GET['recordID']);
    // $productos->intStock=$intStock = $StockActual + 1;
    // $productos->update($_GET['recordID']);
} elseif (isset($_GET['talle_colores'])) {
    $productos = new tallesColores();
    $sub = $_GET['sub'];
    $talle = $_GET['talle'];
    $delete = $productos->deleteItem($_GET['recordID'], $sub, $talle);
}
header('Location: carrito.php');
Пример #4
0
        $html = '';
        foreach ($colores as $key => $val) {
            $html .= '
						<div class="tallebox">
							<p>' . $val->nombre . '</p>
							<p><input class="inputshort" type="text" name="color[' . $val->id . ']" value="' . $val->cantidad . '" id="color' . $val->id . '"></p>
						</div>';
        }
        echo $html;
    } else {
        if ($talles == 3) {
            //require colores
            include_once "../colores/classes/class.colores.php";
            include_once "../talles/classes/class.talles.php";
            include_once "../productos/classes/class.tallesColores.php";
            $x = new tallesColores();
            $talles = new talles();
            $talles = $talles->all();
            $colores = new colores();
            $colores = $colores->all();
            $all = $x->all($_GET['idproducto']);
            $id_colores_usados = array_keys($all);
            $key = rand();
            $used = array_keys($all);
            if (isset($_GET['action']) && $_GET['action'] == 'add' || empty($all)) {
                ?>
					<div class="segmentTalleColor">
								<label for="">Color</label>
								<select name="color_talle[<?php 
                echo $key;
                ?>
Пример #5
0
 
			<p>CANTIDAD MAXIMA DE COMPRA <span><?php 
                    echo $limitCompraProd;
                    ?>
</span></p> 
			<input type="hidden" value="<?php 
                    echo $limitCompra;
                    ?>
" id="limitMax">
		<?php 
                } else {
                    ?>
			<input type="hidden" value="100000" id="limitMax">
		<?php 
                }
                $producto = new tallesColores();
                $all = $producto->all($row_DatosProductos['idProducto']);
                $colores = $producto->colores();
                $talles = $producto->talles();
                foreach ($all as $k => $v) {
                    ?>
	<div style="width:100%;float:left;">
		<a class="tooltip"><?php 
                    echo $colores[$k];
                    ?>
</a>
		<input type="hidden"  value="">
		<?php 
                    foreach ($v['talle'] as $kt => $vt) {
                        ?>
		<div class="talles-box <?php 
Пример #6
0
     $productos->idProducto = $idProducto;
     $productos->strNombre = $strNombre;
     $productos->strDetalle = $strDetalle;
     $productos->intCategoria = $intCategoria;
     $productos->intStock = $sumatoria_colores_total;
     $productos->dblPrecio = $dblPrecio;
     $productos->destacado = $destacado;
     $productos->intMinCompra = $intMinCompra;
     $productos->intMaxCompra = $intMaxCompra;
     $productos->message = $message;
     $productos->update($idProducto);
     $colours = new colores_productos();
     $colours->updateAllColours($color, $idProducto);
     $msg_final .= '<div class="notify"><p>producto actualizado! <a href="../productos/e_producto.php?id=' . $idProducto . '&activo=2&sub=d">Ver</a></p></div>';
 } elseif (isset($_POST["color_talle"])) {
     $x = new tallesColores();
     $x->idProducto = $idProducto;
     $x->strNombre = $strNombre;
     $x->strDetalle = $strDetalle;
     $x->intCategoria = $intCategoria;
     $x->intStock = $sumatoria_colores_total;
     $x->dblPrecio = $dblPrecio;
     $x->destacado = $destacado;
     $x->intMinCompra = $intMinCompra;
     $x->intMaxCompra = $intMaxCompra;
     $x->message = $message;
     $x->save();
     foreach ($_POST["color_talle"] as $k => $v) {
         try {
             $x->add($v, $idProducto, $v['color']);
         } catch (Exception $e) {
Пример #7
0
 if ((int) $canTotal > (int) $limite) {
     $_SESSION["notification"] = "Disculpe, no se encuentra disponible la cantidad seleccionada.";
     @header('location: carrito.php');
 }
 $tempMaxCompra->storeSum($id_producto, $canTotal);
 try {
     $stock = new TempStock();
     $stock->setTallesColores($id_producto, $pedido, $_SESSION['MM_IdUsuario']);
 } catch (Exception $e) {
     echo $e->getMessage();
 }
 $id_usuario = $_SESSION['MM_IdUsuario'];
 //primero chequeo si el producto ya existe en el carrito del usuario.
 include_once "includes/class.carrito.php";
 // $carr =  new carrito();
 $x = new tallesColores();
 foreach ($pedido as $k => $v) {
     foreach ($v['talle'] as $kt => $vt) {
         if ((int) $vt > 0) {
             if (!$x->productExist($id_usuario, $id_producto, $kt, $k)) {
                 $x->usuario = $id_usuario;
                 $x->producto = $id_producto;
                 $x->color = $k;
                 $x->talle = $kt;
                 $x->cantidad = $vt;
                 $x->insert();
             } else {
                 $x->updateShoppingCartItem($vt, $id_usuario, $id_producto, $kt, $k);
             }
         }
     }