Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions components/shopify/actions/get-order/common.mjs
Original file line number Diff line number Diff line change
@@ -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,
},
},
};
39 changes: 39 additions & 0 deletions components/shopify/actions/get-order/get-order.mjs
Original file line number Diff line number Diff line change
@@ -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;
},
};