@sgflabs/storefront-core 0.1.10 → 0.1.11
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.
- package/package.json +7 -7
- package/src/components/organisms/ProductSidebar/CertificationFilter.tsx +105 -31
- package/src/components/organisms/ProductSidebar/ProductSidebar.tsx +8 -4
- package/src/components/sections/ProductListing/ProductListing.tsx +28 -11
- package/src/lib/data/products.ts +13 -0
- package/src/lib/runtime/public-storefront-runtime-env.ts +14 -0
- package/src/lib/storefront/industry-certifications.ts +32 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sgflabs/storefront-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "Shared storefront library consumed as raw TypeScript source by the brand apps.",
|
|
5
5
|
"license": "PolyForm-Shield-1.0.0",
|
|
6
6
|
"sideEffects": [
|
|
@@ -55,9 +55,9 @@
|
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@sentry/nextjs": "^10.63.0",
|
|
57
57
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
58
|
-
"@sgflabs/gstin": "^0.1.
|
|
59
|
-
"@sgflabs/page-spec": "^0.1.
|
|
60
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
58
|
+
"@sgflabs/gstin": "^0.1.11",
|
|
59
|
+
"@sgflabs/page-spec": "^0.1.11",
|
|
60
|
+
"@sgflabs/storefront-core-common": "^0.1.11",
|
|
61
61
|
"@testing-library/dom": "^10.4.1",
|
|
62
62
|
"@testing-library/jest-dom": "^7.0.0",
|
|
63
63
|
"@testing-library/react": "^16.3.2",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"@sentry/nextjs": "^10.63.0",
|
|
75
75
|
"@sgflabs/artha-go-sdk": "^0.3.0",
|
|
76
|
-
"@sgflabs/gstin": "^0.1.
|
|
77
|
-
"@sgflabs/page-spec": "^0.1.
|
|
78
|
-
"@sgflabs/storefront-core-common": "^0.1.
|
|
76
|
+
"@sgflabs/gstin": "^0.1.11",
|
|
77
|
+
"@sgflabs/page-spec": "^0.1.11",
|
|
78
|
+
"@sgflabs/storefront-core-common": "^0.1.11",
|
|
79
79
|
"next": "15.5.27",
|
|
80
80
|
"react": "^19.2.3",
|
|
81
81
|
"react-dom": "^19.2.3"
|
|
@@ -1,47 +1,68 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { useEffect } from "react"
|
|
3
|
+
import { useEffect, useRef, useState } from "react"
|
|
4
4
|
|
|
5
5
|
import { FilterCheckboxOption, FilterSection } from "../../molecules"
|
|
6
6
|
import useFilters from "../../../hooks/useFilters"
|
|
7
|
+
import { CollapseIcon } from "../../../icons"
|
|
7
8
|
import { CERTIFICATION_TYPE_LABELS } from "../../../lib/helpers/certification-label"
|
|
8
9
|
import { registerFilterSection } from "../../../lib/helpers/filter-section-registry"
|
|
10
|
+
import type { CertificationType } from "../../../lib/helpers/parse-listing-controls"
|
|
11
|
+
import { cn } from "../../../lib/utils"
|
|
9
12
|
|
|
10
13
|
const CERTIFICATION_SECTION_ID = "certification"
|
|
11
14
|
|
|
15
|
+
// Beyond this many selections the trigger shows a count, not the labels, so a
|
|
16
|
+
// long selection cannot overflow the sidebar's width.
|
|
17
|
+
const MAX_LABELS_IN_TRIGGER = 2
|
|
18
|
+
|
|
12
19
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* (packages/modules/b2c-core/src/shared/certification/has-certification-filter.ts).
|
|
16
|
-
* The full ProductCertificationType has 10 values (also: iso, haccp, gmp,
|
|
17
|
-
* brc, other) -- deliberately not all shown here, matching the mockup.
|
|
20
|
+
* Multi-select certification dropdown. The options come from the caller (the
|
|
21
|
+
* storefront's industry decides them); an industry with none renders nothing.
|
|
18
22
|
*/
|
|
19
|
-
const SIDEBAR_CERTIFICATION_TYPES = ["fssai", "halal", "kosher", "organic", "vegan"] as const
|
|
20
|
-
|
|
21
|
-
type SidebarCertificationType = (typeof SIDEBAR_CERTIFICATION_TYPES)[number]
|
|
22
|
-
|
|
23
23
|
export function CertificationFilter({
|
|
24
|
+
certificationTypes,
|
|
24
25
|
certificationCounts,
|
|
25
26
|
searchTerm = "",
|
|
26
27
|
}: {
|
|
27
|
-
|
|
28
|
+
/** The industry's options -- see `getIndustryCertificationTypes`. */
|
|
29
|
+
certificationTypes: readonly CertificationType[]
|
|
30
|
+
certificationCounts?: Partial<Record<CertificationType, number>>
|
|
28
31
|
/** "Find a filter" substring match over certification labels, lifted from the sidebar. */
|
|
29
32
|
searchTerm?: string
|
|
30
33
|
}) {
|
|
31
34
|
const { isFilterActive, updateFilters } = useFilters("certification_type")
|
|
35
|
+
const [open, setOpen] = useState(false)
|
|
36
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
37
|
+
const triggerRef = useRef<HTMLButtonElement>(null)
|
|
32
38
|
|
|
33
|
-
//
|
|
34
|
-
//
|
|
39
|
+
// Not an Accordion: an active chip's reveal opens the dropdown and scrolls
|
|
40
|
+
// the section into view.
|
|
35
41
|
useEffect(() => {
|
|
36
42
|
return registerFilterSection(CERTIFICATION_SECTION_ID, () => {
|
|
43
|
+
setOpen(true)
|
|
37
44
|
document
|
|
38
45
|
.getElementById(CERTIFICATION_SECTION_ID)
|
|
39
46
|
?.scrollIntoView({ behavior: "smooth", block: "center" })
|
|
40
47
|
})
|
|
41
48
|
}, [])
|
|
42
49
|
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (!open) return
|
|
52
|
+
const closeOnOutsideClick = (event: MouseEvent) => {
|
|
53
|
+
if (!containerRef.current?.contains(event.target as Node)) {
|
|
54
|
+
setOpen(false)
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
document.addEventListener("mousedown", closeOnOutsideClick)
|
|
58
|
+
return () => document.removeEventListener("mousedown", closeOnOutsideClick)
|
|
59
|
+
}, [open])
|
|
60
|
+
|
|
43
61
|
const query = searchTerm.trim().toLowerCase()
|
|
44
|
-
|
|
62
|
+
// While the shopper is searching filters, show the matches rather than hide
|
|
63
|
+
// them inside a closed dropdown.
|
|
64
|
+
const isOpen = open || query !== ""
|
|
65
|
+
const visibleTypes = certificationTypes.filter(
|
|
45
66
|
(type) => !query || CERTIFICATION_TYPE_LABELS[type].toLowerCase().includes(query)
|
|
46
67
|
)
|
|
47
68
|
|
|
@@ -49,26 +70,79 @@ export function CertificationFilter({
|
|
|
49
70
|
return null
|
|
50
71
|
}
|
|
51
72
|
|
|
73
|
+
// Summarise only types this industry offers: a stale `?certification_type=`
|
|
74
|
+
// from another industry must not show as a selection the shopper cannot see.
|
|
75
|
+
const selectedLabels = certificationTypes
|
|
76
|
+
.filter((type) => isFilterActive(type))
|
|
77
|
+
.map((type) => CERTIFICATION_TYPE_LABELS[type])
|
|
78
|
+
const summary =
|
|
79
|
+
selectedLabels.length === 0
|
|
80
|
+
? "Select certifications"
|
|
81
|
+
: selectedLabels.length <= MAX_LABELS_IN_TRIGGER
|
|
82
|
+
? selectedLabels.join(", ")
|
|
83
|
+
: `${selectedLabels.length} selected`
|
|
84
|
+
|
|
52
85
|
return (
|
|
53
86
|
<FilterSection heading="Certification" id={CERTIFICATION_SECTION_ID}>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
87
|
+
<div
|
|
88
|
+
ref={containerRef}
|
|
89
|
+
// On the container, not the panel: after opening by keyboard, focus is
|
|
90
|
+
// still on the trigger, and Escape must close from there too.
|
|
91
|
+
onKeyDown={(event) => {
|
|
92
|
+
if (event.key === "Escape" && open) {
|
|
93
|
+
setOpen(false)
|
|
94
|
+
triggerRef.current?.focus()
|
|
95
|
+
}
|
|
96
|
+
}}
|
|
97
|
+
>
|
|
98
|
+
<button
|
|
99
|
+
ref={triggerRef}
|
|
100
|
+
type="button"
|
|
101
|
+
onClick={() => setOpen((wasOpen) => !wasOpen)}
|
|
102
|
+
aria-expanded={isOpen}
|
|
103
|
+
aria-controls={isOpen ? "certification-options" : undefined}
|
|
104
|
+
className={cn(
|
|
105
|
+
"flex h-9 w-full items-center justify-between gap-2 rounded-[9px] border border-primary px-3 text-left text-[13px]",
|
|
106
|
+
"focus:border-brand-700 focus:outline-none",
|
|
107
|
+
selectedLabels.length > 0 ? "font-semibold text-primary" : "text-neutral-500"
|
|
108
|
+
)}
|
|
109
|
+
data-testid="filter-certification-trigger"
|
|
110
|
+
>
|
|
111
|
+
<span className="truncate">{summary}</span>
|
|
112
|
+
<CollapseIcon
|
|
113
|
+
size={16}
|
|
114
|
+
className={cn("shrink-0 transition-transform duration-200", isOpen && "rotate-180")}
|
|
69
115
|
/>
|
|
70
|
-
|
|
71
|
-
|
|
116
|
+
</button>
|
|
117
|
+
{isOpen && (
|
|
118
|
+
<div
|
|
119
|
+
id="certification-options"
|
|
120
|
+
role="group"
|
|
121
|
+
aria-label="Certification"
|
|
122
|
+
className="mt-1.5 flex max-h-56 flex-col gap-0.5 overflow-y-auto overscroll-contain rounded-[9px] border border-primary bg-primary px-2.5 py-1.5"
|
|
123
|
+
data-testid="filter-certification-panel"
|
|
124
|
+
>
|
|
125
|
+
{visibleTypes.map((type) => {
|
|
126
|
+
const checked = isFilterActive(type)
|
|
127
|
+
const amount = certificationCounts?.[type]
|
|
128
|
+
return (
|
|
129
|
+
<FilterCheckboxOption
|
|
130
|
+
key={type}
|
|
131
|
+
label={CERTIFICATION_TYPE_LABELS[type]}
|
|
132
|
+
checked={checked}
|
|
133
|
+
onCheck={() => updateFilters(type)}
|
|
134
|
+
amount={amount}
|
|
135
|
+
// A zero-count option leads to an empty result, so it is not
|
|
136
|
+
// selectable -- unless already selected (the buyer must be able
|
|
137
|
+
// to untick it). Unknown counts (facets not loaded) never disable.
|
|
138
|
+
disabled={amount === 0 && !checked}
|
|
139
|
+
data-testid={`filter-certification-${type}`}
|
|
140
|
+
/>
|
|
141
|
+
)
|
|
142
|
+
})}
|
|
143
|
+
</div>
|
|
144
|
+
)}
|
|
145
|
+
</div>
|
|
72
146
|
</FilterSection>
|
|
73
147
|
)
|
|
74
148
|
}
|
|
@@ -19,6 +19,7 @@ import { categoriesMirrorApplications } from '../../../lib/helpers/categories-mi
|
|
|
19
19
|
import { type FlatCategoryLike } from '../../../lib/helpers/category-tree';
|
|
20
20
|
import { registerFilterSection } from '../../../lib/helpers/filter-section-registry';
|
|
21
21
|
import { isCategoriesCollectionsBrowseMode } from '../../../lib/storefront/browse-nav-flags';
|
|
22
|
+
import { getIndustryCertificationTypes } from '../../../lib/storefront/industry-certifications';
|
|
22
23
|
import { cn } from '../../../lib/utils';
|
|
23
24
|
|
|
24
25
|
interface ProductSidebarProps {
|
|
@@ -64,11 +65,13 @@ export const ProductSidebar = ({
|
|
|
64
65
|
// Category filter is redundant with the Application filter — hide it.
|
|
65
66
|
// In categories-collections browse mode there is no Application filter, so
|
|
66
67
|
// never hide Category on that basis.
|
|
67
|
-
// Davison (categories-collections) is apparel: Size replaces Certification
|
|
68
|
-
// (
|
|
68
|
+
// Davison (categories-collections) is apparel: Size replaces Certification.
|
|
69
|
+
// Which certifications show (if any) is decided by the storefront's industry,
|
|
70
|
+
// not hardcoded -- FSSAI/Halal are food facets, ISO/GMP/BRC are polymer ones.
|
|
69
71
|
const hideApplicationFilter = isCategoriesCollectionsBrowseMode()
|
|
70
72
|
const showApparelSizeFilter = hideApplicationFilter
|
|
71
|
-
|
|
73
|
+
// categories-collections (apparel) never shows them, even if the industry env is unset.
|
|
74
|
+
const certificationTypes = hideApplicationFilter ? [] : getIndustryCertificationTypes()
|
|
72
75
|
const hideCategoryFilter =
|
|
73
76
|
!hideApplicationFilter &&
|
|
74
77
|
categoriesMirrorApplications(
|
|
@@ -191,8 +194,9 @@ export const ProductSidebar = ({
|
|
|
191
194
|
{showApparelSizeFilter && (
|
|
192
195
|
<SizeFilter searchTerm={findFilterTerm} />
|
|
193
196
|
)}
|
|
194
|
-
{
|
|
197
|
+
{certificationTypes.length > 0 && (
|
|
195
198
|
<CertificationFilter
|
|
199
|
+
certificationTypes={certificationTypes}
|
|
196
200
|
certificationCounts={facetCounts?.certification}
|
|
197
201
|
searchTerm={findFilterTerm}
|
|
198
202
|
/>
|
|
@@ -12,11 +12,11 @@ import { CATEGORY_PAGE_SIZE, PRODUCT_LIMIT } from "../../../const"
|
|
|
12
12
|
* Facets the sidebar renders counts for. Requested only on the two routes that
|
|
13
13
|
* can compute them; the core `/store/products` branch below cannot, so that
|
|
14
14
|
* listing renders the controls without counts rather than zeros it never
|
|
15
|
-
* measured.
|
|
16
|
-
*
|
|
15
|
+
* measured. An industry with no certifications (apparel, ...) omits
|
|
16
|
+
* `certification`, since the Certification sidebar section is hidden there.
|
|
17
17
|
*/
|
|
18
18
|
const LISTING_FACETS_DEFAULT = ["has_price", "has_sample", "certification"] as const
|
|
19
|
-
const
|
|
19
|
+
const LISTING_FACETS_NO_CERTIFICATION = ["has_price", "has_sample"] as const
|
|
20
20
|
import { listApplicationCategories, listApplications, listSellerApplications } from "../../../lib/data/applications"
|
|
21
21
|
import { getCategoryNamesByIds, listCategoryTreePage } from "../../../lib/data/categories"
|
|
22
22
|
import { getMusicCategoryIds } from "../../../lib/data/music-categories"
|
|
@@ -27,6 +27,7 @@ import {
|
|
|
27
27
|
} from "../../../lib/data/products"
|
|
28
28
|
import { CERTIFICATION_TYPE_LABELS } from "../../../lib/helpers/certification-label"
|
|
29
29
|
import { isCategoriesCollectionsBrowseMode } from "../../../lib/storefront/browse-nav-flags"
|
|
30
|
+
import { getIndustryCertificationTypes } from "../../../lib/storefront/industry-certifications"
|
|
30
31
|
import { isMusicOnlyCatalogEnabled } from "../../../lib/streaming/streaming-feature-flags"
|
|
31
32
|
import type { SortOptions } from "../../../types/product"
|
|
32
33
|
|
|
@@ -121,12 +122,19 @@ export const ProductListing = async ({
|
|
|
121
122
|
const priceMode =
|
|
122
123
|
sort === "price_asc" || sort === "price_desc" || minPrice != null || maxPrice != null
|
|
123
124
|
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
125
|
+
// Certification is industry-specific: only the types this storefront's
|
|
126
|
+
// industry offers may narrow the catalog, show a chip, or be counted. A
|
|
127
|
+
// stale or shared `?certification_type=halal` on a polymer store is dropped
|
|
128
|
+
// here, so the results, the chips and the dropdown always agree. Apparel
|
|
129
|
+
// (categories-collections) offers none.
|
|
127
130
|
const isApparelBrowse = isCategoriesCollectionsBrowseMode()
|
|
128
|
-
const
|
|
129
|
-
const
|
|
131
|
+
const industryCertificationTypes = isApparelBrowse ? [] : getIndustryCertificationTypes()
|
|
132
|
+
const effectiveCertificationTypes =
|
|
133
|
+
industryCertificationTypes.length === 0
|
|
134
|
+
? undefined
|
|
135
|
+
: certificationTypes?.filter((type) => (industryCertificationTypes as readonly string[]).includes(type))
|
|
136
|
+
const listingFacets =
|
|
137
|
+
industryCertificationTypes.length > 0 ? [...LISTING_FACETS_DEFAULT] : [...LISTING_FACETS_NO_CERTIFICATION]
|
|
130
138
|
const hasCertificationFilter = (effectiveCertificationTypes?.length ?? 0) > 0
|
|
131
139
|
const hasSizeFilter = (sizes?.length ?? 0) > 0
|
|
132
140
|
// A blank/whitespace-only term is "no search", not a filter for "" -- the
|
|
@@ -154,6 +162,7 @@ export const ProductListing = async ({
|
|
|
154
162
|
certificationTypes: effectiveCertificationTypes,
|
|
155
163
|
sizes,
|
|
156
164
|
listingFacets,
|
|
165
|
+
certificationFacetTypes: industryCertificationTypes,
|
|
157
166
|
})
|
|
158
167
|
: (hasApplicationFilter ||
|
|
159
168
|
hasSample ||
|
|
@@ -182,6 +191,7 @@ export const ProductListing = async ({
|
|
|
182
191
|
certificationTypes: effectiveCertificationTypes,
|
|
183
192
|
sizes,
|
|
184
193
|
listingFacets,
|
|
194
|
+
certificationFacetTypes: industryCertificationTypes,
|
|
185
195
|
})
|
|
186
196
|
: listProductsWithSort({
|
|
187
197
|
page: safePage,
|
|
@@ -296,9 +306,16 @@ export const ProductListing = async ({
|
|
|
296
306
|
: {}),
|
|
297
307
|
...(Object.keys(categoryNames).length > 0 ? { category_id: categoryNames } : {}),
|
|
298
308
|
// Static map, not resolved per-request: certification_type's URL values
|
|
299
|
-
// are enum slugs, not ids, so every label is already known up front.
|
|
300
|
-
//
|
|
301
|
-
|
|
309
|
+
// are enum slugs, not ids, so every label is already known up front. Only
|
|
310
|
+
// this industry's types get labels; a chip with no label is hidden, so an
|
|
311
|
+
// out-of-industry value in the URL never shows as a selection.
|
|
312
|
+
...(industryCertificationTypes.length > 0
|
|
313
|
+
? {
|
|
314
|
+
certification_type: Object.fromEntries(
|
|
315
|
+
industryCertificationTypes.map((type) => [type, CERTIFICATION_TYPE_LABELS[type]])
|
|
316
|
+
),
|
|
317
|
+
}
|
|
318
|
+
: {}),
|
|
302
319
|
}
|
|
303
320
|
|
|
304
321
|
return (
|
package/src/lib/data/products.ts
CHANGED
|
@@ -651,6 +651,7 @@ export const listApplicationFilteredProducts = async ({
|
|
|
651
651
|
certificationTypes,
|
|
652
652
|
sizes,
|
|
653
653
|
listingFacets,
|
|
654
|
+
certificationFacetTypes,
|
|
654
655
|
sellerHandle,
|
|
655
656
|
withScopeEntities,
|
|
656
657
|
}: {
|
|
@@ -684,6 +685,12 @@ export const listApplicationFilteredProducts = async ({
|
|
|
684
685
|
* from paying for them.
|
|
685
686
|
*/
|
|
686
687
|
listingFacets?: string[];
|
|
688
|
+
/**
|
|
689
|
+
* Certification types the `certification` facet counts. Absent keeps the
|
|
690
|
+
* backend default (the food set); pass the storefront industry's own list so
|
|
691
|
+
* it does not pay for counts it never shows.
|
|
692
|
+
*/
|
|
693
|
+
certificationFacetTypes?: readonly string[];
|
|
687
694
|
/**
|
|
688
695
|
* Narrow to one seller. Served by the catalog route's own seller scope,
|
|
689
696
|
* which resolves from the seller↔product link rather than the price index —
|
|
@@ -749,6 +756,7 @@ export const listApplicationFilteredProducts = async ({
|
|
|
749
756
|
...(sizes?.length ? { size: sizes.join(',') } : {}),
|
|
750
757
|
...(sellerHandle ? { seller_handle: sellerHandle } : {}),
|
|
751
758
|
...(listingFacets?.length ? { facets: listingFacets.join(',') } : {}),
|
|
759
|
+
...(certificationFacetTypes?.length ? { certification_facet_types: certificationFacetTypes.join(',') } : {}),
|
|
752
760
|
...(region ? { region_id: region.id } : {}),
|
|
753
761
|
...(withScopeEntities ? { with_scope_entities: true } : {}),
|
|
754
762
|
limit,
|
|
@@ -821,6 +829,7 @@ export const listProductsSortedByPrice = async ({
|
|
|
821
829
|
sizes,
|
|
822
830
|
sellerHandle,
|
|
823
831
|
listingFacets,
|
|
832
|
+
certificationFacetTypes,
|
|
824
833
|
}: {
|
|
825
834
|
page?: number;
|
|
826
835
|
limit?: number;
|
|
@@ -850,6 +859,8 @@ export const listProductsSortedByPrice = async ({
|
|
|
850
859
|
sellerHandle?: string;
|
|
851
860
|
/** Facet counts to ask for; see listApplicationFilteredProducts. */
|
|
852
861
|
listingFacets?: string[];
|
|
862
|
+
/** Types the certification facet counts; see listApplicationFilteredProducts. */
|
|
863
|
+
certificationFacetTypes?: readonly string[];
|
|
853
864
|
}): Promise<{
|
|
854
865
|
response: {
|
|
855
866
|
products: HttpTypes.StoreProduct[];
|
|
@@ -894,6 +905,7 @@ export const listProductsSortedByPrice = async ({
|
|
|
894
905
|
...(sizes?.length ? { size: sizes.join(',') } : {}),
|
|
895
906
|
...(sellerHandle ? { seller_handle: sellerHandle } : {}),
|
|
896
907
|
...(listingFacets?.length ? { facets: listingFacets.join(',') } : {}),
|
|
908
|
+
...(certificationFacetTypes?.length ? { certification_facet_types: certificationFacetTypes.join(',') } : {}),
|
|
897
909
|
limit,
|
|
898
910
|
offset,
|
|
899
911
|
},
|
|
@@ -963,6 +975,7 @@ export const listProductsSortedByPrice = async ({
|
|
|
963
975
|
sortBy,
|
|
964
976
|
sellerHandle,
|
|
965
977
|
listingFacets,
|
|
978
|
+
certificationFacetTypes,
|
|
966
979
|
});
|
|
967
980
|
}
|
|
968
981
|
|
|
@@ -16,6 +16,8 @@ export type StorefrontPublicRuntimeSnapshot = {
|
|
|
16
16
|
NEXT_PUBLIC_ENABLE_COOKIE_CONSENT?: string
|
|
17
17
|
/** Browse panel vocabulary: `applications` (default) or `categories-collections` (Davison). */
|
|
18
18
|
NEXT_PUBLIC_BROWSE_NAV_MODE?: string
|
|
19
|
+
/** Industry sales-channel slug (e.g. `food_ingredients`); decides which certification filters show. */
|
|
20
|
+
NEXT_PUBLIC_STOREFRONT_INDUSTRY?: string
|
|
19
21
|
/** artha-go ai-interface base URL; the AI chat widget renders nothing when unset. */
|
|
20
22
|
NEXT_PUBLIC_AI_INTERFACE_URL?: string
|
|
21
23
|
}
|
|
@@ -80,6 +82,12 @@ export function buildStorefrontRuntimeEnvSnapshot(): StorefrontPublicRuntimeSnap
|
|
|
80
82
|
if (browseNavMode !== undefined) {
|
|
81
83
|
snapshot.NEXT_PUBLIC_BROWSE_NAV_MODE = browseNavMode
|
|
82
84
|
}
|
|
85
|
+
const storefrontIndustry =
|
|
86
|
+
optionalTrim(process.env.STOREFRONT_INDUSTRY) ??
|
|
87
|
+
optionalTrim(process.env.NEXT_PUBLIC_STOREFRONT_INDUSTRY)
|
|
88
|
+
if (storefrontIndustry !== undefined) {
|
|
89
|
+
snapshot.NEXT_PUBLIC_STOREFRONT_INDUSTRY = storefrontIndustry
|
|
90
|
+
}
|
|
83
91
|
const aiInterfaceUrl =
|
|
84
92
|
optionalTrim(process.env.AI_INTERFACE_URL) ??
|
|
85
93
|
optionalTrim(process.env.NEXT_PUBLIC_AI_INTERFACE_URL)
|
|
@@ -151,6 +159,12 @@ export function readStorefrontRuntimePublic(
|
|
|
151
159
|
optionalTrim(process.env.NEXT_PUBLIC_BROWSE_NAV_MODE)
|
|
152
160
|
)
|
|
153
161
|
}
|
|
162
|
+
if (publicKey === "NEXT_PUBLIC_STOREFRONT_INDUSTRY") {
|
|
163
|
+
return (
|
|
164
|
+
optionalTrim(process.env.STOREFRONT_INDUSTRY) ??
|
|
165
|
+
optionalTrim(process.env.NEXT_PUBLIC_STOREFRONT_INDUSTRY)
|
|
166
|
+
)
|
|
167
|
+
}
|
|
154
168
|
if (publicKey === "NEXT_PUBLIC_AI_INTERFACE_URL") {
|
|
155
169
|
return (
|
|
156
170
|
optionalTrim(process.env.AI_INTERFACE_URL) ??
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CertificationType } from "../helpers/parse-listing-controls"
|
|
2
|
+
import { readStorefrontRuntimePublic } from "../runtime/public-storefront-runtime-env"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Industry slugs match the platform's sales-channel slugs
|
|
6
|
+
* (INDUSTRY_SLUG_BY_CHANNEL_NAME in @sgftech/framework, e.g. "Food Ingredients"
|
|
7
|
+
* -> "food_ingredients"). Restated rather than imported: storefront-core does
|
|
8
|
+
* not depend on the backend framework package.
|
|
9
|
+
*/
|
|
10
|
+
const DEFAULT_INDUSTRY = "food_ingredients"
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Certifications that make sense for an industry's products. An industry not
|
|
14
|
+
* listed here (apparel, digital media, ...) has none, so the filter is hidden
|
|
15
|
+
* rather than showing food facets (FSSAI/Halal/...) on a store that cannot have
|
|
16
|
+
* them.
|
|
17
|
+
*/
|
|
18
|
+
const CERTIFICATION_TYPES_BY_INDUSTRY: Record<string, readonly CertificationType[]> = {
|
|
19
|
+
food_ingredients: ["fssai", "halal", "kosher", "organic", "vegan"],
|
|
20
|
+
polymer_specialities: ["iso", "gmp", "brc"],
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The certification filter options for this storefront's industry, from
|
|
25
|
+
* `NEXT_PUBLIC_STOREFRONT_INDUSTRY` (an industry sales-channel slug). Unset
|
|
26
|
+
* keeps the original food behaviour; an unrecognised industry gets none.
|
|
27
|
+
*/
|
|
28
|
+
export function getIndustryCertificationTypes(): readonly CertificationType[] {
|
|
29
|
+
const raw = readStorefrontRuntimePublic("NEXT_PUBLIC_STOREFRONT_INDUSTRY")
|
|
30
|
+
const industry = raw ? raw.trim().toLowerCase() : DEFAULT_INDUSTRY
|
|
31
|
+
return CERTIFICATION_TYPES_BY_INDUSTRY[industry] ?? []
|
|
32
|
+
}
|