File manager - Edit - /home/webapp69.cm.in.th/u69319090028/Shop/app/Services/WishlistService.php
Back
<?php /** * WishlistService * Handles user saved items / wishlist management */ require_once __DIR__ . '/../Models/SavedItem.php'; require_once __DIR__ . '/../Models/Product.php'; require_once __DIR__ . '/../Services/CartService.php'; class WishlistService { private SavedItem $savedItemModel; private Product $productModel; private CartService $cartService; public function __construct() { $this->savedItemModel = new SavedItem(); $this->productModel = new Product(); $this->cartService = new CartService(); } public function getWishlist(int $userId): array { return $this->savedItemModel->getUserWishlist($userId); } public function isSaved(int $userId, int $productId): bool { return $this->savedItemModel->isSaved($userId, $productId); } public function toggleWishlist(int $userId, int $productId): array { $product = $this->productModel->findById($productId); if (!$product || $product['status'] !== 'active' || !empty($product['deleted_at'])) { return ['success' => false, 'message' => 'ไม่พบข้อมูลสินค้า']; } $isSaved = $this->savedItemModel->toggle($userId, $productId); return [ 'success' => true, 'is_saved' => $isSaved, 'message' => $isSaved ? 'เพิ่มในรายการโปรดแล้ว' : 'นำออกจากรายการโปรดแล้ว' ]; } public function moveToCart(int $userId, int $productId): array { $cartResult = $this->cartService->addItem($userId, $productId, 1); if (!$cartResult['success']) { return $cartResult; } // Remove from wishlist once moved $this->savedItemModel->remove($userId, $productId); return [ 'success' => true, 'message' => 'ย้ายสินค้าไปยังรถเข็นเรียบร้อยแล้ว' ]; } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.23 |
proxy
|
phpinfo
|
Settings