Tuesday, February 8, 2022

[FIXED] Wrong amount of product with codeigniter

Issue

My query is oriented to experts Codeigniter . I am making a purchasing system and have the following problem , adding products of different pages or rather to add products from different pages within my solution performs poorly sums .

My code

public function comprar($id, $titulo, $numRifa){            
        $this->load->model('rifasDB');
        $fila = $this->rifasDB->rifasDetalladaDB($id, $titulo);
        $idRifa = $numRifa;
        $nombreRifa = $numRifa;
        $precioRifa = $fila->precio;
        $insert = array( 
                 array('id' => $idRifa,
                        'qty' => 1, 
                        'price' => $precioRifa, 
                        'name' => $nombreRifa));

            $this->cart->insert($insert);
            // $datosRifas = array('idNumRifa' => $idRifa, 'idTitulo' => $id);      
            // $this->session->set_userdata($datosRifas);
            header("Location:". base_url() ."Rifas/rifasDetalladas/". $id ."/". $titulo);

    }

My view

 <li><a href=""?><i class="glyphicon glyphicon-shopping-cart"></i> <?php echo $this->cart->format_number($this->cart->total())?></a></li>

My Loops prints numbers

<?php while($numerosRifas <= $numRifas ){?>
            <?php $numerosRifas++?>
        <div class="col-md-3 img-portfolio">
            <!-- <a href="portfolio-item.html"> -->
            <div style="text-align:center; border:solid 22px;">
               <span style="font-weight:800; font-size:100px; text-align:center;"><?php echo $numerosRifas;?></span>
            </div> 
            <?php if($this->session->userdata('idNumRifa') == $numerosRifas && $this->session->userdata('idTitulo') == $id){?>
               <input type="button" value="COMPRAR <?php echo $numerosRifas;?>" <?php if ($pageId !== 1) echo 'disabled="disabled"' ?> />
            <?php }else{?>
                <?php if($this->session->userdata('login')){?>
                 <a href="<?= base_url()?>Rifas/comprar/<?= $id ?>/<?= $nomRifa ?>/<?= $numerosRifas?>"><input type="button" value="COMPRAR <?php echo $numerosRifas;?>" <?php if ($pageId !== 1) echo 'disabled="enabled"' ?> /></a>
                 <?php }else{?>
                    <a href="<?= base_url()?>Login"><input type="button" value="COMPRAR <?php echo $numerosRifas;?>" <?php if ($pageId !== 1) echo 'disabled="enabled"' ?> /></a>
                <?php }?>
            <?php }?>
            <!-- </a> -->
        </div>
    <?php }?> 

I appreciate all kinds of help you can give me orienting in which the error can be


Solution

Please read the docx

The Cart class utilizes CodeIgniter’s Session Class to save the cart information to a database, so before using the Cart class you must set up a database table as indicated in the Session Documentation, and set the session preferences in your application/config/config.php file to utilize a database.

codeigniter cart



Answered By - Pradeep

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.