Файловый менеджер - Редактировать - /home/skymarketplace/public_html/controllers/CartController.php
Назад
<?php namespace App\Controllers; use App\models\CartModel; use App\core\JsonResponse; class CartController { protected CartModel $cartModel; public function __construct(CartModel $cartModel = null) { $this->cartModel = $cartModel ?? new CartModel(); } public function addToCart($userId, $data): void { if (!isset($data['product_id'], $data['quantity'])) { JsonResponse::send(['error' => 'Missing required fields'], 400); return; } $success = $this->cartModel->add($userId, $data['product_id'], $data['quantity']); if ($success) { JsonResponse::send(['success' => 'Product added to cart']); } else { JsonResponse::send(['error' => 'Failed to add to cart'], 500); } } public function removeFromCart($userId, $itemId): void { $success = $this->cartModel->remove($userId, $itemId); if ($success) { JsonResponse::send(['success' => 'Item removed from cart']); } else { JsonResponse::send(['error' => 'Failed to remove item'], 500); } } public function getCart($userId): void { $items = $this->cartModel->getItems($userId); JsonResponse::send(['cart' => $items]); } public function clearCart($userId): void { $this->cartModel->clear($userId); JsonResponse::send(['success' => 'Cart cleared']); } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.31 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка