Fix product price not showing
This commit is contained in:
parent
6810685aa8
commit
efecc951a1
3 changed files with 41 additions and 25 deletions
|
@ -20,17 +20,7 @@ require '../../index.php';
|
||||||
switch ($_SERVER['REQUEST_METHOD']) {
|
switch ($_SERVER['REQUEST_METHOD']) {
|
||||||
case 'GET':
|
case 'GET':
|
||||||
if (isset($_GET['wish_id'])) {
|
if (isset($_GET['wish_id'])) {
|
||||||
$columns = $database
|
$wish = new Wish($_GET['wish_id'], true);
|
||||||
->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);
|
|
||||||
|
|
||||||
$response['info'] = $wish;
|
$response['info'] = $wish;
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,11 @@ class Wish
|
||||||
/**
|
/**
|
||||||
* Static
|
* 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 NO_IMAGE = '/src/assets/img/no-image.svg';
|
||||||
|
|
||||||
public const STATUS_TEMPORARY = 'temporary';
|
public const STATUS_TEMPORARY = 'temporary';
|
||||||
|
@ -45,6 +50,7 @@ class Wish
|
||||||
*/
|
*/
|
||||||
private Cache\Embed $cache;
|
private Cache\Embed $cache;
|
||||||
|
|
||||||
|
/** General */
|
||||||
public int $id;
|
public int $id;
|
||||||
public int $wishlist;
|
public int $wishlist;
|
||||||
public ?string $title;
|
public ?string $title;
|
||||||
|
@ -53,9 +59,12 @@ class Wish
|
||||||
public ?string $url;
|
public ?string $url;
|
||||||
public ?int $priority;
|
public ?int $priority;
|
||||||
public bool $is_purchasable;
|
public bool $is_purchasable;
|
||||||
|
|
||||||
public ?string $status;
|
public ?string $status;
|
||||||
|
|
||||||
|
/** Product */
|
||||||
|
public ?float $price;
|
||||||
|
|
||||||
|
/** Other */
|
||||||
public \stdClass $info;
|
public \stdClass $info;
|
||||||
|
|
||||||
public bool $exists = false;
|
public bool $exists = false;
|
||||||
|
@ -68,9 +77,12 @@ class Wish
|
||||||
|
|
||||||
if (is_numeric($wish)) {
|
if (is_numeric($wish)) {
|
||||||
$wish = $database
|
$wish = $database
|
||||||
->query('SELECT *
|
->query(
|
||||||
FROM `wishes`
|
'SELECT ' . self::SELECT . '
|
||||||
WHERE `id` = ' . $wish . ';')
|
FROM ' . self::FROM . '
|
||||||
|
LEFT JOIN ' . self::LEFT_JOIN . '
|
||||||
|
WHERE ' . sprintf(self::WHERE, $_GET['wish_id'])
|
||||||
|
)
|
||||||
->fetch();
|
->fetch();
|
||||||
|
|
||||||
$columns = $wish;
|
$columns = $wish;
|
||||||
|
@ -108,11 +120,17 @@ class Wish
|
||||||
{
|
{
|
||||||
ob_start();
|
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
|
* Card
|
||||||
*/
|
*/
|
||||||
$userIsCurrent = isset($_SESSION['user']['id']) && intval($_SESSION['user']['id']) === $ofUser;
|
|
||||||
|
|
||||||
if ($this->url) {
|
if ($this->url) {
|
||||||
$generateCache = $this->cache->generateCache() || !$this->url ? 'true' : 'false';
|
$generateCache = $this->cache->generateCache() || !$this->url ? 'true' : 'false';
|
||||||
} else {
|
} else {
|
||||||
|
@ -178,6 +196,10 @@ class Wish
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
<div class="meta">
|
||||||
|
<span class="date"><?= $numberFormatter->format($this->price ?? 0) ?></span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<?php if ($this->description) { ?>
|
<?php if ($this->description) { ?>
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<?= $this->description ?>
|
<?= $this->description ?>
|
||||||
|
|
|
@ -56,18 +56,22 @@ class Wishlist
|
||||||
{
|
{
|
||||||
global $database;
|
global $database;
|
||||||
|
|
||||||
$SELECT = isset($sql['SELECT']) ? $sql['SELECT'] : '*';
|
$SELECT = isset($sql['SELECT']) ? $sql['SELECT'] : Wish::SELECT;
|
||||||
$FROM = isset($sql['FROM']) ? $sql['FROM'] : '`wishes`';
|
$FROM = isset($sql['FROM']) ? $sql['FROM'] : Wish::FROM;
|
||||||
$WHERE = isset($sql['WHERE']) ? $sql['WHERE'] : '`wishlist` = ' . $this->id;
|
$LEFT_JOIN = isset($sql['LEFT_JOIN']) ? $sql['LEFT_JOIN'] : Wish::LEFT_JOIN;
|
||||||
$ORDER_BY = isset($sql['ORDER_BY']) ? $sql['ORDER_BY'] : '`priority` DESC, `title` ASC, `url` ASC';
|
$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)';
|
$WHERE .= ' AND (`status` != "' . Wish::STATUS_FULFILLED . '" OR `status` IS NULL)';
|
||||||
|
|
||||||
$this->wishes = $database
|
$this->wishes = $database
|
||||||
->query('SELECT ' . $SELECT . '
|
->query(
|
||||||
FROM ' . $FROM . '
|
'SELECT ' . $SELECT . '
|
||||||
WHERE ' . $WHERE . '
|
FROM ' . $FROM . '
|
||||||
ORDER BY ' . $ORDER_BY . ';')
|
LEFT JOIN ' . $LEFT_JOIN . '
|
||||||
|
WHERE ' . $WHERE . '
|
||||||
|
ORDER BY ' . $ORDER_BY . ';'
|
||||||
|
)
|
||||||
->fetchAll();
|
->fetchAll();
|
||||||
|
|
||||||
foreach ($this->wishes as &$wish) {
|
foreach ($this->wishes as &$wish) {
|
||||||
|
|
Loading…
Reference in a new issue