Skip to content

Commit

Permalink
Improve Shopify product variant components (#12613)
Browse files Browse the repository at this point in the history
* updated product variant components

* remove console.log
  • Loading branch information
michelle0927 committed Jun 28, 2024
1 parent 79efd66 commit 6dd2880
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 20 deletions.
61 changes: 57 additions & 4 deletions components/shopify/actions/create-product-variant/common.mjs
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;
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "shopify-create-product-variant",
name: "Create Product Variant",
description: "Create a new product variant. [See the documentation](https://shopify.dev/api/admin-rest/2022-01/resources/product-variant#[post]/admin/api/2022-01/products/{product_id}/variants.json)",
version: "0.0.12",
version: "0.0.13",
type: "action",
props: {
shopify,
Expand Down Expand Up @@ -44,6 +44,13 @@ export default {
"sku",
],
},
locationId: {
propDefinition: [
shopify,
"locationId",
],
optional: true,
},
...common.props,
},
};
65 changes: 63 additions & 2 deletions components/shopify/actions/update-product-variant/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@ 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",
],
},
harmonizedSystemCode: {
type: "integer",
label: "Harmonized System Code",
Expand All @@ -19,10 +49,27 @@ export default {
sku,
countryCodeOfOrigin,
harmonizedSystemCode,
locationId,
available,
barcode,
weight,
weightUnit,
} = this;

if (!option && !price && !imageId && !metafieldsArray && !sku) {
throw new ConfigurationError("Must enter one of `title`, `price`, `imageId`, `metafields`, or `sku`.");
if (available && !locationId) {
throw new ConfigurationError("Must enter LocationId to set the available quantity");
}

if (!option
&& !price
&& !imageId
&& !metafieldsArray
&& !sku
&& !barcode
&& !weight
&& !weightUnit
) {
throw new ConfigurationError("Must enter one of `title`, `price`, `imageId`, `metafields`, `sku`, `barcode`, `weight`, or `weightUnit`.");
}

const metafields = await this.createMetafieldsArray(metafieldsArray, productVariantId, "variants");
Expand All @@ -34,6 +81,9 @@ export default {
image_id: imageId,
metafields,
sku,
barcode,
weight,
weight_unit: weightUnit,
});
response.productVariant = productVariant;

Expand All @@ -47,6 +97,17 @@ export default {
response.inventoryItem = inventoryItem;
}

if (available) {
const { result: inventoryLevel } = await this.shopify.updateInventoryLevel({
inventory_item_id: productVariant.inventory_item_id,
location_id: locationId,
available,
});
response.inventoryLevel = inventoryLevel;
const { result: updatedVariant } = await this.shopify.getProductVariant(productVariantId);
response.productVariant = updatedVariant;
}

$.export("$summary", `Updated product variant \`${productVariant.title}\` with id \`${productVariant.id}\``);
return response;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "shopify-update-product-variant",
name: "Update Product Variant",
description: "Update an existing product variant. [See the docs](https://shopify.dev/api/admin-rest/2022-01/resources/product-variant#[put]/admin/api/2022-01/variants/{variant_id}.json)",
version: "0.0.14",
version: "0.0.15",
type: "action",
props: {
shopify,
Expand Down Expand Up @@ -67,10 +67,11 @@ export default {
],
description: "The country code [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of where the item came from",
},
harmonizedSystemCode: {
type: "integer",
label: "Harmonized System Code",
description: "The general [harmonized system](https://en.wikipedia.org/wiki/Harmonized_System) code for the inventory item",
locationId: {
propDefinition: [
shopify,
"locationId",
],
optional: true,
},
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/shopify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/shopify",
"version": "0.6.4",
"version": "0.6.5",
"description": "Pipedream Shopify Components",
"main": "shopify.app.mjs",
"keywords": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default {
key: "shopify_developer_app-create-product-variant",
name: "Create Product Variant",
description: "Create a new product variant. [See the documentation](https://shopify.dev/api/admin-rest/2022-01/resources/product-variant#[post]/admin/api/2022-01/products/{product_id}/variants.json)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
shopify,
Expand Down Expand Up @@ -44,6 +44,13 @@ export default {
"sku",
],
},
locationId: {
propDefinition: [
shopify,
"locationId",
],
optional: true,
},
...common.props,
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
key: "shopify_developer_app-update-product-variant",
name: "Update Product Variant",
description: "Update an existing product variant. [See the docs](https://shopify.dev/api/admin-rest/2022-01/resources/product-variant#[put]/admin/api/2022-01/variants/{variant_id}.json)",
version: "0.0.3",
version: "0.0.4",
type: "action",
props: {
shopify,
Expand Down Expand Up @@ -67,10 +67,11 @@ export default {
],
description: "The country code [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of where the item came from",
},
harmonizedSystemCode: {
type: "integer",
label: "Harmonized System Code",
description: "The general [harmonized system](https://en.wikipedia.org/wiki/Harmonized_System) code for the inventory item",
locationId: {
propDefinition: [
shopify,
"locationId",
],
optional: true,
},
...common.props,
Expand Down
2 changes: 1 addition & 1 deletion components/shopify_developer_app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/shopify_developer_app",
"version": "0.2.4",
"version": "0.2.5",
"description": "Pipedream Shopify (Developer App) Components",
"main": "shopify_developer_app.app.mjs",
"keywords": [
Expand Down

0 comments on commit 6dd2880

Please sign in to comment.