Skip to content

Commit d6498f3

Browse files
committed
feat(reviews): conditionally enable reviews functionality based on store setting
1 parent 7927d26 commit d6498f3

13 files changed

Lines changed: 66 additions & 14 deletions

File tree

.changeset/tiny-parts-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@bigcommerce/catalyst-core": minor
3+
---
4+
5+
Conditionally enable storefront reviews functionality based on `site.settings.reviews.enabled`. The storefront logic when this setting is enabled/disabled matches exactly the logic of Stencil + Cornerstone.

core/app/[locale]/(default)/(faceted)/brand/[slug]/page-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const BrandPageQuery = graphql(`
2121
productComparisonsEnabled
2222
}
2323
}
24+
reviews {
25+
enabled
26+
}
2427
}
2528
}
2629
}

core/app/[locale]/(default)/(faceted)/brand/[slug]/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export default async function Brand(props: Props) {
103103
return notFound();
104104
}
105105

106+
const reviewsEnabled = settings?.reviews.enabled ?? false;
107+
106108
const productComparisonsEnabled =
107109
settings?.storefront.catalog?.productComparisonsEnabled ?? false;
108110

@@ -141,6 +143,7 @@ export default async function Brand(props: Props) {
141143
: undefined,
142144
price: pricesTransformer(product.prices, format),
143145
subtitle: product.brand?.name ?? undefined,
146+
rating: product.reviewSummary.averageRating,
144147
}));
145148
});
146149

@@ -220,6 +223,7 @@ export default async function Brand(props: Props) {
220223
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
221224
removeLabel={t('Compare.remove')}
222225
resetFiltersLabel={t('FacetedSearch.resetFilters')}
226+
reviewsEnabled={reviewsEnabled}
223227
showCompare={productComparisonsEnabled}
224228
sortDefaultValue="featured"
225229
sortLabel={t('Search.title')}

core/app/[locale]/(default)/(faceted)/category/[slug]/page-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const CategoryPageQuery = graphql(
4040
productComparisonsEnabled
4141
}
4242
}
43+
reviews {
44+
enabled
45+
}
4346
}
4447
}
4548
}

core/app/[locale]/(default)/(faceted)/category/[slug]/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ export default async function Category(props: Props) {
113113
href: path ?? '#',
114114
}));
115115

116+
const reviewsEnabled = settings?.reviews.enabled ?? false;
117+
116118
const productComparisonsEnabled =
117119
settings?.storefront.catalog?.productComparisonsEnabled ?? false;
118120

@@ -154,6 +156,7 @@ export default async function Category(props: Props) {
154156
: undefined,
155157
price: pricesTransformer(product.prices, format),
156158
subtitle: product.brand?.name ?? undefined,
159+
rating: product.reviewSummary.averageRating,
157160
}));
158161
});
159162

@@ -256,6 +259,7 @@ export default async function Category(props: Props) {
256259
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
257260
removeLabel={t('Compare.remove')}
258261
resetFiltersLabel={t('FacetedSearch.resetFilters')}
262+
reviewsEnabled={reviewsEnabled}
259263
showCompare={productComparisonsEnabled}
260264
sortDefaultValue="featured"
261265
sortLabel={t('SortBy.sortBy')}

core/app/[locale]/(default)/(faceted)/search/page-data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const SearchPageQuery = graphql(`
1313
productComparisonsEnabled
1414
}
1515
}
16+
reviews {
17+
enabled
18+
}
1619
}
1720
}
1821
}

core/app/[locale]/(default)/(faceted)/search/page.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export default async function Search(props: Props) {
7878

7979
const { settings } = await getSearchPageData();
8080

81+
const reviewsEnabled = settings?.reviews.enabled ?? false;
82+
8183
const productComparisonsEnabled =
8284
settings?.storefront.catalog?.productComparisonsEnabled ?? false;
8385

@@ -126,6 +128,7 @@ export default async function Search(props: Props) {
126128
: undefined,
127129
price: pricesTransformer(product.prices, format),
128130
subtitle: product.brand?.name ?? undefined,
131+
rating: product.reviewSummary.averageRating,
129132
}));
130133
});
131134

