Search.../

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
Array<string>

IDs of the products to adjust.

adjust
BulkAdjustProperties

Numeric property to adjust.

Returns

Fulfilled - Bulk action results and metadata. Rejected - Error message.

Return Type:

Promise<BulkUpdateResponse>
NAME
TYPE
DESCRIPTION
results
Array<BulkResults>

Bulk action results.

bulkActionMetadata
BulkActionMetadata

Bulk action metadata.

Was this helpful?

Adjust the weight of multiple products by amount

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 **************************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export 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 error
15 }
16}
17
18/*************
19 * Page code *
20 *************/
21
22import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';
23
24// Sample product IDs:
25const ids = [
26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"
28]
29
30// Increase the weight by 10
31const adjust = {
32 "weight": {
33 "amount": 10
34 }
35}
36
37myBulkAdjustProductPropertyFunction(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 error
45 });
46
47/* Promise resolves to:
48 *
49 * {
50 * "results": [
51 * {
52 * "itemMetadata": {
53 * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
54 * "originalIndex": 0,
55 * "success": true
56 * }
57 * },
58 * {
59 * "itemMetadata": {
60 * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5",
61 * "originalIndex": 1,
62 * "success": true
63 * }
64 * }
65 * ],
66 * "bulkActionMetadata": {
67 * "totalSuccesses": 2,
68 * "totalFailures": 0,
69 * "undetailedFailures": 0
70 * }
71 * }
72 *
73 */
Adjust the cost of multiple products by percentage

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 **************************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export 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 error
15 }
16}
17
18/*************
19 * Page code *
20 *************/
21
22import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';
23
24// Sample product IDs:
25const ids = [
26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"
28]
29
30// Increase the price by 20 percent
31const adjust = {
32 "cost": {
33 "percentage": {
34 "roundToInt": true,
35 "rate": 20
36 }
37 }
38}
39
40myBulkAdjustProductPropertyFunction(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 error
48 });
49
50/* Promise resolves to:
51 *
52 * {
53 * "results": [
54 * {
55 * "itemMetadata": {
56 * "_id": "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
57 * "originalIndex": 0,
58 * "success": true
59 * }
60 * },
61 * {
62 * "itemMetadata": {
63 * "_id": "0614129c-8777-9f3b-4dfe-b80a54df10d5",
64 * "originalIndex": 1,
65 * "success": true
66 * }
67 * }
68 * ],
69 * "bulkActionMetadata": {
70 * "totalSuccesses": 2,
71 * "totalFailures": 0,
72 * "undetailedFailures": 0
73 * }
74 * }
75 *
76 */
Attempt to adjust the price of multiple products by amount

In this example, an error is returned as the resulting product price is below 0.

Copy Code
1/**************************************
2 * Backend code - my-backend-file.jsw *
3 **************************************/
4
5import wixStoresBackend from 'wix-stores-backend';
6
7export 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 error
15 }
16}
17
18/*************
19 * Page code *
20 *************/
21
22import { myBulkAdjustProductPropertyFunction } from 'backend/my-backend-file';
23
24// Sample product IDs:
25const ids = [
26 "91f7ac8b-2baa-289c-aa50-6d64764f35d3",
27 "0614129c-8777-9f3b-4dfe-b80a54df10d5"
28]
29
30// Decrease the price by 30
31const adjust = {
32 "price": {
33 "amount": -30
34 }
35}
36
37myBulkAdjustProductPropertyFunction(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 error
45 });
46
47/* 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": 0
78 * }
79 * }
80 *
81 */
82