wishlist
Lists the products the signed-in customer saved, one numbered page at a time; saving and unsaving stay with the Salla SDK.
import { wishlist, WishlistListParams } from '@salla.sa/twilight-theme-engine/api/wishlist';In plain words
Shoppers save products they like to a wishlist. wishlist.list({ page }) returns those saved products, a page at a time, as ordinary product objects you can draw with a product card.
It only reads. Saving and unsaving go through the Salla SDK, or the useWishlist hook, which also tells you whether one product is saved.
Signature
wishlist.list(params?: WishlistListParams): Promise<ProductsListResult> // { items, next }
wishlist.queries.list(params: Omit<WishlistListParams, 'signal'>)
// key ['wishlist', 'list', params, { scope }]
interface WishlistListParams {
page?: number; // default 1
perPage?: number; // default 15
filterable?: boolean;
signal?: AbortSignal;
}Try it live
import { useQuery } from '@tanstack/react-query';
import { getAuthToken } from '@salla.sa/twilight-theme-engine/api/client';
import { wishlist } from '@salla.sa/twilight-theme-engine/api/wishlist';
export function SavedProducts() {
const { data } = useQuery({
...wishlist.queries.list({ page: 1 }),
enabled: Boolean(getAuthToken()),
});
return (
<ul>
{data?.items.map((item) => (
<li key={item.id}>{item.name}</li>
))}
</ul>
);
}
Example
import { useQuery } from '@tanstack/react-query';
import { getAuthToken } from '@salla.sa/twilight-theme-engine/api/client';
import { wishlist } from '@salla.sa/twilight-theme-engine/api/wishlist';
import { ProductCard } from '@salla.sa/twilight-theme-engine/components/product';
export function WishlistGrid({ page }: { page: number }) {
const { data } = useQuery({
...wishlist.queries.list({ page }),
enabled: Boolean(getAuthToken()),
});
return (
<div className="s-products-list-wrapper s-products-list-vertical-cards">
{data?.items.map((item, index) => (
<ProductCard key={item.id} product={item} index={index} />
))}
</div>
);
}
How it behaves
Endpoint:
GET products?source=wishlist&page=…&per_page=…, plusfilterablewhen given. It is kept apart fromproduct.listso page numbers and cursors never mix.A guest gets HTTP 401
unauthorized(demo store). The engine wishlist loader wraps the call inorUnauthorized, which does handle that 401.Like
product.list, every item is remembered as a list-card preview, and the key includes the active branch scope.
Gotchas
filterable: trueis sent, but the result has onlyitemsandnext: the response filters are dropped.Paginate with
page.nextcomes back too, butWishlistListParamshas no cursor to send it to.The saved list does not follow the SDK: after
useWishlist().toggle()orSalla.wishlistchanges, invalidate['wishlist', 'list']to read it again.
Related
The shopper's wishlist, shared by every component on the page: check a product, and add, remove or toggle it through the Salla SDK.
Product preview cacheThe list-card cache that lets a product's details paint at once from the card you already have, before the full details arrive.
getAuthTokenReturns the customer's login token the way the API client finds it, or null for a guest; use it to switch customer-only queries on.
Source and docs
- Engine source:
packages/theme-engine/src/api/wishlist.ts