Check nextjs-commerce bug if no images are added for a product

This commit is contained in:
royderks 2021-04-20 13:52:28 +02:00 committed by Zaiste
parent 740192affe
commit bbbe270842
No known key found for this signature in database
GPG Key ID: 15DF7EBC7F2FFE35
3 changed files with 48 additions and 9 deletions

View File

@ -680,7 +680,7 @@ export enum WebhookEventTypeEnum {
AnyEvents = 'ANY_EVENTS',
/** A new order is placed. */
OrderCreated = 'ORDER_CREATED',
/** An order is confirmed (status change unconfirmed -> unfulfilled) by staff user using OrderConfirm mutation. Also triggers when user finish checkout and shop setting `automatically_confirm_all_new_orders` is enabled. */
/** An order is confirmed (status change unconfirmed -> unfulfilled) by a staff user using the OrderConfirm mutation. It also triggers when the user completes the checkout and the shop setting `automatically_confirm_all_new_orders` is enabled. */
OrderConfirmed = 'ORDER_CONFIRMED',
/** Payment is made and an order is fully paid. */
OrderFullyPaid = 'ORDER_FULLY_PAID',
@ -714,7 +714,7 @@ export enum WebhookEventTypeEnum {
ProductVariantDeleted = 'PRODUCT_VARIANT_DELETED',
/** A new checkout is created. */
CheckoutCreated = 'CHECKOUT_CREATED',
/** A checkout is updated. Also triggers for all updates related to a checkout. */
/** A checkout is updated. It also triggers all updates related to the checkout. */
CheckoutUpdated = 'CHECKOUT_UPDATED',
/** A new fulfillment is created. */
FulfillmentCreated = 'FULFILLMENT_CREATED',
@ -1035,6 +1035,7 @@ export type ShippingMethod = Node &
/** The ID of the object. */
id: Scalars['ID']
name: Scalars['String']
description?: Maybe<Scalars['JSONString']>
minimumOrderWeight?: Maybe<Weight>
maximumOrderWeight?: Maybe<Weight>
maximumDeliveryDays?: Maybe<Scalars['Int']>
@ -1102,6 +1103,7 @@ export type ShippingMethodTranslation = Node & {
/** The ID of the object. */
id: Scalars['ID']
name?: Maybe<Scalars['String']>
description?: Maybe<Scalars['JSONString']>
/** Translation language. */
language: LanguageDisplay
}
@ -2779,6 +2781,7 @@ export type ShippingMethodTranslatableContent = Node & {
/** The ID of the object. */
id: Scalars['ID']
name: Scalars['String']
description?: Maybe<Scalars['JSONString']>
/** Returns translated shipping method fields for the given language code. */
translation?: Maybe<ShippingMethodTranslation>
/** Shipping method are the methods you'll use to get customer's orders to them. They are directly exposed to the customers. */
@ -5614,7 +5617,7 @@ export type MutationShippingPriceUpdateArgs = {
export type MutationShippingPriceTranslateArgs = {
id: Scalars['ID']
input: NameTranslationInput
input: ShippingPriceTranslationInput
languageCode: LanguageCodeEnum
}
@ -7211,6 +7214,8 @@ export type ShippingPriceCreate = {
export type ShippingPriceInput = {
/** Name of the shipping method. */
name?: Maybe<Scalars['String']>
/** Shipping method description (JSON). */
description?: Maybe<Scalars['JSONString']>
/** Minimum order weight to use this shipping method. */
minimumOrderWeight?: Maybe<Scalars['WeightScalar']>
/** Maximum order weight to use this shipping method. */
@ -7292,8 +7297,10 @@ export type ShippingPriceTranslate = {
shippingMethod?: Maybe<ShippingMethod>
}
export type NameTranslationInput = {
export type ShippingPriceTranslationInput = {
name?: Maybe<Scalars['String']>
/** Translated shipping method description (JSON). */
description?: Maybe<Scalars['JSONString']>
}
/** Exclude products from shipping price. */
@ -8495,6 +8502,10 @@ export type ProductVariantTranslate = {
productVariant?: Maybe<ProductVariant>
}
export type NameTranslationInput = {
name?: Maybe<Scalars['String']>
}
/** Manage product variant prices in channels. */
export type ProductVariantChannelListingUpdate = {
__typename?: 'ProductVariantChannelListingUpdate'
@ -11678,6 +11689,8 @@ export type AccountRegisterInput = {
redirectUrl?: Maybe<Scalars['String']>
/** User language code. */
languageCode?: Maybe<LanguageCodeEnum>
/** User public metadata. */
metadata?: Maybe<Array<MetadataInput>>
}
/** Updates the account of the logged-in user. */

View File

@ -1634,7 +1634,7 @@ enum WebhookEventTypeEnum {
ORDER_CREATED
"""
An order is confirmed (status change unconfirmed -> unfulfilled) by staff user using OrderConfirm mutation. Also triggers when user finish checkout and shop setting `automatically_confirm_all_new_orders` is enabled.
An order is confirmed (status change unconfirmed -> unfulfilled) by a staff user using the OrderConfirm mutation. It also triggers when the user completes the checkout and the shop setting `automatically_confirm_all_new_orders` is enabled.
"""
ORDER_CONFIRMED
@ -1719,7 +1719,7 @@ enum WebhookEventTypeEnum {
CHECKOUT_CREATED
"""
A checkout is updated. Also triggers for all updates related to a checkout.
A checkout is updated. It also triggers all updates related to the checkout.
"""
CHECKOUT_UPDATED
@ -2254,6 +2254,7 @@ type ShippingMethod implements Node & ObjectWithMetadata {
"""
id: ID!
name: String!
description: JSONString
minimumOrderWeight: Weight
maximumOrderWeight: Weight
maximumDeliveryDays: Int
@ -2374,6 +2375,7 @@ type ShippingMethodTranslation implements Node {
"""
id: ID!
name: String
description: JSONString
"""
Translation language.
@ -4929,6 +4931,7 @@ type ShippingMethodTranslatableContent implements Node {
"""
id: ID!
name: String!
description: JSONString
"""
Returns translated shipping method fields for the given language code.
@ -8927,7 +8930,7 @@ type Mutation {
Shipping method ID.
"""
id: ID!
input: NameTranslationInput!
input: ShippingPriceTranslationInput!
"""
Translation language code.
@ -12791,6 +12794,11 @@ input ShippingPriceInput {
"""
name: String
"""
Shipping method description (JSON).
"""
description: JSONString
"""
Minimum order weight to use this shipping method.
"""
@ -12929,8 +12937,13 @@ type ShippingPriceTranslate {
shippingMethod: ShippingMethod
}
input NameTranslationInput {
input ShippingPriceTranslationInput {
name: String
"""
Translated shipping method description (JSON).
"""
description: JSONString
}
"""
@ -14859,6 +14872,10 @@ type ProductVariantTranslate {
productVariant: ProductVariant
}
input NameTranslationInput {
name: String
}
"""
Manage product variant prices in channels.
"""
@ -19721,6 +19738,11 @@ input AccountRegisterInput {
User language code.
"""
languageCode: LanguageCodeEnum
"""
User public metadata.
"""
metadata: [MetadataInput!]
}
"""

View File

@ -14,6 +14,9 @@ import {
import type { Cart, LineItem } from '../types'
// TODO: Check nextjs-commerce bug if no images are added for a product
const placeholderImg = '/product-img-placeholder.svg'
const money = ({ amount, currency }: Money) => {
return {
value: +amount,
@ -97,7 +100,8 @@ export function normalizeProduct(productNode: SaleorProduct): Product {
path: `/${slug}`,
slug: slug?.replace(/^\/+|\/+$/g, ''),
price: money(pricing?.priceRange?.start?.net) || 0,
images: media,
// TODO: Check nextjs-commerce bug if no images are added for a product
images: media?.length ? media : [{ url: placeholderImg }],
variants: variants ? normalizeProductVariants(variants) : [],
options: variants ? normalizeProductOptions(variants) : [],
...rest,