Skip to content

Commit 5b2edd0

Browse files
committed
feat(reviews): conditionally enable reviews functionality based on store setting
1 parent e155398 commit 5b2edd0

13 files changed

Lines changed: 63 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
@@ -26,6 +26,9 @@ const BrandPageQuery = graphql(`
2626
productComparisonsEnabled
2727
}
2828
}
29+
reviews {
30+
enabled
31+
}
2932
}
3033
}
3134
}

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

Lines changed: 3 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

@@ -219,6 +221,7 @@ export default async function Brand(props: Props) {
219221
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
220222
removeLabel={t('Compare.remove')}
221223
resetFiltersLabel={t('FacetedSearch.resetFilters')}
224+
reviewsEnabled={reviewsEnabled}
222225
showCompare={productComparisonsEnabled}
223226
sortDefaultValue="featured"
224227
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
@@ -45,6 +45,9 @@ const CategoryPageQuery = graphql(
4545
productComparisonsEnabled
4646
}
4747
}
48+
reviews {
49+
enabled
50+
}
4851
}
4952
}
5053
}

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

Lines changed: 3 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

@@ -255,6 +257,7 @@ export default async function Category(props: Props) {
255257
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
256258
removeLabel={t('Compare.remove')}
257259
resetFiltersLabel={t('FacetedSearch.resetFilters')}
260+
reviewsEnabled={reviewsEnabled}
258261
showCompare={productComparisonsEnabled}
259262
sortDefaultValue="featured"
260263
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
@@ -18,6 +18,9 @@ const SearchPageQuery = graphql(`
1818
productComparisonsEnabled
1919
}
2020
}
21+
reviews {
22+
enabled
23+
}
2124
}
2225
}
2326
}

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

Lines changed: 3 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

@@ -251,6 +253,7 @@ export default async function Search(props: Props) {
251253
rangeFilterApplyLabel={t('FacetedSearch.Range.apply')}
252254
removeLabel={t('Compare.remove')}
253255
resetFiltersLabel={t('FacetedSearch.resetFilters')}
256+
reviewsEnabled={reviewsEnabled}
254257
showCompare={productComparisonsEnabled}
255258
sortDefaultValue="featured"
256259
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
@@ -171,6 +171,11 @@ const ProductQuery = graphql(
171171
`
172172
query ProductQuery($entityId: Int!) {
173173
site {
174+
settings {
175+
reviews {
176+
enabled
177+
}
178+
}
174179
product(entityId: $entityId) {
175180
entityId
176181
name
@@ -199,7 +204,7 @@ export const getProduct = cache(async (entityId: number, customerAccessToken?: s
199204
fetchOptions: customerAccessToken ? { cache: 'no-store' } : { next: { revalidate } },
200205
});
201206

202-
return data.site.product;
207+
return data.site;
203208
});
204209

205210
const StreamableProductVariantBySkuQuery = graphql(`

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

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

7979
const productId = Number(slug);
8080

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

8385
if (!baseProduct) {
8486
return notFound();
@@ -535,6 +537,7 @@ export default async function Product({ params, searchParams }: Props) {
535537
href: baseProduct.path,
536538
images: streamableImages,
537539
price: streamablePrices,
540+
reviewsEnabled,
538541
subtitle: baseProduct.brand?.name,
539542
rating: baseProduct.reviewSummary.averageRating,
540543
accordions: streameableAccordions,
@@ -559,12 +562,14 @@ export default async function Product({ params, searchParams }: Props) {
559562
title={t('RelatedProducts.title')}
560563
/>
561564

562-
<Reviews
563-
productId={productId}
564-
searchParams={searchParams}
565-
streamableImages={streamableImages}
566-
streamableProduct={streamableProduct}
567-
/>
565+
{reviewsEnabled && (
566+
<Reviews
567+
productId={productId}
568+
searchParams={searchParams}
569+
streamableImages={streamableImages}
570+
streamableProduct={streamableProduct}
571+
/>
572+
)}
568573

569574
<Stream
570575
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 {
@@ -30,6 +32,7 @@ export interface ProductCardProps {
3032
compareLabel?: string;
3133
compareParamName?: string;
3234
product: Product;
35+
reviewsEnabled?: boolean;
3336
}
3437

3538
// eslint-disable-next-line valid-jsdoc
@@ -55,7 +58,8 @@ export interface ProductCardProps {
5558
* ```
5659
*/
5760
export function ProductCard({
58-
product: { id, title, subtitle, badge, price, image, href, inventoryMessage },
61+
product: { id, title, subtitle, badge, price, image, href, inventoryMessage, rating },
62+
reviewsEnabled = false,
5963
colorScheme = 'light',
6064
className,
6165
showCompare = false,
@@ -149,6 +153,9 @@ export function ProductCard({
149153
</span>
150154
)}
151155
{price != null && <PriceLabel colorScheme={colorScheme} price={price} />}
156+
{reviewsEnabled && typeof rating === 'number' && rating > 0 && (
157+
<Rating rating={rating} />
158+
)}
152159
<span
153160
className={clsx(
154161
'block text-sm font-normal',

0 commit comments

Comments
 (0)