public static function getProduct($id) { $query = "SELECT *, produits.id as id_produit FROM produits\n\t\t\t\t\tLEFT JOIN images on produits.id=images.id_produit\n\t\t\t\t\tWHERE produits.id=" . $id . " AND deleted=0"; if ($products = DBOperation::getAll($query)) { $result = null; foreach ($products as $product) { if (!isset($result)) { $result = new Product($product["id_produit"], $product["nom"], $product["description"], $product["prix"]); } $result->setImage($product["link"]); } return $result; } return false; }
/** * Convert a product array into a product object. * * @param array $aProduct product. * * @return Product converted product. */ private static function convertToObject($aProduct) { $oProduct = new Product(); $oProduct->setId(intval($aProduct['id'])); $oProduct->setName($aProduct['name']); $oProduct->setDescription($aProduct['description']); $oProduct->setImage($aProduct['image']); $oProduct->setPrice(floatval($aProduct['price'])); $oProduct->setRating(intval($aProduct['rating'])); $oProduct->setActive(intval($aProduct['active'])); $aCategories = CategoryManager::getFromProductId($oProduct->getId()); foreach ($aCategories as $oCategory) { $oProduct->addCategory($oCategory); } return $oProduct; }