bulkAdjustProductProperty( )
Adjusts a numeric property for up to 100 products at a time.
Description
The bulkAdjustProductProperty()
function returns a Promise that resolves when the
property of the products have been adjusted.
A property can be increased or decreased either by percentage or amount.
The properties that can be bulk-adjusted are detailed in the adjust
object in the parameters section below.
Note: Do not pass important information from client-side code. Doing so opens a vulnerability that a malicious user can exploit to change information, such as a buyer’s personal details (address, email, etc.) or product price information. To learn more about how to keep your code secure, see Security Considerations When Working with Wix Code.
Syntax
function bulkAdjustProductProperty(ids: Array<string>, adjust: BulkAdjustProperties): Promise<BulkUpdateResponse>
bulkAdjustProductProperty Parameters
NAME
TYPE
DESCRIPTION
IDs of the products to adjust.
Numeric property to adjust.
Returns
Fulfilled - Bulk action results and metadata. Rejected - Error message.
Return Type:
NAME
TYPE
DESCRIPTION
Bulk action results.
Bulk action metadata.
Was this helpful?
1/**************************************2 * Backend code - my-backend-file.jsw *3 **************************************/45import wixStoresBackend from 'wix-stores-backend';67export async function myBulkAdjustProductPropertyFunction(ids, adjust) {8 try {9 const productAdjustmentResults = await wixStoresBackend.bulkAdjustProductProperty(ids, adjust);10 console.log('Bulk action results:', productAdjustmentResults);11 return productAdjustmentResults;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16}1718/*************19 * Page code *20 *************/2122import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';2324// Sample product IDs:25const ids = [26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"28]2930// Increase the weight by 1031const adjust = {32 "weight": {33 "amount": 1034 }35}3637myBulkAdjustProductPropertyFunction(ids, adjust)38 .then((productAdjustmentResults) => {39 console.log('Bulk action results:', productAdjustmentResults);40 return productAdjustmentResults;41 })42 .catch((error) => {43 console.error(error);44 // Handle the error45 });4647/* Promise resolves to:48 *49 * {50 * "results": [51 * {52 * "itemMetadata": {53 * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",54 * "originalIndex": 0,55 * "success": true56 * }57 * },58 * {59 * "itemMetadata": {60 * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5",61 * "originalIndex": 1,62 * "success": true63 * }64 * }65 * ],66 * "bulkActionMetadata": {67 * "totalSuccesses": 2,68 * "totalFailures": 0,69 * "undetailedFailures": 070 * }71 * }72 *73 */
1/**************************************2 * Backend code - my-backend-file.jsw *3 **************************************/45import wixStoresBackend from 'wix-stores-backend';67export async function myBulkAdjustProductPropertyFunction(ids, adjust) {8 try {9 const productAdjustmentResults = await wixStoresBackend.bulkAdjustProductProperty(ids, adjust);10 console.log('Bulk action results:', productAdjustmentResults);11 return productAdjustmentResults;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16}1718/*************19 * Page code *20 *************/2122import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';2324// Sample product IDs:25const ids = [26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"28]2930// Increase the price by 20 percent31const adjust = {32 "cost": {33 "percentage": {34 "roundToInt": true,35 "rate": 2036 }37 }38}3940myBulkAdjustProductPropertyFunction(ids, adjust)41 .then((productAdjustmentResults) => {42 console.log('Bulk action results:', productAdjustmentResults);43 return productAdjustmentResults;44 })45 .catch((error) => {46 console.error(error);47 // Handle the error48 });4950/* Promise resolves to:51 *52 * {53 * "results": [54 * {55 * "itemMetadata": {56 * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",57 * "originalIndex": 0,58 * "success": true59 * }60 * },61 * {62 * "itemMetadata": {63 * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5",64 * "originalIndex": 1,65 * "success": true66 * }67 * }68 * ],69 * "bulkActionMetadata": {70 * "totalSuccesses": 2,71 * "totalFailures": 0,72 * "undetailedFailures": 073 * }74 * }75 *76 */
In this example, an error is returned as the resulting product price is below 0.
1/**************************************2 * Backend code - my-backend-file.jsw *3 **************************************/45import wixStoresBackend from 'wix-stores-backend';67export async function myBulkAdjustProductPropertyFunction(ids, adjust) {8 try {9 const productAdjustmentResults = await wixStoresBackend.bulkAdjustProductProperty(ids, adjust);10 console.log('Bulk action results:', productAdjustmentResults);11 return productAdjustmentResults;12 } catch (error) {13 console.error(error);14 // Handle the error15 }16}1718/*************19 * Page code *20 *************/2122import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';2324// Sample product IDs:25const ids = [26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"28]2930// Decrease the price by 3031const adjust = {32 "price": {33 "amount": -3034 }35}3637myBulkAdjustProductPropertyFunction(ids, adjust)38 .then((productAdjustmentResults) => {39 console.log('Bulk action results:', productAdjustmentResults);40 return productAdjustmentResults;41 })42 .catch((error) => {43 console.error(error);44 // Handle the error45 });4647/* Promise resolves to:48 *49 * {50 * "results": [51 * {52 * "itemMetadata": {53 * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",54 * "originalIndex": 0,55 * "success": false,56 * "error": {57 * "code": "PRODUCT_ADJUSTMENT_PRICE_OUT_OF_RANGE",58 * "description": "Product/variant price must be between 0 and 999999999.99 after adjustment"59 * }60 * }61 * },62 * {63 * "itemMetadata": {64 * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5",65 * "originalIndex": 1,66 * "success": false,67 * "error": {68 * "code": "PRODUCT_ADJUSTMENT_PRICE_OUT_OF_RANGE",69 * "description": "Product/variant price must be between 0 and 999999999.99 after adjustment"70 * }71 * }72 * }73 * ],74 * "bulkActionMetadata": {75 * "totalSuccesses": 0,76 * "totalFailures": 2,77 * "undetailedFailures": 078 * }79 * }80 *81 */82