diff --git a/src/Controllers/CatalogController.php b/src/Controllers/CatalogController.php index a77f95d..f4af8af 100644 --- a/src/Controllers/CatalogController.php +++ b/src/Controllers/CatalogController.php @@ -79,7 +79,7 @@ public function catalogAction(string $tagName, $pageNumber): string 'productTitle' => $productTitle, 'activeBrands' => $activeBrands, 'sortBy' => $sortBy, - 'wishList' => $wishList + 'wishList' => $wishList ?? [], ]; return $this->render('catalog', $params); diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index 43c099e..6385763 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -7,6 +7,7 @@ use Core\Http\Request; use Exception; use Up\Services\Repository\OrderService; +use Up\Services\Repository\ProductService; use Up\Services\Repository\UserService; class UserController extends BaseController @@ -21,18 +22,21 @@ public function userAction(): string|null { $user = UserService::getUserByEmail($_SESSION['UserEmail']); $orders = OrderService::getOrderList($_SESSION['UserEmail']); + $wishesProducts = ProductService::getProductsByIds($_SESSION['wishList']); $params = [ 'userEmail' => $user->email, 'user' => $user, 'userFullName' => $user->name . ' ' . $user->surname, 'orders' => $orders, + 'wishesProducts' => $wishesProducts, ]; return $this->render('account', $params); } header('Location: /login/'); + return null; } diff --git a/src/Services/Repository/ProductService.php b/src/Services/Repository/ProductService.php index a461a0d..3ea53c1 100644 --- a/src/Services/Repository/ProductService.php +++ b/src/Services/Repository/ProductService.php @@ -38,11 +38,11 @@ public static function getProductList( . "INNER JOIN IMAGE " . "ON PRODUCT.ID = IMAGE.PRODUCT_ID " . "WHERE IS_COVER=? $brandCondition" - ." AND PRODUCT.ENTITY_STATUS_ID=? " + . " AND PRODUCT.ENTITY_STATUS_ID=? " . $sortString . " LIMIT ? OFFSET ? "; - $params = [1,1, 10, $offset]; + $params = [1, 1, 10, $offset]; } else { @@ -53,11 +53,11 @@ public static function getProductList( . "ON PRODUCT.ID = PRODUCT_TAG.PRODUCT_ID " . "INNER JOIN TAG ON PRODUCT_TAG.TAG_ID = TAG.ID " . "WHERE IS_COVER=? AND TAG.TITLE=? $brandCondition " - ." AND PRODUCT.ENTITY_STATUS_ID=? " + . " AND PRODUCT.ENTITY_STATUS_ID=? " . $sortString . " LIMIT ? OFFSET ? "; - $params = [1, $category,1, 10, $offset]; + $params = [1, $category, 1, 10, $offset]; } $result = SafeQueryBuilder::Select($query, $params); @@ -132,7 +132,7 @@ public static function getProductListForAdmin(int $pageNumber): array $result = SafeQueryBuilder::Select($query, [$isCover, $limit, $offset]); - return self::fetchProductsFromResult($result, true, true, true,true); + return self::fetchProductsFromResult($result, true, true, true, true); } /** @@ -202,11 +202,11 @@ public static function getProductsByTitle( . "INNER JOIN IMAGE " . "ON PRODUCT.ID=IMAGE.PRODUCT_ID " . "WHERE TITLE LIKE ? AND IS_COVER=? $brandCondition" - ." AND PRODUCT.ENTITY_STATUS_ID=? " + . " AND PRODUCT.ENTITY_STATUS_ID=? " . $sortString . " LIMIT ? OFFSET ? "; - $params = ["%$productTitle%", 1,1, 10, $offset]; + $params = ["%$productTitle%", 1, 1, 10, $offset]; } else { @@ -218,7 +218,7 @@ public static function getProductsByTitle( . "INNER JOIN TAG ON PRODUCT_TAG.TAG_ID = TAG.ID " . "WHERE PRODUCT.TITLE LIKE ? AND IS_COVER=? " . "AND TAG.TITLE=? $brandCondition " - ." AND PRODUCT.ENTITY_STATUS_ID=? " + . " AND PRODUCT.ENTITY_STATUS_ID=? " . $sortString . " LIMIT ? OFFSET ? "; @@ -233,12 +233,13 @@ public static function getProductsByTitle( /** * @throws Exception */ - public static function updateProductByID(int $id, - string $title, - float $price, - string $description, - int $brandId, - array $tags + public static function updateProductByID( + int $id, + string $title, + float $price, + string $description, + int $brandId, + array $tags ): bool { $table = 'PRODUCT'; @@ -267,6 +268,7 @@ public static function updateProductByID(int $id, } } FileCache::delete('products'); + return SafeQueryBuilder::Update($table, $data, $condition, $params); } @@ -308,11 +310,11 @@ public static function getNewProducts(): array . " FROM PRODUCT INNER JOIN IMAGE" . " ON PRODUCT.ID = IMAGE.PRODUCT_ID" . " WHERE IS_COVER=?" - ." AND PRODUCT.ENTITY_STATUS_ID=? " + . " AND PRODUCT.ENTITY_STATUS_ID=? " . " ORDER BY DATE_RELEASE DESC" . " LIMIT ?"; - $params = [1, 1,5]; + $params = [1, 1, 5]; $result = SafeQueryBuilder::Select($query, $params); @@ -331,6 +333,7 @@ public static function updateProductStatus(int $id, int $statusId): bool $condition = '`ID` = ?'; $params = [$id]; FileCache::delete('products'); + return SafeQueryBuilder::Update($table, $data, $condition, $params); } @@ -354,7 +357,7 @@ private static function fetchProductsFromResult( bool $includeDescription = false, bool $includeBrand = false, bool $includeTags = false, - bool $includeStatus=false + bool $includeStatus = false ): array { $products = []; @@ -394,4 +397,26 @@ private static function fetchProductsFromResult( return $products; } + + /** + * @throws Exception + */ + public static function getProductsByIds(?array $ids): array + { + if ($ids !== []) + { + $placeholder = "(" . implode(",", $ids) . ")"; + + $query = "SELECT PRODUCT.ID, TITLE, PRICE, PATH FROM PRODUCT " + . "INNER JOIN IMAGE " + . "ON PRODUCT.ID = IMAGE.PRODUCT_ID " + . "WHERE PRODUCT.ID IN $placeholder"; + + $result = SafeQueryBuilder::Select($query); + + return self::fetchProductsFromResult($result); + } + + return []; + } } \ No newline at end of file diff --git a/src/Views/default/components/account-wishes.php b/src/Views/default/components/account-wishes.php index 0874ef7..6c1ef90 100644 --- a/src/Views/default/components/account-wishes.php +++ b/src/Views/default/components/account-wishes.php @@ -1,22 +1,26 @@
See your favorites list here
- APPLE iPad Pro 11” M2 Chip (4th Generation) Wi-Fi 128GB Silver
+=$wishesProduct->getTitle()?>