Search.../

arrangePlans( )

Changes the display order of the pricing plans on the site page and in the Dashboard.

Description

The arrangePlans() function returns a Promise that resolves when the plans are rearranged on the site page and in the Dashboard.

To rearrange the order of the plans, provide a list of the IDs for all non-archived plans in the desired order, including hidden plans.

Note: Make sure to provide all non-archived plan IDs to avoid unpredictable results.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function arrangePlans(ids: Array<string>): Promise<void>

arrangePlans Parameters

NAME
TYPE
DESCRIPTION
ids
Array<
string
>

IDs of all non-archived plans in the order you want them arranged.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Arrange plans (dashboard page code)

Copy Code
1import { plans } from 'wix-pricing-plans.v2';
2
3/* Sample ids value:
4 * [
5 * "7a3375ce-18a9-42cb-8e39-47918ade45ec",
6 * "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
7 * "838f2c9d-c8d0-4799-a10a-e2f23849db10",
8 * "b20feb39-a452-453e-96ee-01036adcd04e",
9 * "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990 "
10 * ]
11 */
12
13export async function myArrangePlansFunction(ids) {
14 try {
15 const arranged = await plans.arrangePlans(ids);
16
17 return;
18 } catch (error) {
19 console.error(error);
20 // Handle the error
21 }
22}
23
24/* Promise resolves to void */
Arrange plans (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { plans } from 'wix-pricing-plans.v2';
3import { elevate } from 'wix-auth';
4
5/* Sample ids value:
6 * [
7 * "7a3375ce-18a9-42cb-8e39-47918ade45ec",
8 * "cb4a8c57-273a-4567-94e3-cc43d5d339f2",
9 * "838f2c9d-c8d0-4799-a10a-e2f23849db10",
10 * "b20feb39-a452-453e-96ee-01036adcd04e",
11 * "d2fa5805-0d1a-4cfb-9b43-e683cf5fa990 "
12 * ]
13 */
14
15export const myArrangePlansFunction = webMethod(Permissions.Anyone, async (ids) => {
16 try {
17 const elevatedArrangePlans = elevate(plans.arrangePlans);
18 const arranged = await elevatedArrangePlans(ids);
19
20 return;
21 } catch (error) {
22 console.error(error);
23 // Handle the error
24 }
25});
26
27/* Promise resolves to void */
Sort plans alphabetically

Select a sorting option to arranage plans in ascending or descending order by plan slug.

Copy Code
1/*************************************
2 * Backend code - plan-functions.web.js *
3 *************************************/
4
5import { Permissions, webMethod } from 'wix-web-module';
6import { plans } from 'wix-pricing-plans.v2';
7import { elevate } from 'wix-auth';
8
9const elevatedArrangePlans = elevate(plans.arrangePlans);
10
11export const sortPlansBySlug = webMethod(Permissions.Anyone, async (direction) => {
12 let publicPlansQuery = plans.queryPublicPlans();
13
14 if (direction === 'ascending') {
15 publicPlansQuery = publicPlansQuery.ascending('slug');
16 } else {
17 publicPlansQuery = publicPlansQuery.descending('slug');
18 }
19
20 const sortedPlans = await publicPlansQuery.find();
21 const planIds = sortedPlans.items.map(item => item._id);
22
23 return await elevatedArrangePlans(planIds);
24});
25
26/*************
27 * Page code *
28 *************/
29
30import { sortPlansBySlug } from 'backend/plan-functions.web';
31import wixLocationFrontend from 'wix-location-frontend';
32
33$w.onReady(function () {
34 $w('#dropdownSort').options =
35 [
36 {
37 label: 'Ascending',
38 value: 'ascending'
39 },
40 {
41 label: 'Decending',
42 value: 'descending'
43 }
44 ];
45
46 $w('#dropdownSort').onChange(async () => {
47 const direction = $w('#dropdownSort').value;
48 sortPlansBySlug(direction);
49 const url = wixLocationFrontend.url;
50 wixLocationFrontend.to(url);
51 })
52});
53