mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
feat: add activate warranty to order details page
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import customerAddress from './customer-address';
|
||||
import orderCard from './order-card';
|
||||
import orderCard from './order';
|
||||
|
||||
const customerDetailsFragment = /* GraphQL */ `
|
||||
${customerAddress}
|
||||
|
@@ -28,4 +28,19 @@ const orderCard = /* GraphQL */ `
|
||||
${lineItemFragment}
|
||||
`;
|
||||
|
||||
export const orderMetafields = /* GraphQL */ `
|
||||
fragment OrderMetafield on Order {
|
||||
id
|
||||
warrantyStatus: metafield(namespace: "custom", key: "warranty_status") {
|
||||
value
|
||||
}
|
||||
warrantyActivationDeadline: metafield(
|
||||
namespace: "custom"
|
||||
key: "warranty_activation_deadline"
|
||||
) {
|
||||
value
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default orderCard;
|
@@ -38,7 +38,7 @@ import { getCustomerQuery } from './queries/customer';
|
||||
import { getMenuQuery } from './queries/menu';
|
||||
import { getMetaobjectQuery, getMetaobjectsQuery } from './queries/metaobject';
|
||||
import { getImageQuery, getMetaobjectsByIdsQuery } from './queries/node';
|
||||
import { getCustomerOrderQuery } from './queries/order';
|
||||
import { getCustomerOrderQuery, getOrderMetafieldsQuery } from './queries/order';
|
||||
import { getCustomerOrderMetafieldsQuery, getCustomerOrdersQuery } from './queries/orders';
|
||||
import { getPageQuery, getPagesQuery } from './queries/page';
|
||||
import {
|
||||
@@ -1161,3 +1161,27 @@ export const getOrdersMetafields = async (): Promise<{ [key: string]: OrderMetaf
|
||||
{} as { [key: string]: OrderMetafield }
|
||||
);
|
||||
};
|
||||
|
||||
export const getOrderMetafields = async (orderId: string): Promise<OrderMetafield> => {
|
||||
const res = await adminFetch<{
|
||||
data: {
|
||||
order: {
|
||||
id: string;
|
||||
} & ShopifyOrderMetafield;
|
||||
};
|
||||
variables: {
|
||||
id: string;
|
||||
};
|
||||
}>({
|
||||
query: getOrderMetafieldsQuery,
|
||||
variables: { id: `gid://shopify/Order/${orderId}` },
|
||||
tags: [`${TAGS.orderMetafields}/${orderId}`]
|
||||
});
|
||||
|
||||
const order = res.body.data.order;
|
||||
|
||||
return {
|
||||
warrantyStatus: order.warrantyStatus?.value ?? null,
|
||||
warrantyActivationDeadline: order.warrantyActivationDeadline?.value ?? null
|
||||
};
|
||||
};
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import lineItemFragment from '../fragments/line-item';
|
||||
import { orderMetafields } from '../fragments/order';
|
||||
|
||||
// NOTE: https://shopify.dev/docs/api/customer/latest/queries/customer
|
||||
export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
@@ -220,3 +221,12 @@ export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
}
|
||||
${lineItemFragment}
|
||||
`;
|
||||
|
||||
export const getOrderMetafieldsQuery = /* GraphQL */ `
|
||||
query getOrderMetafields($id: ID!) {
|
||||
order(id: $id) {
|
||||
...OrderMetafield
|
||||
}
|
||||
}
|
||||
${orderMetafields}
|
||||
`;
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import customerDetailsFragment from '../fragments/customer-details';
|
||||
import { orderMetafields } from '../fragments/order';
|
||||
|
||||
const customerFragment = `#graphql
|
||||
`;
|
||||
@@ -19,18 +20,10 @@ export const getCustomerOrderMetafieldsQuery = /* GraphQL */ `
|
||||
customer(id: $id) {
|
||||
orders(first: 20, sortKey: PROCESSED_AT, reverse: true) {
|
||||
nodes {
|
||||
id
|
||||
warrantyStatus: metafield(namespace: "custom", key: "warranty_status") {
|
||||
value
|
||||
}
|
||||
warrantyActivationDeadline: metafield(
|
||||
namespace: "custom"
|
||||
key: "warranty_activation_deadline"
|
||||
) {
|
||||
value
|
||||
}
|
||||
...OrderMetafield
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
${orderMetafields}
|
||||
`;
|
||||
|
Reference in New Issue
Block a user