Skip to content

Commit 6433303

Browse files
committed
fix: pass cart id to collection
1 parent 3ebc057 commit 6433303

File tree

7 files changed

+17
-6
lines changed

7 files changed

+17
-6
lines changed

src/app/collections/route.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export async function GET(request: NextRequest) {
88
const handle = searchParams.get("handle") ?? ""
99
const pageParam = searchParams.get("pageParam") ?? "0"
1010
const limit = searchParams.get("limit") ?? "12"
11+
const cart_id = searchParams.get("cart_id") ?? ""
1112

1213
const collection = await fetchCollection(handle)
1314
.then((res) => res)
@@ -19,6 +20,7 @@ export async function GET(request: NextRequest) {
1920
pageParam,
2021
id: collection.id,
2122
limit,
23+
cart_id,
2224
}).then((res) => res)
2325

2426
return NextResponse.json({
@@ -45,15 +47,18 @@ async function fetchCollectionProducts({
4547
pageParam,
4648
id,
4749
limit,
50+
cart_id,
4851
}: {
4952
pageParam: string
5053
id: string
5154
limit: string
55+
cart_id: string
5256
}) {
5357
const { products, count, offset } = await medusaRequest(
5458
"GET",
5559
`/products?collection_id[]=${id}`,
5660
{
61+
cart_id,
5762
limit,
5863
offset: pageParam,
5964
expand: "variants,variants.prices",

src/lib/data/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ export const fetchProductsList = async ({
126126
...queryParams,
127127
})
128128

129+
console.log({ pageParam, ...queryParams })
130+
131+
console.log({ products, count, offset })
132+
129133
return {
130134
response: { products, count },
131135
nextPage: count > offset + 12 ? offset + 12 : null,

src/modules/collections/templates/index.tsx

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,14 @@ const CollectionTemplate: React.FC<CollectionTemplateProps> = ({
8686
<h1>{collection.title}</h1>
8787
</div>
8888
<ul className="grid grid-cols-2 small:grid-cols-3 medium:grid-cols-4 gap-x-4 gap-y-8">
89-
{previews.map((p) => (
90-
<li key={p.id}>
91-
{console.log(p)}
92-
<ProductPreview {...p} />
93-
</li>
94-
))}
89+
{previews.map((p) => {
90+
console.log(p)
91+
return (
92+
<li key={p.id}>
93+
<ProductPreview {...p} />
94+
</li>
95+
)
96+
})}
9597
{isFetchingNextPage &&
9698
repeat(getNumberOfSkeletons(infiniteData?.pages)).map((index) => (
9799
<li key={index}>
File renamed without changes.

0 commit comments

Comments
 (0)