/** * Requête AJAX pour trouver le nombre de BD * dans le panier actuel de l'utilisateur */ public function ajaxMainCountBooksInCart() { $this->lock(); $user = $this->getUser(); $userId = $user['id']; $cartManager = new CartManager(); $cartId = $cartManager->findCart($userId); if (empty($cartId)) { die('0'); } // $remainingTime = $cartManager->findCartDelay($cartId); // if($remainingTime < 0){ // // Augmenter la quantité disponible des livres ... // // ... en récupérant les livres du panier ... // $booksIds = $cartManager->findAllBooksIdsInCart($cartId); // // ... pour ajouter un à la quantité disponible // $bookManager = new BookManager(); // foreach ($booksIds as $bookId) { // $bookManager->increaseQuantityAvailable($bookId['book_id']); // } // // Une fois les lignes du cart_to_books détruites, détruire le cart en cours // if ($cartManager->removeBooks($cartId)) { // if ($cartManager->removeCart($cartId)) { // } // } // die('0'); // } $cartBookManager = new CartBookManager(); $number = $cartBookManager->countBooksInCart($cartId); die($number); }
public function AddbooktoCart($book_id) { $books = ""; $cm = new \Manager\CartManager(); $cbm = new \Manager\Book_cartManager(); $user = $this->getUser(); $user_id = $user['id']; $cart_id = $cm->findCart($user_id); if (empty($cart_id)) { $cart_id = $cm->AddbooktoCart($user_id); } $cbm->AddbooktoCart($cart_id, $book_id); $this->redirectToRoute('catalogue'); }
public function returnOrder() { $cartManager = new CartManager(); $bookManager = new BookManager(); $userManager = new UserManager(); $cartId = ""; $books = ""; if (!empty($_POST)) { $cartId = trim(strip_tags($_POST['cartId'])); // Retrouver la commande correspondante $booksIds = $cartManager->findAllBooksIdsInCart($cartId); $books = $bookManager->showBooks($booksIds); // Récupérer l'id de l'utilisateur $userId = $cartManager->getUserIdByCart($cartId); $user = $userManager->find($userId); $data = ['books' => $books, 'user' => $user]; $this->show('admin/confirm_order_return', $data); } else { $this->show('admin/confirm_order_return'); } }
/** * Requête AJAX pour trouver les informations sur la BD * à faire apparaître dans la fenêtre modale */ public function ajaxCatalogDetail() { $bookId = $_GET['id']; $bookManager = new BookManager(); $book = $bookManager->extendedFind($bookId); $cartManager = new CartManager(); // Récupère le panier de l'utilisateur $cartId = $cartManager->findCart($this->getUser()['id']); // Récupère les id des livres qui sont déjà dans le panier $booksInCartIds = []; if (!empty($cartId)) { $booksInCartIds = $cartManager->findAllBooksIdsInCart($cartId); } $bookInCartIds = []; foreach ($booksInCartIds as $array) { $bookInCartIds[] = $array['book_id']; } // Vérifie si les livres affichés dans le catalogue sont dans le panier $isBookInCart = 0; if (in_array($book['id'], $bookInCartIds)) { $isBookInCart = 1; } $book['isBookInCart'] = $isBookInCart; // livres de la meme serie $booksCarousel = $bookManager->bookCarousel($bookId); // titre de la série dont est issue la bd $serieTitle = $bookManager->getSerieTitle($bookId); $numberBooksInSerie = count($booksCarousel); $data = array('book' => $book, 'booksCarousel' => $booksCarousel, 'serieTitle' => $serieTitle, 'numberBooksInSerie' => $numberBooksInSerie); $this->show('book/ajax_catalog_showDetail', $data); }