fix: user wishlist view
This commit is contained in:
parent
4fc16105af
commit
05cd98812b
4 changed files with 44 additions and 38 deletions
|
@ -117,7 +117,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
'placeholders' => array(),
|
||||
);
|
||||
$where = array(
|
||||
'wishlist' => '`wishlist` = ' . $wishlist->id,
|
||||
'wishlist' => '`wishlist` = ' . $wishlist->getId(),
|
||||
'priority' => '`priority` = ' . $_GET['priority'],
|
||||
);
|
||||
|
||||
|
@ -137,10 +137,10 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
*/
|
||||
$wishlist = Wishlist::getFromId($_GET['wishlist_id']);
|
||||
|
||||
if ($wishlist->exists) {
|
||||
/** Determine if user is allowed to access wishlist */
|
||||
if ($user->isLoggedIn() && $user->getId() === $wishlist->user) {
|
||||
$response['results'] = $wishlist;
|
||||
if ($wishlist instanceof Wishlist) {
|
||||
if ($user->isLoggedIn() && $user->getId() === $wishlist->getUserId()) {
|
||||
$response['results'] = $wishlist->getCards();
|
||||
} else {
|
||||
http_response_code(403);
|
||||
}
|
||||
|
@ -167,8 +167,11 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
$wishlistId = $wishlist->getId();
|
||||
$wishlistName = $wishlist->getName();
|
||||
|
||||
$wishlists[$wishlistId] = $wishlist;
|
||||
$wishlistsItems[$wishlistId] = array(
|
||||
$wishlists[] = array(
|
||||
'id' => $wishlistId,
|
||||
'hash' => $wishlist->getHash(),
|
||||
);
|
||||
$wishlistsItems[] = array(
|
||||
'name' => $wishlistName,
|
||||
'value' => $wishlistId,
|
||||
'text' => $wishlistName,
|
||||
|
@ -176,7 +179,7 @@ switch ($_SERVER['REQUEST_METHOD']) {
|
|||
}
|
||||
|
||||
$response['wishlists'] = $wishlists;
|
||||
$response['wishlists_items'] = $wishlistsItems;
|
||||
$response['wishlistsItems'] = $wishlistsItems;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
|
@ -11,10 +11,10 @@ $(function () {
|
|||
.api({
|
||||
'action' : 'get wishlists by priority',
|
||||
'beforeSend' : function (settings) {
|
||||
var wishlist_id = $('.wishlist-cards[data-wishlist]').attr('data-wishlist');
|
||||
var wishlistId = $('.wishlist-cards[data-wishlist]').attr('data-wishlist');
|
||||
|
||||
if (undefined === wishthis.$_GET.id && wishlist_id.length > 0) {
|
||||
wishthis.$_GET.id = wishlist_id;
|
||||
if (undefined === wishthis.$_GET.id && undefined !== wishlistId && wishlistId.length > 0) {
|
||||
wishthis.$_GET.id = wishlistId;
|
||||
}
|
||||
|
||||
settings.urlData.style = $('input[name="style"]').val();
|
||||
|
|
|
@ -9,20 +9,20 @@ $(function () {
|
|||
/**
|
||||
* Get Wishlists
|
||||
*/
|
||||
var wishlists_items = [];
|
||||
var wishlists_api = {
|
||||
var wishlistsItems = [];
|
||||
var wishlistsApi = {
|
||||
'action' : 'get wishlists',
|
||||
'onSuccess' : function(response, dropdown_wishlists, xhr) {
|
||||
'onSuccess' : function(response, dropdownWishlists, xhr) {
|
||||
/** Save response for later use */
|
||||
wishlists = response.wishlists;
|
||||
wishlists_items = response.wishlists_items;
|
||||
wishlistsItems = response.wishlistsItems;
|
||||
|
||||
/** Setup and populate dropdown */
|
||||
var dropdown_values = {
|
||||
'values' : wishlists_items,
|
||||
var dropdownValues = {
|
||||
'values' : wishlistsItems,
|
||||
};
|
||||
|
||||
dropdown_wishlists.dropdown('setup menu', dropdown_values);
|
||||
dropdownWishlists.dropdown('setup menu', dropdownValues);
|
||||
|
||||
/** Select a dropdown item */
|
||||
setDropdownWishlistsSelection();
|
||||
|
@ -57,13 +57,15 @@ $(function () {
|
|||
.then(handleFetchError)
|
||||
.then(handleFetchResponse)
|
||||
.then(function(response) {
|
||||
var wishlist;
|
||||
|
||||
/** Set current wishlist */
|
||||
wishlist = response.results;
|
||||
/** Set currently selected wishlist */
|
||||
wishlists.forEach(wishlistI => {
|
||||
if (wishlistI.id === parseInt(wishlist_id)) {
|
||||
wishlist = wishlistI;
|
||||
}
|
||||
});
|
||||
|
||||
/** Set share link */
|
||||
$('.wishlist-share').attr('href', '/wishlist/' + wishlist.hash);
|
||||
$('.wishlist-share').attr('href', '/wishlist/' + $(wishlist).prop('hash'));
|
||||
|
||||
/** Enable wishlist options buttons */
|
||||
$('.button.wishlist-wish-add').removeClass('disabled');
|
||||
|
@ -160,7 +162,7 @@ $(function () {
|
|||
}
|
||||
},
|
||||
})
|
||||
.api(wishlists_api)
|
||||
.api(wishlistsApi)
|
||||
.api('query');
|
||||
|
||||
/**
|
||||
|
@ -572,15 +574,16 @@ $(function () {
|
|||
if (wishthis.$_GET.id) {
|
||||
wishlist_id = wishthis.$_GET.id;
|
||||
} else {
|
||||
if (Object.keys(wishlists).length >= 1) {
|
||||
var first_wishlist_id = Object.keys(wishlists)[0];
|
||||
if (wishlists.length >= 1) {
|
||||
wishlist = $(wishlists).first();
|
||||
|
||||
var first_wishlist_id = wishlist.prop('id');
|
||||
|
||||
wishlist_id = first_wishlist_id;
|
||||
}
|
||||
}
|
||||
|
||||
wishlist = wishlists[wishlist_id];
|
||||
dropdown_wishlists.dropdown('set selected', wishlist.id);
|
||||
dropdown_wishlists.dropdown('set selected', wishlist_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -118,14 +118,14 @@ class Wish
|
|||
/**
|
||||
* A unix timestamp of when this wish was last edited.
|
||||
*
|
||||
* @var int
|
||||
* @var int|null
|
||||
*/
|
||||
private int $edited;
|
||||
private ?int $edited;
|
||||
|
||||
public string $style = 'grid';
|
||||
|
||||
/** Product */
|
||||
public ?float $price;
|
||||
public ?float $price = null;
|
||||
|
||||
/** Other */
|
||||
public \stdClass $info;
|
||||
|
@ -160,14 +160,14 @@ class Wish
|
|||
|
||||
$this->id = $columns['id'];
|
||||
$this->wishlist = $columns['wishlist'];
|
||||
$this->title = $columns['title'];
|
||||
$this->description = $columns['description'];
|
||||
$this->image = $columns['image'];
|
||||
$this->url = $columns['url'];
|
||||
$this->title = $columns['title'] ?? '';
|
||||
$this->description = $columns['description'] ?? '';
|
||||
$this->image = $columns['image'] ?? '';
|
||||
$this->url = $columns['url'] ?? '';
|
||||
$this->priority = $columns['priority'];
|
||||
$this->status = $columns['status'];
|
||||
$this->is_purchasable = $columns['is_purchasable'];
|
||||
$this->edited = $columns['edited'];
|
||||
$this->edited = $columns['edited'] ? \strtotime($columns['edited']) : null;
|
||||
|
||||
$this->info = new \stdClass();
|
||||
|
||||
|
|
Loading…
Reference in a new issue