Skip to content

Commit

Permalink
BUG#PWA-3215 Products not found using URL key (#4183)
Browse files Browse the repository at this point in the history
* BUG#PWA-3124 Products not found using URL key

* BUG#PWA-3125 Products not found using URL key

---------

Co-authored-by: Aanchal Pawar <[email protected]>
  • Loading branch information
RaghavendraTirumalasetti and glo82145 authored Mar 18, 2024
1 parent caa8187 commit 7dd6bed
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
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

0 comments on commit 7dd6bed

Please sign in to comment.