mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
feat: add activate warranty form
Signed-off-by: Chloe <pinkcloudvnn@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@ export const TAGS = {
|
||||
export const HIDDEN_PRODUCT_TAG = 'nextjs-frontend-hidden';
|
||||
export const DEFAULT_OPTION = 'Default Title';
|
||||
export const SHOPIFY_GRAPHQL_API_ENDPOINT = '/api/2024-04/graphql.json';
|
||||
export const SHOPIFY_GRAPHQL_CUSTOMER_API_ENDPOINT = '/account/customer/api/2024-07/graphql';
|
||||
|
||||
export const CORE_WAIVER = 'core-waiver';
|
||||
export const CORE_VARIANT_ID_KEY = 'coreVariantId';
|
||||
|
25
lib/shopify/fragments/line-item.ts
Normal file
25
lib/shopify/fragments/line-item.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
const lineItemFragment = /* GraphQL */ `
|
||||
fragment LineItem on LineItem {
|
||||
title
|
||||
image {
|
||||
altText
|
||||
height
|
||||
url
|
||||
width
|
||||
}
|
||||
price {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
quantity
|
||||
sku
|
||||
totalPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
variantTitle
|
||||
id
|
||||
}
|
||||
`;
|
||||
|
||||
export default lineItemFragment;
|
@@ -1,9 +1,12 @@
|
||||
import lineItemFragment from './line-item';
|
||||
|
||||
const orderCard = /* GraphQL */ `
|
||||
fragment OrderCard on Order {
|
||||
id
|
||||
number
|
||||
name
|
||||
processedAt
|
||||
createdAt
|
||||
financialStatus
|
||||
fulfillments(first: 1) {
|
||||
edges {
|
||||
@@ -17,20 +20,12 @@ const orderCard = /* GraphQL */ `
|
||||
currencyCode
|
||||
}
|
||||
lineItems(first: 20) {
|
||||
edges {
|
||||
node {
|
||||
title
|
||||
quantity
|
||||
image {
|
||||
altText
|
||||
height
|
||||
url
|
||||
width
|
||||
}
|
||||
}
|
||||
nodes {
|
||||
...LineItem
|
||||
}
|
||||
}
|
||||
}
|
||||
${lineItemFragment}
|
||||
`;
|
||||
|
||||
export default orderCard;
|
||||
|
@@ -7,6 +7,7 @@ import {
|
||||
PRICE_FILTER_ID,
|
||||
PRODUCT_METAFIELD_PREFIX,
|
||||
SHOPIFY_GRAPHQL_API_ENDPOINT,
|
||||
SHOPIFY_GRAPHQL_CUSTOMER_API_ENDPOINT,
|
||||
TAGS,
|
||||
VARIANT_METAFIELD_PREFIX,
|
||||
YEAR_FILTER_ID
|
||||
@@ -29,9 +30,12 @@ import {
|
||||
getCollectionQuery,
|
||||
getCollectionsQuery
|
||||
} from './queries/collection';
|
||||
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 { getCustomerOrdersQuery } from './queries/orders';
|
||||
import { getPageQuery, getPagesQuery } from './queries/page';
|
||||
import {
|
||||
getProductQuery,
|
||||
@@ -46,18 +50,19 @@ import {
|
||||
Connection,
|
||||
Customer,
|
||||
Filter,
|
||||
Fulfillment,
|
||||
Image,
|
||||
LineItem,
|
||||
Menu,
|
||||
Metaobject,
|
||||
Money,
|
||||
Order,
|
||||
Fulfillment,
|
||||
Transaction,
|
||||
Page,
|
||||
PageInfo,
|
||||
Product,
|
||||
ProductVariant,
|
||||
ShopifyAddToCartOperation,
|
||||
ShopifyAddress,
|
||||
ShopifyCart,
|
||||
ShopifyCartOperation,
|
||||
ShopifyCollection,
|
||||
@@ -65,6 +70,7 @@ import {
|
||||
ShopifyCollectionProductsOperation,
|
||||
ShopifyCollectionsOperation,
|
||||
ShopifyCreateCartOperation,
|
||||
ShopifyCustomer,
|
||||
ShopifyCustomerOperation,
|
||||
ShopifyCustomerOrderOperation,
|
||||
ShopifyCustomerOrdersOperation,
|
||||
@@ -73,6 +79,8 @@ import {
|
||||
ShopifyMenuOperation,
|
||||
ShopifyMetaobject,
|
||||
ShopifyMetaobjectsOperation,
|
||||
ShopifyMoneyV2,
|
||||
ShopifyOrder,
|
||||
ShopifyPage,
|
||||
ShopifyPageOperation,
|
||||
ShopifyPagesOperation,
|
||||
@@ -84,26 +92,18 @@ import {
|
||||
ShopifyRemoveFromCartOperation,
|
||||
ShopifySetCartAttributesOperation,
|
||||
ShopifyUpdateCartOperation,
|
||||
TransmissionType,
|
||||
ShopifyCustomer,
|
||||
ShopifyOrder,
|
||||
ShopifyAddress,
|
||||
ShopifyMoneyV2,
|
||||
LineItem
|
||||
Transaction,
|
||||
TransmissionType
|
||||
} from './types';
|
||||
import { getCustomerQuery } from './queries/customer';
|
||||
import { getCustomerOrdersQuery } from './queries/orders';
|
||||
import { getCustomerOrderQuery } from './queries/order';
|
||||
|
||||
const domain = process.env.SHOPIFY_STORE_DOMAIN
|
||||
? ensureStartsWith(process.env.SHOPIFY_STORE_DOMAIN, 'https://')
|
||||
: '';
|
||||
|
||||
const customerApiUrl = process.env.SHOPIFY_CUSTOMER_ACCOUNT_API_URL;
|
||||
const customerApiVersion = process.env.SHOPIFY_CUSTOMER_API_VERSION;
|
||||
|
||||
const storefrontEndpoint = `${domain}${SHOPIFY_GRAPHQL_API_ENDPOINT}`;
|
||||
const customerEndpoint = `${customerApiUrl}/account/customer/api/${customerApiVersion}/graphql`;
|
||||
const customerEndpoint = `${customerApiUrl}/${SHOPIFY_GRAPHQL_CUSTOMER_API_ENDPOINT}`;
|
||||
|
||||
const userAgent = '*';
|
||||
const placeholderProductImage =
|
||||
@@ -528,24 +528,15 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
||||
}));
|
||||
|
||||
const orderLineItems: LineItem[] =
|
||||
shopifyOrder.lineItems?.edges.map((edge) => ({
|
||||
id: edge.node.id,
|
||||
title: edge.node.title,
|
||||
quantity: edge.node.quantity,
|
||||
image: {
|
||||
url: edge.node.image?.url || placeholderProductImage,
|
||||
altText: edge.node.image?.altText || edge.node.title,
|
||||
width: 62,
|
||||
height: 62
|
||||
},
|
||||
price: reshapeMoney(edge.node.price),
|
||||
totalPrice: reshapeMoney(edge.node.totalPrice),
|
||||
variantTitle: edge.node.variantTitle,
|
||||
sku: edge.node.sku
|
||||
shopifyOrder.lineItems?.nodes?.map((item) => ({
|
||||
...item,
|
||||
price: reshapeMoney(item.price),
|
||||
totalPrice: reshapeMoney(item.totalPrice)
|
||||
})) || [];
|
||||
|
||||
const order: Order = {
|
||||
id: shopifyOrder.id.replace('gid://shopify/Order/', ''),
|
||||
id: shopifyOrder.id,
|
||||
normalizedId: shopifyOrder.id.replace('gid://shopify/Order/', ''),
|
||||
name: shopifyOrder.name,
|
||||
processedAt: shopifyOrder.processedAt,
|
||||
fulfillments: orderFulfillments,
|
||||
@@ -556,7 +547,8 @@ function reshapeOrder(shopifyOrder: ShopifyOrder): Order {
|
||||
subtotal: reshapeMoney(shopifyOrder.subtotal),
|
||||
totalShipping: reshapeMoney(shopifyOrder.totalShipping),
|
||||
totalTax: reshapeMoney(shopifyOrder.totalTax),
|
||||
totalPrice: reshapeMoney(shopifyOrder.totalPrice)
|
||||
totalPrice: reshapeMoney(shopifyOrder.totalPrice),
|
||||
createdAt: shopifyOrder.createdAt
|
||||
};
|
||||
|
||||
if (shopifyOrder.customer) {
|
||||
|
@@ -1,3 +1,5 @@
|
||||
import lineItemFragment from '../fragments/line-item';
|
||||
|
||||
// NOTE: https://shopify.dev/docs/api/customer/latest/queries/customer
|
||||
export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
query getCustomerOrderQuery($orderId: ID!) {
|
||||
@@ -55,11 +57,9 @@ export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
}
|
||||
}
|
||||
lineItems(first: 50) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
...LineItem
|
||||
}
|
||||
nodes {
|
||||
id
|
||||
...LineItem
|
||||
}
|
||||
}
|
||||
totalPrice {
|
||||
@@ -194,25 +194,6 @@ export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
happenedAt
|
||||
}
|
||||
|
||||
fragment LineItem on LineItem {
|
||||
title
|
||||
image {
|
||||
altText
|
||||
height
|
||||
url
|
||||
width
|
||||
}
|
||||
price {
|
||||
...Price
|
||||
}
|
||||
quantity
|
||||
sku
|
||||
totalPrice {
|
||||
...Price
|
||||
}
|
||||
variantTitle
|
||||
}
|
||||
|
||||
fragment OrderPaymentInformation on OrderPaymentInformation {
|
||||
paymentStatus
|
||||
totalPaidAmount {
|
||||
@@ -237,4 +218,5 @@ export const getCustomerOrderQuery = /* GraphQL */ `
|
||||
}
|
||||
}
|
||||
}
|
||||
${lineItemFragment}
|
||||
`;
|
||||
|
@@ -121,7 +121,7 @@ export type Address = {
|
||||
export type LineItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
image: Image;
|
||||
image: Image | null;
|
||||
price?: Money;
|
||||
quantity?: number;
|
||||
sku?: string;
|
||||
@@ -131,9 +131,11 @@ export type LineItem = {
|
||||
|
||||
export type Order = {
|
||||
id: string;
|
||||
normalizedId: string;
|
||||
name: string;
|
||||
customer?: Customer;
|
||||
processedAt: string;
|
||||
createdAt: string;
|
||||
fulfillments: Fulfillment[];
|
||||
transactions: Transaction[];
|
||||
lineItems: LineItem[];
|
||||
@@ -156,13 +158,16 @@ export type ShopifyOrder = {
|
||||
confirmationNumber: string;
|
||||
customer: ShopifyCustomer;
|
||||
processedAt: string;
|
||||
createdAt: string;
|
||||
cancelledAt: string | null;
|
||||
currencyCode: string;
|
||||
transactions: ShopifyOrderTransaction[];
|
||||
billingAddress: ShopifyAddress;
|
||||
shippingAddress: ShopifyAddress;
|
||||
fulfillments: Connection<ShopifyFulfillment>;
|
||||
lineItems: Connection<ShopifyLineItem>;
|
||||
lineItems: {
|
||||
nodes: ShopifyLineItem[];
|
||||
};
|
||||
totalPrice: ShopifyMoneyV2;
|
||||
subtotal: ShopifyMoneyV2;
|
||||
totalShipping: ShopifyMoneyV2;
|
||||
@@ -269,7 +274,7 @@ type ShopifyFulfillmentLineItem = {
|
||||
type ShopifyLineItem = {
|
||||
id: string;
|
||||
title: string;
|
||||
image: ShopifyImage;
|
||||
image: Image | null;
|
||||
price: ShopifyMoneyV2;
|
||||
quantity: number;
|
||||
sku: string;
|
||||
@@ -277,13 +282,6 @@ type ShopifyLineItem = {
|
||||
variantTitle: string;
|
||||
};
|
||||
|
||||
type ShopifyImage = {
|
||||
altText: string;
|
||||
height: number;
|
||||
url: string;
|
||||
width: number;
|
||||
};
|
||||
|
||||
type ShopifyFulfillmentEvent = {
|
||||
status: string;
|
||||
happenedAt: string;
|
||||
|
@@ -87,3 +87,11 @@ export function parseJSON(json: any) {
|
||||
function noproto(k: string, v: string) {
|
||||
if (k !== '__proto__') return v;
|
||||
}
|
||||
|
||||
export function toPrintDate(date: string) {
|
||||
return new Date(date).toLocaleDateString('en-US', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user