Skip to content

Commit

Permalink
fix(core): use customerId in product api (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemoya committed Jul 8, 2024
1 parent f350e7b commit 5d0975b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/fuzzy-ties-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@bigcommerce/catalyst-core": patch
---

Use customerId in product API to get correct product information.
4 changes: 4 additions & 0 deletions core/app/api/product/[id]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/
import { NextRequest, NextResponse } from 'next/server';

import { getSessionCustomerId } from '~/auth';
import { getChannelIdFromLocale } from '~/channels.config';
import { client } from '~/client';
import { graphql } from '~/client/graphql';
Expand All @@ -22,6 +23,8 @@ const GetProductQuery = graphql(
);

export const GET = async (request: NextRequest, { params }: { params: { id: string } }) => {
const customerId = await getSessionCustomerId();

if (request.headers.get('x-catalyst-product-sheet') !== 'true') {
return NextResponse.json(
{ status: 'error', message: 'Endpoint only available for product-sheet component.' },
Expand All @@ -48,6 +51,7 @@ export const GET = async (request: NextRequest, { params }: { params: { id: stri
document: GetProductQuery,
variables: { productId: Number(id), optionValueIds },
channelId: getChannelIdFromLocale(locale),
customerId,
});

return NextResponse.json(data.site.product);
Expand Down

0 comments on commit 5d0975b

Please sign in to comment.