@graphcommerce/magento-product 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@ fragment ProductPageItem on ProductInterface @injectable {
2
2
  __typename
3
3
  uid
4
4
  ...ProductPageCategory
5
+ ...ProductPageBreadcrumb
5
6
  ...ProductPageDescription
6
7
  ...ProductPageGallery
7
8
  ...ProductPageMeta
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 4.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#1659](https://github.com/graphcommerce-org/graphcommerce/pull/1659) [`6987ec7d2`](https://github.com/graphcommerce-org/graphcommerce/commit/6987ec7d21ce2d481fabbd6eda039702fcf5242b) Thanks [@Jessevdpoel](https://github.com/Jessevdpoel)! - Added product and category breadcrumbs
8
+
9
+ ## 4.6.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#1660](https://github.com/graphcommerce-org/graphcommerce/pull/1660) [`48e6522bb`](https://github.com/graphcommerce-org/graphcommerce/commit/48e6522bb9424d4bd77fd77c68065f5625f3ec8d) Thanks [@paales](https://github.com/paales)! - Forward onChange handler for AddProductsToCartButton
14
+
15
+ * [#1660](https://github.com/graphcommerce-org/graphcommerce/pull/1660) [`37b1980a0`](https://github.com/graphcommerce-org/graphcommerce/commit/37b1980a04a4a3d77663b404ae83539620cf65b9) Thanks [@paales](https://github.com/paales)! - Do not static build old product pages when the new product page is used an vice versa
16
+
17
+ * Updated dependencies [[`e5048c5ec`](https://github.com/graphcommerce-org/graphcommerce/commit/e5048c5ec52b83dbe70a246ffdcea65b55a884c6)]:
18
+ - @graphcommerce/ecommerce-ui@1.5.1
19
+ - @graphcommerce/magento-cart@4.8.5
20
+
3
21
  ## 4.6.0
4
22
 
5
23
  ### Minor Changes
@@ -1,6 +1,6 @@
1
1
  import { Button, ButtonProps } from '@graphcommerce/next-ui'
2
2
  import { Trans } from '@lingui/react'
3
- import { SxProps, Theme } from '@mui/material'
3
+ import { SxProps, Theme, useEventCallback } from '@mui/material'
4
4
  import { useFormAddProductsToCart } from './AddProductsToCartForm'
5
5
 
6
6
  export type AddProductsToCartButtonProps = {
@@ -22,7 +22,14 @@ export type AddProductsToCartButtonProps = {
22
22
 
23
23
  export function AddProductsToCartButton(props: AddProductsToCartButtonProps) {
24
24
  const { formState, setValue } = useFormAddProductsToCart()
25
- const { loading, sku, index = 0 } = props
25
+ const { loading, sku, index = 0, disabled, onClick } = props
26
+
27
+ const clickHandler: NonNullable<AddProductsToCartButtonProps['onClick']> = useEventCallback(
28
+ (e) => {
29
+ setValue(`cartItems.${index}.sku`, sku)
30
+ onClick?.(e)
31
+ },
32
+ )
26
33
 
27
34
  return (
28
35
  <Button
@@ -31,9 +38,9 @@ export function AddProductsToCartButton(props: AddProductsToCartButtonProps) {
31
38
  variant='pill'
32
39
  size='large'
33
40
  {...props}
34
- disabled={Boolean(formState.errors.cartItems?.[index].sku?.message)}
41
+ disabled={Boolean(formState.errors.cartItems?.[index].sku?.message) || disabled}
35
42
  loading={formState.isSubmitting || loading}
36
- onClick={() => setValue(`cartItems.${index}.sku`, sku)}
43
+ onClick={clickHandler}
37
44
  >
38
45
  <Trans id='Add to Cart' />
39
46
  </Button>
@@ -3,12 +3,12 @@ import { useFormAddProductsToCart } from './AddProductsToCartForm'
3
3
 
4
4
  type AddToCartQuantityProps = Omit<
5
5
  NumberFieldElementProps,
6
- 'error' | 'required' | 'inputProps' | 'inputRef' | 'helperText' | 'name'
6
+ 'error' | 'required' | 'inputProps' | 'helperText' | 'name' | 'control' | 'name'
7
7
  > & { index?: number }
8
8
 
9
9
  export function AddProductsToCartQuantity(props: AddToCartQuantityProps) {
10
10
  const { index = 0 } = props
11
- const { formState, control } = useFormAddProductsToCart()
11
+ const { control } = useFormAddProductsToCart()
12
12
 
13
13
  return (
14
14
  <NumberFieldElement
@@ -17,10 +17,9 @@ export function AddProductsToCartQuantity(props: AddToCartQuantityProps) {
17
17
  {...props}
18
18
  required
19
19
  inputProps={{ min: 1 }}
20
- defaultValue='1'
20
+ defaultValue={1}
21
21
  control={control}
22
22
  name={`cartItems.${index}.quantity`}
23
- helperText={formState.isSubmitted && formState.errors.cartItems?.[index].quantity?.message}
24
23
  />
25
24
  )
26
25
  }
@@ -0,0 +1,14 @@
1
+ fragment ProductPageBreadcrumb on ProductInterface {
2
+ name
3
+ categories {
4
+ uid
5
+ name
6
+ url_path
7
+ include_in_menu
8
+ breadcrumbs {
9
+ category_name
10
+ category_uid
11
+ category_url_path
12
+ }
13
+ }
14
+ }
@@ -0,0 +1,42 @@
1
+ import { usePrevPageRouter } from '@graphcommerce/framer-next-pages'
2
+ import { Trans } from '@lingui/react'
3
+ import { Breadcrumbs, BreadcrumbsProps, Container, Link, Typography } from '@mui/material'
4
+ import PageLink from 'next/link'
5
+ import { productPageCategory } from '../ProductPageCategory/productPageCategory'
6
+ import { ProductPageBreadcrumbFragment } from './ProductPageBreadcrumb.gql'
7
+
8
+ type ProductPageBreadcrumbsProps = ProductPageBreadcrumbFragment & BreadcrumbsProps
9
+
10
+ export function ProductPageBreadcrumb(props: ProductPageBreadcrumbsProps) {
11
+ const { categories, name } = props
12
+ const prev = usePrevPageRouter()
13
+
14
+ const category =
15
+ categories?.find((c) => `/${c?.url_path}` === prev?.asPath) ?? productPageCategory(props)
16
+
17
+ return (
18
+ <Container maxWidth={false}>
19
+ <Breadcrumbs>
20
+ <PageLink href='/' passHref>
21
+ <Link underline='hover' color='inherit'>
22
+ <Trans id='Home' />
23
+ </Link>
24
+ </PageLink>
25
+ {category?.breadcrumbs?.map((mapped_category, i) => (
26
+ <Link
27
+ underline='hover'
28
+ key={mapped_category?.category_uid}
29
+ color='inherit'
30
+ href={`/${mapped_category?.category_url_path}`}
31
+ >
32
+ {mapped_category?.category_name}
33
+ </Link>
34
+ ))}
35
+ <Link underline='hover' color='inherit' href={`/${category?.url_path}`}>
36
+ {category?.name}
37
+ </Link>
38
+ <Typography color='text.primary'>{name}</Typography>
39
+ </Breadcrumbs>
40
+ </Container>
41
+ )
42
+ }
@@ -0,0 +1,2 @@
1
+ export * from './ProductPageBreadcrumb.gql'
2
+ export * from './ProductPageBreadcrumb'
@@ -6,7 +6,9 @@ import { ProductPageCategoryFragment } from './ProductPageCategory.gql'
6
6
  * - Prefers categories that are included in the menu
7
7
  * - Prefers categories that have a longer path than shorter ones.
8
8
  */
9
- export function productPageCategory(product?: ProductPageCategoryFragment | null) {
9
+ export function productPageCategory<Product extends ProductPageCategoryFragment>(
10
+ product?: Product | null,
11
+ ): NonNullable<Product['categories']>[number] | undefined {
10
12
  if (!product?.categories?.length) return undefined
11
13
  return product?.categories?.reduce((carry, value) => {
12
14
  if (!value?.include_in_menu) return carry
@@ -11,7 +11,7 @@ export type ProductTypenames = NonNullable<
11
11
  export async function getProductStaticPaths(
12
12
  client: ApolloClient<NormalizedCacheObject>,
13
13
  locale: string,
14
- typename: ProductTypenames,
14
+ typename?: ProductTypenames,
15
15
  ) {
16
16
  const query = client.query({
17
17
  query: ProductStaticPathsDocument,
@@ -25,7 +25,7 @@ export async function getProductStaticPaths(
25
25
  const paths: Return['paths'] = (await Promise.all(pages))
26
26
  .map((q) => q.data.products?.items)
27
27
  .flat(1)
28
- .filter((item) => item?.__typename === typename)
28
+ .filter((item) => (typename ? item?.__typename === typename : true))
29
29
  .map((p) => ({ params: { url: `${p?.url_key}` }, locale }))
30
30
 
31
31
  return process.env.VERCEL_ENV !== 'production' ? paths.slice(0, 1) : paths
@@ -1,6 +1,7 @@
1
1
  export * from './AddProductsToCart'
2
2
  export * from './JsonLdProduct/jsonLdProduct'
3
3
  export * from './ProductAddToCart'
4
+ export * from './ProductCustomizable'
4
5
  export * from './ProductList/ProductList.gql'
5
6
  export * from './ProductListCount/ProductListCount'
6
7
  export * from './ProductListFilters/ProductFilters.gql'
@@ -18,6 +19,7 @@ export * from './ProductListItems/renderer'
18
19
  export * from './ProductListLink/ProductListLink'
19
20
  export * from './ProductListPagination/ProductListPagination'
20
21
  export * from './ProductListSort/ProductListSort'
22
+ export * from './ProductPageBreadcrumb'
21
23
  export * from './ProductPageCategory/productPageCategory'
22
24
  export * from './ProductPageDescription/ProductPageDescription'
23
25
  export * from './ProductPageGallery/ProductPageGallery'
@@ -31,4 +33,3 @@ export * from './ProductSpecs/ProductSpecs'
31
33
  export * from './ProductStaticPaths/getProductStaticPaths'
32
34
  export * from './ProductUpsells/UpsellProducts.gql'
33
35
  export * from './ProductWeight/ProductWeight'
34
- export * from './ProductCustomizable'
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/magento-product",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "4.6.0",
5
+ "version": "4.7.0",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -19,12 +19,13 @@
19
19
  "type-fest": "^2.12.2"
20
20
  },
21
21
  "dependencies": {
22
- "@graphcommerce/ecommerce-ui": "1.5.0",
22
+ "@graphcommerce/ecommerce-ui": "1.5.1",
23
23
  "@graphcommerce/framer-scroller": "2.1.39",
24
+ "@graphcommerce/framer-next-pages": "3.3.0",
24
25
  "@graphcommerce/graphql": "3.4.8",
25
26
  "@graphcommerce/graphql-mesh": "4.2.0",
26
27
  "@graphcommerce/image": "3.1.9",
27
- "@graphcommerce/magento-cart": "4.8.4",
28
+ "@graphcommerce/magento-cart": "4.8.5",
28
29
  "@graphcommerce/magento-store": "4.3.0",
29
30
  "@graphcommerce/next-ui": "4.27.0",
30
31
  "schema-dts": "^1.1.0"