File manager - Edit - /home/webapp69.cm.in.th/u69319090039/Shop39/app/Controllers/WishlistController.php
Back
<?php class WishlistController extends Controller { public function toggle(): void { $this->validateCsrf(); $user = Auth::user(); $productId = (int)($_POST['product_id'] ?? 0); $db = Database::getInstance(); $stmt = $db->prepare("SELECT * FROM wishlists WHERE user_id = :uid AND product_id = :pid"); $stmt->execute(['uid' => $user['id'], 'pid' => $productId]); $existing = $stmt->fetch(); if ($existing) { $del = $db->prepare("DELETE FROM wishlists WHERE id = :id"); $del->execute(['id' => $existing['id']]); $added = false; Session::setFlash('info', 'นำสินค้าออกจากรายการที่ชอบแล้ว'); } else { $ins = $db->prepare("INSERT INTO wishlists (user_id, product_id) VALUES (:uid, :pid)"); $ins->execute(['uid' => $user['id'], 'pid' => $productId]); $added = true; Session::setFlash('success', 'เพิ่มสินค้าในรายการที่ชอบเรียบร้อยแล้ว'); } if ($this->isAjax()) { $this->json(['status' => 'success', 'added' => $added]); } else { $this->redirect('wishlist'); } } public function index(): void { $user = Auth::user(); $db = Database::getInstance(); $sql = "SELECT p.*, c.name AS category_name, sp.shop_name, w.id AS wishlist_id FROM wishlists w JOIN products p ON w.product_id = p.id JOIN categories c ON p.category_id = c.id JOIN seller_profiles sp ON p.seller_id = sp.id WHERE w.user_id = :uid ORDER BY w.id DESC"; $stmt = $db->prepare($sql); $stmt->execute(['uid' => $user['id']]); $products = $stmt->fetchAll(); $this->render('wishlist/index', [ 'title' => 'รายการสินค้าที่ชอบ', 'products' => $products ]); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.22 |
proxy
|
phpinfo
|
Settings