-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Shopify product variant components (#12613)
* updated product variant components * remove console.log
- Loading branch information
1 parent
79efd66
commit 6dd2880
Showing
8 changed files
with
150 additions
and
20 deletions.
There are no files selected for viewing
61 changes: 57 additions & 4 deletions
61
components/shopify/actions/create-product-variant/common.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,69 @@ | ||
import { ConfigurationError } from "@pipedream/platform"; | ||
|
||
export default { | ||
props: { | ||
available: { | ||
type: "string", | ||
label: "Available Quantity", | ||
description: "Sets the available inventory quantity", | ||
optional: true, | ||
}, | ||
barcode: { | ||
type: "string", | ||
label: "Barcode", | ||
description: "The barcode, UPC, or ISBN number for the product", | ||
optional: true, | ||
}, | ||
weight: { | ||
type: "string", | ||
label: "Weight", | ||
description: "The weight of the product variant in the unit system specified with Weight Unit", | ||
optional: true, | ||
}, | ||
weightUnit: { | ||
type: "string", | ||
label: "Weight Unit", | ||
description: "The unit of measurement that applies to the product variant's weight. If you don't specify a value for weight_unit, then the shop's default unit of measurement is applied.", | ||
optional: true, | ||
options: [ | ||
"g", | ||
"kg", | ||
"oz", | ||
"lb", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
if (this.available && !this.locationId) { | ||
throw new ConfigurationError("Must enter LocationId to set the available quantity"); | ||
} | ||
|
||
const productVariant = { | ||
option1: this.option, | ||
price: this.price, | ||
image_id: this.imageId, | ||
sku: this.sku, | ||
barcode: this.barcode, | ||
weight: this.weight, | ||
weight_unit: this.weightUnit, | ||
}; | ||
const response = (await this.shopify.createProductVariant( | ||
let { result } = await this.shopify.createProductVariant( | ||
this.productId, | ||
productVariant, | ||
)).result; | ||
$.export("$summary", `Created new product variant \`${response.title}\` with id \`${response.id}\``); | ||
return response; | ||
); | ||
|
||
if (this.available) { | ||
const { result: inventoryLevel } = await this.shopify.updateInventoryLevel({ | ||
inventory_item_id: result.inventory_item_id, | ||
location_id: this.locationId, | ||
available: this.available, | ||
}); | ||
const { result: updatedProductVariant } = await this.shopify.getProductVariant(result.id); | ||
result = updatedProductVariant; | ||
result.inventoryLevel = inventoryLevel; | ||
} | ||
|
||
$.export("$summary", `Created new product variant \`${result.title}\` with id \`${result.id}\``); | ||
return result; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters