I need some help with listing ACTIVE
current Member orders:
export function button_click(event) {
const urlId = getUrlId();
if (wixUsers.currentUser.loggedIn) {
// Check for active orders (!! HELP !!)
orders.listCurrentMemberOrders()
.then((ordersList) => {
if (ordersList.length > 0) {
// Member has active orders
const firstOrderStatus = ordersList[0].status;
wixLocation.to(`/profil/kontakt/${urlId}`);
} else {
// Member has no orders
wixLocation.to(`/abonnementer`);
}
})
.catch((error) => {
console.error(error);
});
} else {
// rest of my code
Currently, this code checks if there are ANY orders - even cancelled and ended orders.
The API tells me that I should be able to filter
orders by 'ACTIVE'
Link to API: https://www.wix.com/velo/reference/wix-pricing-plans-frontend/orders/listcurrentmemberorders
Example from the API reference:
import { orders } from 'wix-pricing-plans-frontend';
/* Sample filters object:
* {
* 'orderStatuses': ['PAUSED', 'CANCELED']
* }
*/
/* Sample sorting object:
* {
* 'fieldName': '_createdDate',
* 'order': 'DESC'
* }
*/
/* Sample paging object:
* {
* 'limit': 2
* }
*/
$w('#listMyOrdersButton').onClick((event) => {
orders.listCurrentMemberOrders(filters, sorting, paging)
.then((ordersList) => {
const firstOrderId = ordersList[0]._id;
const firstCreatedDate = ordersList[0]._createdDate;
console.log('Your list of filtered and sorted orders:', ordersList);
return ordersList;
})
.catch((error) => {
console.error(error);
})
});
I just can't get it to work -- the example provided doesn't help me, and adding the word 'ACTIVE' various places doesn't solve it for me.
So, does anyone know how do I implement the filter
'ACTIVE'
to the code?
Thanks!
If we follow the instructions in the documentation, the filter argument is expected to be an object with one or more properties that each has an array of strings as value. So it should work like this:
orders.listCurrentMemberOrders({ orderStatuses: ['ACTIVE'] })
If you also want to include another status, like maybe PAUSED, then just add it to the array:
orders.listCurrentMemberOrders({ orderStatuses: ['ACTIVE', 'PAUSED'] })