J'ai un problème lorsque j'ajoute des produits au panier, mais quand je veux aller chercher le contenu du panier, je le trouve vide.Ajouter et montrer la liste des produits dans le panier codeigniter
ceci est mon contrôleur:
public function add_to_cart(){
$insert_data = array(
'id' => $this->input->post('id'),
'name' => $this->input->post('name'),
'price' => $this->input->post('price'),
'qty' => $this->input->post('qty'));
// This function add items into cart.
$this->cart->insert($insert_data);
}
et ceci est ma forme d'ajouter un nouveau produit au panier:
<div class="button-group">
<form method="POST" action="<?php echo base_url().'add_to_cart'; ?>">
<div style="display:none">
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash();?>" />
</div>
<input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
<input type="number" name="qty" id="<?php echo $ligneBase->id;?>">
<input type="hidden" name="name" value="<?php echo $ligneBase->name;?>">
<input type="hidden" name="price" value="<?php echo $ligneBase->price;?>">
<input type="hidden" name="id" value="<?php echo $ligneBase->id;?>">
<input class="add_cart" type="submit" value="Add to cart">
<div class="add-to-links">
</form>
</div>
et ceci est mon panier en header.php:
<table class="table">
<tbody>
<div id="text">
<?php $cart_check = $this->cart->contents();
// If cart is empty, this will show below message.
if(empty($cart_check)) {
echo '<h4 align="center">No Product in cart, To add products to your shopping cart click on "Add to Cart" Button</h4>';
} ?>
</div>
<?php
$cart = $this->cart->contents();
foreach($cart as $indice => $ligneBase){
?>
<tr>
<td class="text-center"><a href="product.html"><img class="img-thumbnail" title="Xitefun Causal Wear Fancy Shoes" alt="Xitefun Causal Wear Fancy Shoes" src="image/product/sony_vaio_1-50x50.jpg"></a></td>
<td class="text-left"><a href="product.html"><?php echo $ligneBase->id;?></a></td>
<td class="text-right">x 1</td>
<td class="text-right"><?php echo $ligneBase->name;?> </td>
<td class="text-center"><button class="btn btn-danger btn-xs remove" title="Remove" onClick="" type="button"><i class="fa fa-times"></i></button></td>
</tr>
<?php
}
?>
</tbody>
</table>
Est-ce que cette ligne retourne une rowid lorsque vous insérez $ this-> Cart-> insert (insert_data de $); – shantanu
Assez sûr que la bibliothèque 'cart' a été supprimée dans les versions récentes de CI - Juste un avertissement! – MackieeE