Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG#PWA-3215 Products not found using URL key #4183

Merged
merged 4 commits into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const RESOLVE_URL = gql`
# eslint-disable-next-line @graphql-eslint/require-id-when-available
... on ProductInterface {
uid
sku
__typename
}
# eslint-disable-next-line @graphql-eslint/require-id-when-available
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ export const GET_STORE_CONFIG_DATA = gql`
}
`;

export const GET_PRODUCT_DETAIL_QUERY = gql`
query getProductDetailForProductPage($urlKey: String!) {
products(filter: { url_key: { eq: $urlKey } }) {
export const GET_SINGLE_PRODUCT_DETAIL_QUERY = gql`
query getProductDetailForProductPage($sku: String!) {
products(filter: { sku: { eq: $sku } }) {
items {
id
uid
Expand All @@ -27,5 +27,5 @@ export const GET_PRODUCT_DETAIL_QUERY = gql`

export default {
getStoreConfigData: GET_STORE_CONFIG_DATA,
getProductDetailQuery: GET_PRODUCT_DETAIL_QUERY
getSingleProductDetailQuery: GET_SINGLE_PRODUCT_DETAIL_QUERY
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import { useEventingContext } from '../../../context/eventing';
* @returns {Bool} result.product - The product's details.
*/
export const useProduct = props => {
const { mapProduct } = props;
const { mapProduct, sku } = props;

const operations = mergeOperations(DEFAULT_OPERATIONS, props.operations);
const { getStoreConfigData, getProductDetailQuery } = operations;
const { getStoreConfigData, getSingleProductDetailQuery } = operations;
const { pathname } = useLocation();
const [
,
Expand All @@ -45,12 +45,12 @@ export const useProduct = props => {
const productUrlSuffix = storeConfigData?.storeConfig?.product_url_suffix;
const urlKey = productUrlSuffix ? slug.replace(productUrlSuffix, '') : slug;

const { error, loading, data } = useQuery(getProductDetailQuery, {
const { error, loading, data } = useQuery(getSingleProductDetailQuery, {
fetchPolicy: 'cache-and-network',
nextFetchPolicy: 'cache-first',
skip: !storeConfigData,
variables: {
urlKey
sku
}
});

Expand Down
5 changes: 3 additions & 2 deletions packages/venia-ui/lib/RootComponents/Product/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ import ProductShimmer from './product.shimmer';
*/

const Product = props => {
const { __typename: productType } = props;
const { __typename: productType, sku } = props;
const talonProps = useProduct({
mapProduct
mapProduct,
sku
});

const { error, loading, product } = talonProps;
Expand Down