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';23/* 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 */1213export async function myArrangePlansFunction(ids) {14 try {15 const arranged = await plans.arrangePlans(ids);1617 return;18 } catch (error) {19 console.error(error);20 // Handle the error21 }22}2324/* 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';45/* 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 */1415export const myArrangePlansFunction = webMethod(Permissions.Anyone, async (ids) => {16 try {17 const elevatedArrangePlans = elevate(plans.arrangePlans);18 const arranged = await elevatedArrangePlans(ids);1920 return;21 } catch (error) {22 console.error(error);23 // Handle the error24 }25});2627/* 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 *************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { plans } from 'wix-pricing-plans.v2';7import { elevate } from 'wix-auth';89const elevatedArrangePlans = elevate(plans.arrangePlans);1011export const sortPlansBySlug = webMethod(Permissions.Anyone, async (direction) => {12 let publicPlansQuery = plans.queryPublicPlans();1314 if (direction === 'ascending') {15 publicPlansQuery = publicPlansQuery.ascending('slug');16 } else {17 publicPlansQuery = publicPlansQuery.descending('slug');18 }1920 const sortedPlans = await publicPlansQuery.find();21 const planIds = sortedPlans.items.map(item => item._id);2223 return await elevatedArrangePlans(planIds);24});2526/*************27 * Page code *28 *************/2930import { sortPlansBySlug } from 'backend/plan-functions.web';31import wixLocationFrontend from 'wix-location-frontend';3233$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 ];4546 $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