<?php
session_start();
include('../conexion.php');
include('../include/sesiones.php');
if (isset($_SESSION['carrito'])) {
    $carrito_mio = $_SESSION['carrito'];
    $total = 0;
    for ($i = 0; $i <= count($carrito_mio) - 1; $i++) {
        if (isset($carrito_mio[$i])) {
            if ($carrito_mio[$i] != NULL) {
                if (isset($carrito_mio[$i]['atributo1'])) {
                    $atributo1 = $carrito_mio[$i]['atributo1'];
                } else {
                    $atributo1 = 0;
                }
                if (isset($carrito_mio[$i]['atributo2'])) {
                    $atributo2 = $carrito_mio[$i]['atributo2'];
                } else {
                    $atributo2 = 0;
                }

                $art_art_id = $carrito_mio[$i]['art_art_id'];

                $centra = mysqli_query($con, "SELECT * FROM articulos_has_bodegas WHERE art_id='$art_art_id' AND atributo1='$atributo1'
                 AND atributo2='$atributo2' ")
                    or die(mysqli_error($con));
                while ($cero2 = mysqli_fetch_array($centra)) {
                    $articulos_art_id = $cero2["articulos_art_id"];

                    $centrar5 = mysqli_query($con, "SELECT * FROM articulos where art_id='$articulos_art_id' and empresa='$emp_id' ")
                        or die(mysqli_error($con));
                    while ($cero5 = mysqli_fetch_array($centrar5)) {

                        $art_id = ($cero5['art_id']);
                        $art_pvp = ($cero5['art_pvp']);
                        $art_nombre_online = ($cero5['art_nombre_online']);

                        $art_promo_desc = $cero5['art_promo_desc'];

                        $nombre_archivo = '../../img/articulos/' . $art_id . '.jpg';
?>
                        <div class="cart_item">
                            <div class="cart_img">
                                <a href="cart.php">
                                    <?php
                                    if (file_exists($nombre_archivo)) { ?>
                                        <img src="<?php echo $emp_url_sub; ?>/img/articulos/<?php echo $art_id; ?>.jpg" alt="">
                                    <?php } else { ?>
                                        <img src="<?php echo $emp_url_sub; ?>/img/articulos/sin_imagen.jpg" alt="#">
                                    <?php   }
                                    ?></a>
                            </div>
                            <div class="cart_info">
                                <a href="articulos_detalles.php?art_id=<?php echo $art_id; ?>"><?php echo substr($art_nombre_online, 0, 20); ?></a>
                                <span class="quantity">Cantidad:<?php echo $carrito_mio[$i]['cantidad']; ?></span>


                                <?php include("funcion_precio_cart.php") ?>
                            <?php
                        } ?>
                            </div>
                        </div>
    <?php

                    $precio_base =  ($art_promo_desc != 0) ? $total_desc : $precio_promo;
                    $total += $carrito_mio[$i]['cantidad'] * $precio_base;
                    $total_cantidades;
                }
            }
        }
    }
}

    ?>

    <div class="mini_cart_table">
        <div class="cart_total">
            <span>Total:</span>
            <span class="price">
                <strong style="text-align: left; color: #000000;">



                    <?php
                    if (isset($_SESSION['carrito'])) {

                        echo '$ ' . number_format($total, 0, ",", ".");
                    } else {
                        echo '0';
                    }
                    ?>
                </strong>
            </span>
        </div>
    </div>