diff --git a/components/shopify/actions/get-order/common.mjs b/components/shopify/actions/get-order/common.mjs new file mode 100644 index 0000000000000..79dc2630288f4 --- /dev/null +++ b/components/shopify/actions/get-order/common.mjs @@ -0,0 +1,61 @@ +import { toSingleLineString } from "../../common/utils.mjs"; + +export default { + methods: { + /** + * Formats the order data response + * @param {object} order - The order object from Shopify + * @returns {object} - Formatted order data + */ + formatOrderData(order) { + return { + id: order.id, + order_number: order.order_number, + total_price: order.total_price, + created_at: order.created_at, + updated_at: order.updated_at, + fulfillment_status: order.fulfillment_status, + financial_status: order.financial_status, + customer: order.customer, + line_items: order.line_items, + shipping_address: order.shipping_address, + billing_address: order.billing_address, + }; + }, + }, + props: { + orderFields: { + type: "string[]", + label: "Order Fields", + description: toSingleLineString(` + Select which fields to include in the response. + If none selected, returns all available fields. + See Shopify Order API documentation for available fields: + https://shopify.dev/api/admin-graphql/2024-10/queries/order + `), + optional: true, + }, + includeMetafields: { + type: "boolean", + label: "Include Metafields", + description: "Whether to include order metafields in the response", + optional: true, + default: false, + }, + includeCustomer: { + type: "boolean", + label: "Include Customer Details", + description: + "Whether to include detailed customer information in the response", + optional: true, + default: true, + }, + includeLineItems: { + type: "boolean", + label: "Include Line Items", + description: "Whether to include line items details in the response", + optional: true, + default: true, + }, + }, +}; diff --git a/components/shopify/actions/get-order/get-order.mjs b/components/shopify/actions/get-order/get-order.mjs new file mode 100644 index 0000000000000..dec9d56b68ec5 --- /dev/null +++ b/components/shopify/actions/get-order/get-order.mjs @@ -0,0 +1,39 @@ +import common from "./common.mjs"; +import app from "../../shopify.app.mjs"; + +export default { + ...common, // spread the common configurations + key: "shopify-get-order", + name: "Get Order", + description: "Retrieves a specific order from Shopify", + version: "0.0.1", + type: "action", + props: { + app, + orderId: { + type: "string", + label: "Order ID", + description: "The ID of the order to retrieve", + }, + ...common.props, // spread the common props + }, + async run({ $ }) { + const params = { + fields: this.orderFields, + include_metafields: this.includeMetafields, + include_customer: this.includeCustomer, + include_line_items: this.includeLineItems, + }; + + const response = await this.app.resourceAction( + "order", + "get", + params, + this.orderId + ); + + const formattedOrder = this.formatOrderData(response.result); + $.export("$summary", `Retrieved order ${this.orderId}`); + return formattedOrder; + }, +};