1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
/**
* Get Wishlists information by $userId.
*
* @param int $userId user session Id.
* @return array Result of fetch.
*/
function getWishlist($userId): array
{
try {
$db = createConnection();
$sql = 'SELECT * FROM wishlist w
LEFT JOIN wishitems wi ON wi.wishlistID = w.wishlistID
LEFT JOIN products p ON wi.product_id = p.product_id
LEFT JOIN images i ON p.product_id = i.product_id
WHERE wi.user_id = :userId AND w.status = "1" AND imgPrimary = 1
AND i.imgPath LIKE "%-tn%" AND wi.status = "1"
ORDER BY w.wishlistID, w.date_created, wi.wishitemID DESC';
$stmt = $db->prepare($sql);
$stmt->bindValue(':userId', $userId, PDO::PARAM_INT);
$stmt->execute();
$wishlists = $stmt->fetchAll();
$stmt->closeCursor();
return $wishlists;
} catch (PDOException $e) {
exit($e->getMessage()) ;
return [];
}
} |
Partager