@@ -252,6 +255,7 @@ export default async function Search(props: Props) {
252255
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
253256
removeLabel={t('Compare.remove')}
254257
resetFiltersLabel={t('FacetedSearch.resetFilters')}
258+
reviewsEnabled={reviewsEnabled}
255259
showCompare={productComparisonsEnabled}
256260
sortDefaultValue="featured"
257261
sortLabel={t('SortBy.sortBy')}

core/app/[locale]/(default)/product/[slug]/page-data.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ const ProductQuery = graphql(
170170
`
171171
query ProductQuery($entityId: Int!) {
172172
site {
173+
settings {
174+
reviews {
175+
enabled
176+
}
177+
}
173178
product(entityId: $entityId) {
174179
entityId
175180
name
@@ -198,7 +203,7 @@ export const getProduct = cache(async (entityId: number, customerAccessToken?: s
198203
fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } },
199204
});
200205

201-
return data.site.product;
206+
return data.site;
202207
});
203208

204209
const StreamableProductQuery = graphql(

core/app/[locale]/(default)/product/[slug]/page.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ export default async function Product({ params, searchParams }: Props) {
7777

7878
const productId = Number(slug);
7979

80-
const baseProduct = await getProduct(productId, customerAccessToken);
80+
const { product: baseProduct, settings } = await getProduct(productId, customerAccessToken);
81+
82+
const reviewsEnabled = settings?.reviews.enabled ?? false;
8183

8284
if (!baseProduct) {
8385
return notFound();
@@ -364,6 +366,7 @@ export default async function Product({ params, searchParams }: Props) {
364366
href: baseProduct.path,
365367
images: streamableImages,
366368
price: streamablePrices,
369+
reviewsEnabled,
367370
subtitle: baseProduct.brand?.name,
368371
rating: baseProduct.reviewSummary.averageRating,
369372
accordions: streameableAccordions,
@@ -387,12 +390,14 @@ export default async function Product({ params, searchParams }: Props) {
387390
title={t('RelatedProducts.title')}
388391
/>
389392

390-
<Reviews
391-
productId={productId}
392-
searchParams={searchParams}
393-
streamableImages={streamableImages}
394-
streamableProduct={streamableProduct}
395-
/>
393+
{reviewsEnabled && (
394+
<Reviews
395+
productId={productId}
396+
searchParams={searchParams}
397+
streamableImages={streamableImages}
398+
streamableProduct={streamableProduct}
399+
/>
400+
)}
396401

397402
<Stream
398403
fallback={null}

core/vibes/soul/primitives/product-card/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import * as Skeleton from '@/vibes/soul/primitives/skeleton';
66
import { Image } from '~/components/image';
77
import { Link } from '~/components/link';
88

9+
import { Rating } from '../rating';
10+
911
import { Compare } from './compare';
1012

1113
export interface Product {
@@ -29,6 +31,7 @@ export interface ProductCardProps {
2931
compareLabel?: string;
3032
compareParamName?: string;
3133
product: Product;
34+
reviewsEnabled?: boolean;
3235
}
3336

3437
// eslint-disable-next-line valid-jsdoc
@@ -52,7 +55,8 @@ export interface ProductCardProps {
5255
* ```
5356
*/
5457
export function ProductCard({
55-
product: { id, title, subtitle, badge, price, image, href },
58+
product: { id, title, subtitle, badge, price, image, href, rating },
59+
reviewsEnabled = false,
5660
colorScheme = 'light',
5761
className,
5862
showCompare = false,
@@ -147,6 +151,9 @@ export function ProductCard({
147151
</span>
148152
)}
149153
{price != null && <PriceLabel colorScheme={colorScheme} price={price} />}
154+
{reviewsEnabled && typeof rating === 'number' && rating > 0 && (
155+
<Rating rating={rating} />
156+
)}
150157
</div>
151158
</div>
152159
{href !== '#' && (

0 commit comments

Comments
 (0)