Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Controllers/CatalogController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Controllers/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}

Expand Down
59 changes: 42 additions & 17 deletions src/Services/Repository/ProductService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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
{
Expand All @@ -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 ? ";

Expand All @@ -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';
Expand Down Expand Up @@ -267,6 +268,7 @@ public static function updateProductByID(int $id,
}
}
FileCache::delete('products');

return SafeQueryBuilder::Update($table, $data, $condition, $params);

}
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}

Expand All @@ -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 = [];
Expand Down Expand Up @@ -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 [];
}
}
18 changes: 11 additions & 7 deletions src/Views/default/components/account-wishes.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<?php
if (isset($_SESSION['wishList']))
{
var_dump($_SESSION['wishList']);
}
/**
* @var $wishesProducts
*/
?>
<div class="title__container user__titleContainer">
<h1 class="account__title">Your Wish List</h1>
<p class="account__subtitle">See your favorites list here</p>
</div>
<ul class="account__wishList">
<?php foreach($wishesProducts as $wishesProduct):?>
<li class="account__wishItem">
<img src="/assets/images/productImages/1.jpg" alt="product Image" class="account__wishImg">
<p class="account__wishName">APPLE iPad Pro 11” M2 Chip (4th Generation) Wi-Fi 128GB Silver</p>
<img src="/assets/images/productImages/<?=$wishesProduct->getCover()->getPath()?>"alt="product Image" class="account__wishImg">
<p class="account__wishName"><?=$wishesProduct->getTitle()?></p>
<div class="account__wishFooter">
<a href="" class="account__wishBuy">Buy now</a>
<a href="/order/<?=$wishesProduct->getID()?>/" class="account__wishBuy">Buy now</a>
<div class="product__footer_container">
<p class="product__cost"><?=$wishesProduct->getPrice()?>$</p>
</div>
<button class="account__wishDelete">
<img src="/assets/images/common/bin.svg" alt="delete product from wish list" class="deleteImg">
</button>
</div>
</li>
<?php endforeach;?>
</ul>
3 changes: 2 additions & 1 deletion src/Views/default/pages/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @var \Up\Models\User $user
* @var \Up\Models\Order $orders
* @var $warning
* @var \Up\Models\Product[] $wishesProducts
*/
?>
<div class="navbar">
Expand Down Expand Up @@ -78,7 +79,7 @@ class="account__img">
<?= $this->renderComponent('account-orders', ['orders' => $orders]) ?>
</main>
<main class="account__main" id="accountWishListContainer" data-user-cont="2">
<?= $this->renderComponent('account-wishes', []) ?>
<?= $this->renderComponent('account-wishes', ['wishesProducts' =>$wishesProducts]) ?>
</main>
</div>
<?= $this->renderComponent('account-modals', ['user' => $user]) ?>
Expand Down