mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Add support for totalInvetory
This commit is contained in:
parent
41eb6954e0
commit
81ac0dd1d4
@ -1,5 +1,5 @@
|
||||
import * as Core from '@commerce/types'
|
||||
import { CheckoutLineItem } from './schema'
|
||||
import { CheckoutLineItem, Maybe, Scalars } from './schema'
|
||||
|
||||
export type ShopifyCheckout = {
|
||||
id: string
|
||||
@ -18,6 +18,10 @@ export interface LineItem extends Core.LineItem {
|
||||
* Cart mutations
|
||||
*/
|
||||
|
||||
export type Product = Core.Product & {
|
||||
totalInventory?: Maybe<Scalars['Int']>
|
||||
}
|
||||
|
||||
export type OptionSelections = {
|
||||
option_id: number
|
||||
option_value: number | string
|
||||
|
@ -27,15 +27,8 @@ export type CheckoutPayload =
|
||||
| CheckoutQuery
|
||||
|
||||
const checkoutToCart = (checkoutPayload?: Maybe<CheckoutPayload>): Cart => {
|
||||
if (!checkoutPayload) {
|
||||
throw new CommerceError({
|
||||
message: 'Missing checkout payload from response',
|
||||
})
|
||||
}
|
||||
|
||||
const checkout = checkoutPayload?.checkout
|
||||
throwUserErrors(checkoutPayload?.checkoutUserErrors)
|
||||
|
||||
const checkout = checkoutPayload?.checkout
|
||||
if (!checkout) {
|
||||
throw new CommerceError({
|
||||
message: 'Missing checkout object from response',
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { Product } from '@commerce/types'
|
||||
|
||||
import {
|
||||
Product as ShopifyProduct,
|
||||
Checkout,
|
||||
@ -11,7 +9,7 @@ import {
|
||||
ProductOption,
|
||||
} from '../schema'
|
||||
|
||||
import type { Cart, LineItem } from '../types'
|
||||
import type { Cart, LineItem, Product } from '../types'
|
||||
|
||||
const money = ({ amount, currencyCode }: MoneyV2) => {
|
||||
return {
|
||||
@ -86,6 +84,7 @@ export function normalizeProduct(productNode: ShopifyProduct): Product {
|
||||
handle,
|
||||
priceRange,
|
||||
options,
|
||||
totalInventory,
|
||||
...rest
|
||||
} = productNode
|
||||
|
||||
@ -99,6 +98,7 @@ export function normalizeProduct(productNode: ShopifyProduct): Product {
|
||||
price: money(priceRange?.minVariantPrice),
|
||||
images: normalizeProductImages(images),
|
||||
variants: variants ? normalizeProductVariants(variants) : [],
|
||||
totalInventory,
|
||||
options: options
|
||||
? options
|
||||
.filter((o) => o.name !== 'Title') // By default Shopify adds a 'Title' name when there's only one option. We don't need it. https://community.shopify.com/c/Shopify-APIs-SDKs/Adding-new-product-variant-is-automatically-adding-quot-Default/td-p/358095
|
||||
|
@ -10,6 +10,7 @@ edges {
|
||||
vendor
|
||||
handle
|
||||
description
|
||||
totalInventory
|
||||
priceRange {
|
||||
minVariantPrice {
|
||||
amount
|
||||
|
@ -8,6 +8,7 @@ const getProductQuery = /* GraphQL */ `
|
||||
vendor
|
||||
description
|
||||
descriptionHtml
|
||||
totalInventory
|
||||
options {
|
||||
id
|
||||
name
|
||||
|
Loading…
x
Reference in New Issue
Block a user