Wishlist
useGetFavoritesQuery
This function is used to fetch a list of favorite products.
The useGetFavoritesQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useGetFavoritesQuery } from '@akinon/next/data/client/wishlist';
To fetch the list of favorite products, create a variable and call the function:
const { data: favorites } = useGetFavoritesQuery({
page: Number(searchParams.get('page')),
limit: Number(searchParams.get('limit'))
});
Following parameters can be sent to the function:
page: This value is used for pagination, indicating the page the user is currently on.
limit: It determines the limit of products on page the user is currently on.
Data returned from function:
count: It provides the total number of products that have been added to favorites.
next: This is used for pagination. If a user is on page 2, it contains the URL of page 3.
previous: This is used for pagination. If a user is on page 2, it contains the URL of page 1.
{
"count": 1,
"next": null,
"previous": null,
"results": [{
"pk": 12,
"product": {
"pk": 39,
"name": "Product Name",
"sku": "000000",
"base_code": "000000",
"attributes": {
...
},
"attribute_set": 1,
"attributes_kwargs": {
...
},
"extra_attributes": {},
"productimage_set": [{
"status": "active",
"image": "https://image-url.jpg",
"created_date": "2023-04-18T09:52:55.333304Z",
"specialimage_set": [],
"pk": 312,
"order": 4
}],
"price": "59",
"in_stock": true,
"currency_type": "aed",
"retail_price": "85",
"unit_type": "qty",
"absolute_url": "/product-url/",
"productvideo_set": [],
"product_type": "0",
"price_type": "default",
"form_schema": null,
"is_ready_to_basket": false,
"stock": 80,
"data_source": null,
"basket_offers": [{
...
}],
"extra_data": {
"variants": [{
"attribute_key": "color",
"options": [{
"product": {
"absolute_url": "/url",
"price": "59",
"attributes": {
...
},
"pk": 31,
"productimage_set": [{
"status": "active",
"image": "https://image-url.jpg",
"created_date": "2023-04-18T09:52:55.333304Z",
"specialimage_set": [],
"pk": 312,
"order": 4
}]
},
"in_stock": true,
"is_selectable": true,
"label": "Green"
}]
}]
}
}
}]
}
useGetStockAlertsQuery
The useGetStockAlertsQuery function is used to retrieve the list of stock alert subscriptions made by the user (e.g. “notify me when in stock”). It accepts pagination parameters like page and limit.
The useGetStockAlertsQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useGetStockAlertsQuery } from '@akinon/next/data/client/wishlist';
This function can be used like this:
const { data: getStockAlerts, refetch: fetchStockAlerts } = useGetStockAlertsQuery({
page: 1,
limit: 1000,
}, { skip: !isLoggedIn });
useGetCollectionsOOSQuery
Manages the flow where products that were previously added to the cart but later went out of stock are displayed to the user, and removed from the cart after being acknowledged, allowing the user to proceed with their shopping.
The useGetCollectionsOOSQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useGetCollectionsOOSQuery } from '@akinon/next/data/client/wishlist';
This function can be used like this:
const { data: collectionList, isSuccess: isCollectionSuccess } =
useGetCollectionsOOSQuery(
{
search: collectionName // or product_id: someProductId
},
{
skip:
!basketData || basketData?.unavailable_basket_products?.length === 0
}
);
Both search
and product_id
parameters are optional — the query can be executed with either, both, or none.
useLazyGetCollectionsOOSQuery
The useLazyGetCollectionsOOSQuery function is used to lazily fetch collections associated with out-of-stock products.
Unlike regular queries, it doesn't run automatically on mount — it must be triggered manually, typically in response to user actions or specific conditions.
The useLazyGetCollectionsOOSQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useLazyGetCollectionsOOSQuery } from '@akinon/next/data/client/wishlist';
This function can be used like this:
const [getCollectionsOOS] = useLazyGetCollectionsOOSQuery();
const [oosData, setOosData] = useState(null);
const fetchOOSData = () => {
if (status !== 'authenticated') {
return;
}
getCollectionsOOS({ search: collectionName })
.unwrap()
.then((res) => {
setOosData(res);
});
};
useLazyDeleteCollectionQuery
The useLazyDeleteCollectionQuery function is used to remove products from the cart that were previously added but are now out of stock.
As a lazy query, it doesn't run automatically — it must be triggered manually, typically after the user has seen the out-of-stock item.
The useLazyDeleteCollectionQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useLazyDeleteCollectionQuery } from '@akinon/next/data/client/wishlist';
This function can be used like this:
const [deleteCollection] = useLazyDeleteCollectionQuery();
const [oosData, setOosData] = useState(null);
const removeCollectionAndContinueHandler = () => {
if (status !== 'authenticated') {
return;
}
if (oosData?.results[0]?.pk) {
deleteCollection(oosData.results[0].pk)
.unwrap()
.finally(() => {
fetchOOSData();
});
}
};
useLazyDeleteCollectionItemQuery
The useLazyDeleteCollectionItemQuery function is used to remove a single item from a collection, typically a list of out-of-stock products.
Since it's a lazy query, it doesn't execute automatically — it must be triggered manually.
The useLazyDeleteCollectionItemQuery function is imported from '@akinon/next/data/client/wishlist'
.
import { useLazyDeleteCollectionItemQuery } from '@akinon/next/data/client/wishlist';
This function can be used like this:
const [deleteCollectionItem] = useLazyDeleteCollectionItemQuery();
await deleteCollectionItem(itemPk).unwrap();
Last updated
Was this helpful?