Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Carousel items per page from cms #2062

Merged
merged 8 commits into from
Dec 1, 2023
28 changes: 20 additions & 8 deletions packages/core/cms/faststore/sections.json
Original file line number Diff line number Diff line change
Expand Up @@ -830,17 +830,23 @@
"title": "Product Shelf",
"description": "Add custom shelves to your store",
"type": "object",
"required": ["title", "first", "after", "sort"],
"required": ["title", "numberOfItems", "after", "sort"],
"properties": {
"title": {
"type": "string",
"title": "Title"
},
"first": {
"numberOfItems": {
"type": "integer",
"title": "First",
"title": "Total number of items",
"default": 5,
"description": "Number of items to display"
"description": "Total number of items"
},
"itemsPerPage": {
"type": "integer",
"title": "Number of items per page",
"default": 5,
"description": "Number of items to display per page"
},
"after": {
"type": "integer",
Expand Down Expand Up @@ -925,17 +931,23 @@
"title": "Cross Selling Shelf",
"description": "Add cross selling product data to your users",
"type": "object",
"required": ["title", "items", "kind"],
"required": ["title", "numberOfItems", "kind"],
"properties": {
"title": {
"title": "Title",
"type": "string"
},
"items": {
"title": "First",
"numberOfItems": {
"title": "Total number of items",
"type": "integer",
"default": 5,
"description": "Number of items to display"
"description": "Total Number of items"
},
"itemsPerPage": {
"type": "integer",
"title": "Number of items per page",
"default": 5,
"description": "Number of items to display per page"
hellofanny marked this conversation as resolved.
Show resolved Hide resolved
},
"kind": {
"title": "Kind",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import styles from '../ProductShelf/section.module.scss'
import Section from '../Section'

interface Props {
items: number
numberOfItems: number
itemsPerPage?: number
title: string
kind: 'buy' | 'view'
}

const CrossSellingShelf = ({ items: first, title, kind }: Props) => {
const CrossSellingShelf = ({
numberOfItems,
itemsPerPage,
title,
kind,
}: Props) => {
const { ref, inView } = useInView()
const context = usePDP()
const productGroupID = context?.data?.product?.isVariantOf?.productGroupID
Expand All @@ -29,7 +35,8 @@ const CrossSellingShelf = ({ items: first, title, kind }: Props) => {
>
<UIProductShelf
inView={inView}
first={first}
numberOfItems={numberOfItems}
itemsPerPage={itemsPerPage}
title={title}
selectedFacets={selectedFacets}
/>
Expand Down
13 changes: 10 additions & 3 deletions packages/core/src/components/ui/ProductShelf/ProductShelf.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ type Sort =

export type ProductShelfProps = {
title: string
first?: number
numberOfItems?: number
after?: string
sort?: Sort
term?: string
selectedFacets?: {
key: string
value: string
}[]
itemsPerPage?: number
productCardConfiguration?: {
showDiscountBadge?: boolean
bordered?: boolean
Expand All @@ -45,12 +46,14 @@ function ProductShelf({
bordered = ProductCard.props.bordered,
showDiscountBadge = ProductCard.props.showDiscountBadge,
} = {},
numberOfItems,
itemsPerPage,
...otherProps
}: ProductShelfProps) {
const titleId = textToKebabCase(title)
const id = useId()
const viewedOnce = useRef(false)
const data = useProductsQuery(otherProps)
const data = useProductsQuery({ first: numberOfItems, ...otherProps })
const products = data?.search?.products
const productEdges = products?.edges ?? []
const aspectRatio = 1
Expand Down Expand Up @@ -82,7 +85,11 @@ function ProductShelf({
loading={products === undefined}
>
<ProductShelfWrapper.Component {...ProductShelfWrapper.props}>
<Carousel.Component id={titleId || id} {...Carousel.props}>
<Carousel.Component
id={titleId || id}
itemsPerPage={itemsPerPage}
{...Carousel.props}
>
{productEdges.map((product, idx) => (
<ProductCard.Component
aspectRatio={aspectRatio}
Expand Down