Décrivez ici votre problème ou ce que vous cherchez à faire.

Ent<?php
require_once('Controleur/Controleur.php');
require_once('Vue/Vue.php');
require_once('core/Autoloader.php');
require_once('Modele/ModelePanier.php');
require_once('Modele/OrderModele.php');
require_once('Modele/Produit.php');
require_once('helpers/session.php');
require_once('helpers/ControleurHeleper.php');

Autoloader::register();

class ControleurPanier implements Controleur
{

         public function __construct(){
           $cartManager = New ModelePanier();
           $orderManager = New OrderManager();

             new Session;
            // $cartManager->model('Cart');
             //$orderManager->model('Order');
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->   index    <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function index(){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             $data['title1'] = 'Cart';
             $cartItems = 0;
             $data['cart'] = $cartManager->getAllCart();
             if($data['cart']){
                 foreach ($data['cart'] as $cart) {
                     $cartItems = $cartItems +  $cart->qty;
                 }
             }else {
                 $cartItems = 0;
             }
             Session::set('user_cart', $cartItems );
             $this->vue('front.cart',$data);
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->   Thank    <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function thank(){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             $data['title1'] = 'Thank You';
             $data['title2'] = 'Transaction Done';
             $this->view('front.thank',$data);
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->   orders    <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function orders(){
             Auth::userAuth();
             $data['title1'] = 'Orders';
             $data['orderDetails'] = $orderManager->getUserOrderDetalails(Session::name('user_id'));
             $this->view('front.orders',$data);
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<---> add to cart<--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function add($pro_id,$price){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             $user_id = Session::name('userID');
             if($$cartManager->findCartPro($pro_id,$user_id) > 0){
                 $cartManager->addOne($pro_id,$user_id);
                 Redirect::to('carts');
             }else{
                 $cartManager->addnew($pro_id,$user_id,$price);
                 Redirect::to('carts');
             }
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<---> update Qty <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function updateQty($id){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             Csrf::CsrfToken();
             if($_SERVER['REQUEST_METHOD']=='POST' && $_POST['upQty']){
                 $qty = $_POST['qty'];

                 if ($qty < 1 && empty($qty)) {
                     Redirect::to('carts');
                 }else {
                     $cartManager->updateQty($id,$qty);
                     Session::set('success', 'Qty has been updated');
                     Redirect::to('carts');
                 }
             }
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->   delete   <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function delete($id){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             Csrf::CsrfToken();
             Session::set('success', 'Item has been deleted');
             $delete = $cartManager->delete($id);
             if($delete){
                 Redirect::to('carts');
             }
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->   delete   <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function clear(){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             Csrf::CsrfToken();
             Session::set('success', 'All Item has been deleted');
             $delete =  $cartManager->clear();
             if($delete){
                 Redirect::to('carts');
             }
         }

         /*>>>>>>>>>>>>>>>>>>>>*/
         #<--->  checkout  <--->#
         /*<<<<<<<<<<<<<<<<<<<<*/
         public function checkout(){
           $cartManager = New ModelePanier();
           $orderManager = New OrderModele();
             Auth::userAuth();
             Csrf::CsrfToken();
             if($_SERVER['REQUEST_METHOD']=='POST'){

                 require_once('../vendor/autoload.php');
                 \Stripe\Stripe::setApiKey('sk_test_dRGPlCrOt3QXSuOxSwhvT5cZ00xTVDsc19');

                 $POST = filter_var_array($_POST, FILTER_SANITIZE_STRING);
                 $name = $_POST['name'];
                 $email = $_POST['email'];
                 $mobile = $_POST['mobile'];
                 $address = $_POST['address'];
                 $city = $_POST['city'];
                 $total = $_POST['total'];
                 $qty = $_POST['qty'];

                 if(empty($_POST['payment_method'])){
                     $data['errMethod'] = 'You must choose payment method';
                 }
                 if (strlen($name) < 4) {
                 $data['errName'] = 'Name must not be less than 4 characters';
                 }
                 if (empty($email)) {
                     $data['errEmail'] = 'Email Must Has Value.';
                 }elseif (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
                     $data['errEmail'] = 'Enter Valid Email';
                 }

                 if (strlen($mobile) < 11) {
                     $data['errMobile'] = 'Name must not be less than 11 characters';
                 }

                 if (empty($address)) {
                     $data['errAddress'] = 'Address Must Has Value.';
                 }
                 if (empty($city)) {
                     $data['errCity'] = 'City Must Has Value.';
                 }

                 if(empty($data['errName']) && empty($data['errEmail'])
                     && empty($data['errMobile']) && empty($data['errAddress'])
                     && empty($data['errCity']) && empty($data['errMethod'])){

                     if($_POST['payment_method'] == 'stripe' ){
                         $token = $_POST['stripeToken'];
                         $customer = \Stripe\Customer::create(array(
                             'email' => $email,
                             'source'=>$token
                         ));

                         $charge = \Stripe\Charge::create([
                         'amount' => $qty * 100,
                         'currency' => 'usd',
                         'description' => 'Transaction vers Jc Platon',
                         'customer' => $customer->id
                         ]);

                     }

                     $shipping_id= $orderManager->addToShipping($name,$email,$mobile,$address,$city);
                     Session::set('shipping_id', $shipping_id);

                     //complete order
                     $payment_id= $orderManager->addToPayment($_POST['payment_method'],$shipping_id);

                     $order_id = $orderManager->addToOrder(
                         Session::name('userID'),$shipping_id,$payment_id
                         ,$total
                     );

                     $data['cart'] = $cartManager->getAllCart();
                     foreach ($data['cart'] as $cart) {
                         $this->orderModel->addToOrderDetails(
                             $order_id,$cart->product,$cart->pro_name,
                             $cart->price ,$cart->qty,Session::name('userID')
                         );
                     }

                     $this->cartModel->clear();
                     Session::set('user_cart', '0');
                     Redirect::to("carts/thank");

                 }else {
                     $data['cart'] = $this->cartModel->getAllCart();
                     $this->view('front.cart', $data);
                 }
             }else {
                 Redirect::to('carts');
             }
         }

  //______________________________________________________________________________________
  /**
   *  Affiche la vue de la page
   */
   public function getHTML()
  {
      $vue = new Vue("Panier");
      $vue->generer(array());

  }
}

Bonjour je suis novice sur php et j'aimerai finalier mon projet.
Je suis une architecture mvc en php, poo pour monter mon app mini site commerce en ligne, je suis actuellement bloqué sur la partie qui consite à créer un panier.
Je sollicite votre aide pour pouvoir décanter cette problématique.
Est-ce que quelqu'un peu m'aider?
Merci d'avence !
ourez votre code en utilisant "```" pour bien le mettre en forme. (ne copiez pas trop de code)

Ce que je veux

Décrivez ce que vous cherchez à obtenir.

Ce que j'obtiens

Décrivez vos éventuelles erreurs ou ce que vous obtenez à la place de ce que vous attendez :(

4 réponses


Bonsoir,

c'est quoi exactement ton problème ?

Il fait beaucoup de chose ton controller...

bonjour ,
merci pour votre réponse.
effectivement, je sollicite l´aide de copains car je suis bloqué.
mon but est de créer un panier virtuel .

sauf que mes variables sont en mode undefine sur la partie vue.
je sais que il ya un moyen de forcer mais je suis un simple novice

c´est pourquoi je sollicite l´aide de copains merci beaucoup d´avance