Fix product price not showing

This commit is contained in:
grandeljay 2022-06-13 12:12:44 +02:00
parent 6810685aa8
commit efecc951a1
3 changed files with 41 additions and 25 deletions

View file

@ -20,17 +20,7 @@ require '../../index.php';
switch ($_SERVER['REQUEST_METHOD']) {
case 'GET':
if (isset($_GET['wish_id'])) {
$columns = $database
->query(
'SELECT `wishes`.*,
`products`.`price`
FROM `wishes`
LEFT JOIN `products` ON `wishes`.`id` = `products`.`wish`
WHERE `wishes`.`id` = ' . $_GET['wish_id'] . ';'
)
->fetch();
$wish = new Wish($columns, true);
$wish = new Wish($_GET['wish_id'], true);
$response['info'] = $wish;

View file

@ -13,6 +13,11 @@ class Wish
/**
* Static
*/
public const SELECT = '`wishes`.*, `products`.`price`';
public const FROM = '`wishes`';
public const LEFT_JOIN = '`products` ON `wishes`.`id` = `products`.`wish`';
public const WHERE = '`wishes`.`id` = %d;';
public const NO_IMAGE = '/src/assets/img/no-image.svg';
public const STATUS_TEMPORARY = 'temporary';
@ -45,6 +50,7 @@ class Wish
*/
private Cache\Embed $cache;
/** General */
public int $id;
public int $wishlist;
public ?string $title;
@ -53,9 +59,12 @@ class Wish
public ?string $url;
public ?int $priority;
public bool $is_purchasable;
public ?string $status;
/** Product */
public ?float $price;
/** Other */
public \stdClass $info;
public bool $exists = false;
@ -68,9 +77,12 @@ class Wish
if (is_numeric($wish)) {
$wish = $database
->query('SELECT *
FROM `wishes`
WHERE `id` = ' . $wish . ';')
->query(
'SELECT ' . self::SELECT . '
FROM ' . self::FROM . '
LEFT JOIN ' . self::LEFT_JOIN . '
WHERE ' . sprintf(self::WHERE, $_GET['wish_id'])
)
->fetch();
$columns = $wish;
@ -108,11 +120,17 @@ class Wish
{
ob_start();
$userCard = new User($ofUser);
$numberFormatter = new \NumberFormatter(
$userCard->locale,
\NumberFormatter::CURRENCY
);
$userIsCurrent = isset($_SESSION['user']['id']) && intval($_SESSION['user']['id']) === $userCard->id;
/**
* Card
*/
$userIsCurrent = isset($_SESSION['user']['id']) && intval($_SESSION['user']['id']) === $ofUser;
if ($this->url) {
$generateCache = $this->cache->generateCache() || !$this->url ? 'true' : 'false';
} else {
@ -178,6 +196,10 @@ class Wish
</div>
<?php } ?>
<div class="meta">
<span class="date"><?= $numberFormatter->format($this->price ?? 0) ?></span>
</div>
<?php if ($this->description) { ?>
<div class="description">
<?= $this->description ?>

View file

@ -56,18 +56,22 @@ class Wishlist
{
global $database;
$SELECT = isset($sql['SELECT']) ? $sql['SELECT'] : '*';
$FROM = isset($sql['FROM']) ? $sql['FROM'] : '`wishes`';
$WHERE = isset($sql['WHERE']) ? $sql['WHERE'] : '`wishlist` = ' . $this->id;
$ORDER_BY = isset($sql['ORDER_BY']) ? $sql['ORDER_BY'] : '`priority` DESC, `title` ASC, `url` ASC';
$SELECT = isset($sql['SELECT']) ? $sql['SELECT'] : Wish::SELECT;
$FROM = isset($sql['FROM']) ? $sql['FROM'] : Wish::FROM;
$LEFT_JOIN = isset($sql['LEFT_JOIN']) ? $sql['LEFT_JOIN'] : Wish::LEFT_JOIN;
$WHERE = isset($sql['WHERE']) ? $sql['WHERE'] : '`wishlist` = ' . $this->id;
$ORDER_BY = isset($sql['ORDER_BY']) ? $sql['ORDER_BY'] : '`priority` DESC, `title` ASC, `url` ASC';
$WHERE .= ' AND (`status` != "' . Wish::STATUS_FULFILLED . '" OR `status` IS NULL)';
$this->wishes = $database
->query('SELECT ' . $SELECT . '
FROM ' . $FROM . '
WHERE ' . $WHERE . '
ORDER BY ' . $ORDER_BY . ';')
->query(
'SELECT ' . $SELECT . '
FROM ' . $FROM . '
LEFT JOIN ' . $LEFT_JOIN . '
WHERE ' . $WHERE . '
ORDER BY ' . $ORDER_BY . ';'
)
->fetchAll();
foreach ($this->wishes as &$wish) {