|
1 | 1 | import oto from "../../oto.app.mjs"; |
| 2 | +import utils from "../../common/utils.mjs"; |
2 | 3 |
|
3 | 4 | export default { |
4 | 5 | key: "oto-create-product", |
5 | 6 | name: "Create Product", |
6 | 7 | description: "Creates a new product. [See the documentation](https://apis.tryoto.com/#21b289bc-04c1-49b1-993e-23e928d57f56)", |
7 | | - version: "0.0.{{ts}}", |
| 8 | + version: "0.0.1", |
8 | 9 | type: "action", |
9 | 10 | props: { |
10 | 11 | oto, |
| 12 | + sku: { |
| 13 | + type: "string", |
| 14 | + label: "Sku", |
| 15 | + description: "SKU of the product", |
| 16 | + }, |
| 17 | + productName: { |
| 18 | + type: "string", |
| 19 | + label: "Product Name", |
| 20 | + description: "Name of the product", |
| 21 | + }, |
| 22 | + price: { |
| 23 | + type: "string", |
| 24 | + label: "Price", |
| 25 | + description: "Price of the product", |
| 26 | + }, |
| 27 | + taxAmount: { |
| 28 | + type: "string", |
| 29 | + label: "Tax Amount", |
| 30 | + description: "Tax Amount of the product", |
| 31 | + optional: true, |
| 32 | + }, |
| 33 | + brandId: { |
| 34 | + propDefinition: [ |
| 35 | + oto, |
| 36 | + "brandId", |
| 37 | + ], |
| 38 | + }, |
| 39 | + description: { |
| 40 | + type: "string", |
| 41 | + label: "Description", |
| 42 | + description: "Description of the product", |
| 43 | + optional: true, |
| 44 | + }, |
| 45 | + barcode: { |
| 46 | + type: "string", |
| 47 | + label: "Barcode", |
| 48 | + description: "Barcode of the product", |
| 49 | + optional: true, |
| 50 | + }, |
| 51 | + secondBarcode: { |
| 52 | + type: "string", |
| 53 | + label: "Second Barcode", |
| 54 | + description: "Second Barcode of the product", |
| 55 | + optional: true, |
| 56 | + }, |
| 57 | + productImage: { |
| 58 | + type: "string", |
| 59 | + label: "Product Image", |
| 60 | + description: "Image Link of the product", |
| 61 | + optional: true, |
| 62 | + }, |
| 63 | + category: { |
| 64 | + type: "string", |
| 65 | + label: "Category", |
| 66 | + description: "Category of the product", |
| 67 | + optional: true, |
| 68 | + }, |
| 69 | + hsCode: { |
| 70 | + type: "string", |
| 71 | + label: "HS Code", |
| 72 | + description: "A standardized numerical method of classifying traded products", |
| 73 | + optional: true, |
| 74 | + }, |
| 75 | + itemOrigin: { |
| 76 | + type: "string", |
| 77 | + label: "Item Origin", |
| 78 | + description: "Origin of the product", |
| 79 | + optional: true, |
| 80 | + }, |
| 81 | + bundleItems: { |
| 82 | + type: "boolean", |
| 83 | + label: "Bundle Items", |
| 84 | + description: "It can be true/ false", |
| 85 | + optional: true, |
| 86 | + }, |
| 87 | + customAttributes: { |
| 88 | + type: "object", |
| 89 | + label: "Custom Attributes", |
| 90 | + description: "Custom attributes of the product specified as a JSON Array of objects with keys `attributeName` and `attributeValue`. Example: `[{ \"attributeName\": \"112\", \"attributeValue\": \"test product\"}]`", |
| 91 | + optional: true, |
| 92 | + }, |
11 | 93 | }, |
12 | 94 | async run({ $ }) { |
13 | | - const response = await this.oto.createProduct({}); |
14 | | - $.export("$summary", ""); |
| 95 | + const response = await this.oto.createProduct({ |
| 96 | + $, |
| 97 | + data: { |
| 98 | + sku: this.sku, |
| 99 | + productName: this.productName, |
| 100 | + price: this.price, |
| 101 | + taxAmount: this.taxAmount, |
| 102 | + brandId: this.brandId, |
| 103 | + description: this.description, |
| 104 | + barcode: this.barcode, |
| 105 | + secondBarcode: this.secondBarcode, |
| 106 | + productImage: this.productImage, |
| 107 | + category: this.category, |
| 108 | + hsCode: this.hsCode, |
| 109 | + itemOrigin: this.itemOrigin, |
| 110 | + bundleItems: this.bundleItems, |
| 111 | + customAttributes: utils.parseObject(this.customAttributes), |
| 112 | + }, |
| 113 | + }); |
| 114 | + $.export("$summary", `Successfully created product with ID: ${response.productId}`); |
15 | 115 | return response; |
16 | 116 | }, |
17 | 117 | }; |
0 commit comments