Search...
archiveLocation( )
Developer Preview
Archives a location.
Description
The archiveLocation()
function returns a Promise that resolves to the archived location.
The archiveLocation()
function changes a location's archived
property to true
.
Notes:
- A location's status isn't affected by this function.
- An archived location can't be updated.
- It's currently not possible to unarchive locations.
- A default location can't be archived.
Admin Method
This function requires elevated permissions to run. This function is not universal and runs only on the backend.
Syntax
function archiveLocation(_id: string): Promise<ArchiveLocationResponse>
archiveLocation Parameters
NAME
TYPE
DESCRIPTION
_id
string
ID of the location to archive.
Returns
Return Type:
Promise<
ArchiveLocationResponse
>NAME
TYPE
DESCRIPTION
location
Location
Archived location.
Was this helpful?
Archive a location (dashboard page code)
Copy Code
1import { locations } from 'wix-business-tools.v2';2import { elevate } from 'wix-auth';34/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */56export async function myArchiveLocationFunction(_id) {7 try {8 const elevatedArchiveLocation = elevate(locations.archiveLocation);9 const archivedLocation = await elevatedArchiveLocation(_id);10 console.log('Location has been archived:', archivedLocation);1112 return archivedLocation;13 } catch (error) {14 console.error(error);15 // Handle the error16 }17}1819/* Promise resolves to:20 * {21 * "_id": "0a965e36-4071-4df0-905b-75458817430a"22 * "address": {23 * "streetAddress": {24 * "apt": "",25 * "name": "New Road",26 * "number": "12"27 * },28 * "city": "Kolkata",29 * "postalCode": "70027"30 * },31 * "archived": true,32 * "default": false,33 * "description": "New store in India!",34 * "email": "store@example.com",35 * "name": "India Store",36 * "phone": "0208 209 9087",37 * "revision": "2",38 * "status": "ACTIVE",39 * "timeZone": "Asia/Calcutta",40 * }41 */42
Archive a location (export from backend code)
Copy Code
1import { Permissions, webMethod } from 'wix-web-module';2import { locations } from 'wix-business-tools.v2';3import { elevate } from 'wix-auth';45/* Sample _id value: '0a965e36-4071-4df0-905b-75458817430a' */67export const myArchiveLocationFunction = webMethod(Permissions.Anyone, async (_id) => {8 try {9 const elevatedArchiveLocation = elevate(locations.archiveLocation);10 const archivedLocation = await elevatedArchiveLocation(_id);11 console.log('Location has been archived:', archivedLocation);1213 return archivedLocation;14 } catch (error) {15 console.error(error);16 // Handle the error17 }18});1920/* Promise resolves to:21 * {22 * "_id": "0a965e36-4071-4df0-905b-75458817430a"23 * "address": {24 * "streetAddress": {25 * "apt": "",26 * "name": "New Road",27 * "number": "12"28 * },29 * "city": "Kolkata",30 * "postalCode": "70027"31 * },32 * "archived": true,33 * "default": false,34 * "description": "New store in India!",35 * "email": "store@example.com",36 * "name": "India Store",37 * "phone": "0208 209 9087",38 * "revision": "2",39 * "status": "ACTIVE",40 * "timeZone": "Asia/Calcutta",41 * }42 */43
Archive a location
This code uses the value of user's chosen location from a dropdown on the page and archives it.
Copy Code
1/******************************************2 * Backend code - archive-location.web.js *3 *****************************************/45import { Permissions, webMethod } from 'wix-web-module';6import { locations } from 'wix-business-tools.v2';7import { elevate } from 'wix-auth';89export const archiveLocationById = webMethod(Permissions.Anyone, async (locationId) => {10 try {11 const elevatedArchiveLocation = elevate(locations.archiveLocation);12 const archivedLocation = await elevatedArchiveLocation(locationId);1314 return archivedLocation;15 } catch (error) {16 console.error(error);17 throw new Error(error);18 }19});2021export const listLocations = webMethod(Permissions.Anyone, async () => {22 try {23 const elevatedListLocations = elevate(locations.listLocations);24 const results = await elevatedListLocations();2526 return results.locations;27 } catch (error) {28 console.error(error);29 throw new Error(error);30 }31});323334/*************35 * Page code *36 ************/3738import { archiveLocationById, listLocations } from 'backend/archive-location.web';3940$w.onReady(async () => {41 await populateStoresDropdown();4243 $w('#archiveLocationBtn').onClick(async () => {44 const locationId = $w('#locationsDropdown').value;45 const archivedLocation = await archiveLocationById(locationId);4647 console.log('The following location has been archived', archivedLocation);48 $w('#archivedMessage').show();49 });50});5152async function populateStoresDropdown() {53 const locations = await listLocations();54 const dropdownOptions = locations.map((location) => {55 return {56 label: location.name,57 value: location._id58 }59 });6061 $w('#locationsDropdown').options = dropdownOptions;62}63