/**
  * Fonction permettant de confirmer le panier et de créer un billet de commande
  */
 public function confirmPanier()
 {
     if (sizeof($_SESSION['panier']['id_article'] > 0)) {
         $model_panier = new Model_Panier();
         $precision = ' WHERE id_article IN(' . $_SESSION['panier']['id_article'][0] . ',';
         if (sizeof($_SESSION['panier']['id_article']) > 1) {
             for ($i = 1; $i < sizeof($_SESSION['panier']['id_article']); $i++) {
                 if ($i == sizeof($_SESSION['panier']['id_article']) - 1) {
                     $precision .= $_SESSION['panier']['id_article'][$i];
                 } else {
                     $precision .= $_SESSION['panier']['id_article'][$i] . ',';
                 }
             }
         }
         $precision .= ')';
         $listArticle = $model_panier->listArticlePanier($precision);
         //Update de la quantité d'un article dans la base de donnée
         for ($j = 0; $j < sizeof($_SESSION['panier']['id_article']); $j++) {
             $quantityPanier = intval($_SESSION['panier']['quantite'][$j]);
             $quantityInit = intval($listArticle[$j]['quantite']);
             if ($quantityInit == 0) {
                 $newQuantity = 0;
             } else {
                 $newQuantity = $quantityInit - $quantityPanier;
                 if ($newQuantity < 0) {
                     $newQuantity = 0;
                 }
             }
             $model_panier = new Model_Panier();
             $model_panier->updateQuantity($newQuantity, $_SESSION['panier']['id_article'][$j]);
         }
         //Création d'un billet de commande
         require_once $_SERVER['DOCUMENT_ROOT'] . 'boutique/models/commande.php';
         $numero_commande = rand(1000, 8000);
         $descriptif = $listArticle[0]['nom'] . ' : ' . $_SESSION['panier']['quantite'][0];
         $prix_commande = $listArticle[0]['prix'] * $_SESSION['panier']['quantite'][0];
         for ($i = 1; $i < sizeof($_SESSION['panier']['id_article']); $i++) {
             $descriptif .= ', ';
             $descriptif .= $listArticle[$i]['nom'] . ' : ' . $_SESSION['panier']['quantite'][$i];
             $prix_commande += $listArticle[$i]['prix'] * $_SESSION['panier']['quantite'][$i];
         }
         $id_users = $_SESSION['id_users'];
         $model_commande = new Model_Commande();
         $model_commande->newBillet($numero_commande, $descriptif, $prix_commande, $id_users);
         //On vide la variable session panier
         unset($_SESSION['panier']);
         $_SESSION['panier'] = array();
         $_SESSION['panier']['id_article'] = array();
         $_SESSION['panier']['quantite'] = array();
     }
 }
示例#2
0
 /**
  * Fonction permettant de faire la view du panier
  */
 public function viewPanier()
 {
     serialize($_SESSION['panier']);
     $ids = array_keys($_SESSION['panier']);
     if (empty($ids)) {
         $products = array();
     } else {
         $products_model = new Model_Panier();
         $products = $products_model->listPanier($ids);
     }
     require_once $_SERVER['DOCUMENT_ROOT'] . "/ecommerce/views/panier/panier.php";
 }
示例#3
0
	<?php 
/**
* Page
*
* SubPage Panier
* 
* @package          Ecommerce
* @subpackage       Views/Panier
* @category          Panier
* @author              Axel Mainguy
*/
require $_SERVER['DOCUMENT_ROOT'] . "ecommerce/controllers/panier.php";
$panier = new Controller_Panier();
$json = array('error' => true);
$id_articles = $_GET['id'];
if (isset($id_articles)) {
    require_once $_SERVER['DOCUMENT_ROOT'] . "ecommerce/models/panier.php";
    $products_model = new Model_Panier();
    $products = $products_model->addPanier($id_articles);
    if (empty($products)) {
        $json['message'] = "Ce produit n'existe pas";
    }
    $panier->add($products[0][$id_articles]);
    $json['error'] = false;
    $json['total'] = number_format($panier->total(), 2, ',', ' ');
    $json['count'] = $this->count();
    $json['message'] = "Le produit a bien été ajouté";
} else {
    $json['message'] = "Vous n'avez pas sélectionné de produit a ajouter";
}
echo json_encode($json);