/** * Enregistre la commande finalisée du client * * @param Commande $uneCommande * @throws ErrorSQLException */ public static function ajouterCommande(Commande $uneCommande) { try { $conn = MConnexion::getBdd(); $conn->beginTransaction(); $reqPrepare = $conn->prepare('INSERT INTO commande (numClt,date,pointsUtilise) VALUES (?,?,?)'); $reqPrepare->execute([$uneCommande->getUnClient()->getId(), $uneCommande->getUneDate(), $uneCommande->getPointsUtilise()]); $conn->commit(); $conn = null; } catch (PDOException $ex) { $conn->rollBack(); throw new ErrorSQLException('Impossible de continuer la validation de la commande. Détails : ' . $ex->getMessage()); } }
/** * Récupère les articles d'un commande via la commande. * * @param Commande $uneCommande numéro d'une commande * @param bool $index * * @return Collection * * @throws CollectionException * @throws ErrorSQLException */ public static function getUneCommande(Commande $uneCommande, $index = false) { $lesArticles = new Collection(); try { $conn = MConnexion::getBdd(); $conn->beginTransaction(); $req = !$index ? $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC') : $conn->prepare('SELECT * FROM commander INNER JOIN article ON commander.numArt = article.numArt WHERE numCde = ? ORDER BY pu DESC LIMIT 2'); $req->execute(array($uneCommande->getId())); $req = $req->fetchAll(); foreach ($req as $tabs) { $unArticle = MArticle::getArticle($tabs['numArt']); $unArticle->setQte($tabs['qte']); $lesArticles->ajouter($unArticle); } $conn->commit(); } catch (PDOException $e) { throw new ErrorSQLException('Impossible de récupérer la commande n°' . $uneCommande->getId() . ' Détails : ' . $e->getMessage()); } return $lesArticles; }
public function testGetMontantTotal() { $this->assertEquals(6575, $this->commande->getMontantTotal()); }