From 61406d9fe9dbdc096155895d9b6f3d08e9924bc9 Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Fri, 12 May 2023 12:45:31 -0400 Subject: [PATCH 1/3] removing duplicate recommender on no-results --- .../app/pages/product-list/partials/empty-results.jsx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx index b2ad82db78..5649996554 100644 --- a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx +++ b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx @@ -103,16 +103,6 @@ const EmptySearchResults = ({searchQuery, category}) => { mx={{base: -4, md: -8, lg: 0}} /> - - } - recommender={'products-in-all-categories'} - mx={{base: -4, md: -8, lg: 0}} - /> )} From 31723880a6737b3d46bfccd7e843b92c749de577 Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Fri, 12 May 2023 12:45:57 -0400 Subject: [PATCH 2/3] extract recommender values to constants --- packages/template-retail-react-app/app/constants.js | 12 ++++++++++++ .../app/hooks/use-add-to-cart-modal.js | 3 ++- .../app/pages/cart/index.jsx | 5 +++-- .../app/pages/product-detail/index.jsx | 7 ++++--- .../pages/product-list/partials/empty-results.jsx | 5 +++-- 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/template-retail-react-app/app/constants.js b/packages/template-retail-react-app/app/constants.js index 548a3f2b07..5d6aa4222f 100644 --- a/packages/template-retail-react-app/app/constants.js +++ b/packages/template-retail-react-app/app/constants.js @@ -90,3 +90,15 @@ export const TOAST_MESSAGE_REMOVED_FROM_WISHLIST = defineMessage({ id: 'global.info.removed_from_wishlist', defaultMessage: 'Item removed from wishlist' }) + +// Einstein recommender constants used in +export const EINSTEIN_RECOMMENDERS = { + ADD_TO_CART_MODAL: 'pdp-similar-items', + CART_RECENTLY_VIEWED: 'viewed-recently-einstein', + CART_MAY_ALSO_LIKE: 'product-to-product-einstein', + PDP_COMPLETE_SET: 'complete-the-set', + PDP_MIGHT_ALSO_LIKE: 'pdp-similar-items', + PDP_RECENTLY_VIEWED: 'viewed-recently-einstein', + EMPTY_SEARCH_RESULTS_TOP_SELLERS: 'home-top-revenue-for-category', + EMPTY_SEARCH_RESULTS_MOST_VIEWED: 'products-in-all-categories' +} diff --git a/packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.js b/packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.js index 706ad0f59c..36fdebb25f 100644 --- a/packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.js +++ b/packages/template-retail-react-app/app/hooks/use-add-to-cart-modal.js @@ -30,6 +30,7 @@ import RecommendedProducts from '../components/recommended-products' import {LockIcon} from '../components/icons' import {findImageGroupBy} from '../utils/image-groups-utils' import {getDisplayVariationValues} from '../utils/product-utils' +import {EINSTEIN_RECOMMENDERS} from '../constants' /** * This is the context for managing the AddToCartModal. @@ -229,7 +230,7 @@ export const AddToCartModal = () => { id="add_to_cart_modal.recommended_products.title.might_also_like" /> } - recommender={'pdp-similar-items'} + recommender={EINSTEIN_RECOMMENDERS.ADD_TO_CART_MODAL} products={[product]} mx={{base: -4, md: -8, lg: 0}} shouldFetch={() => product?.id} diff --git a/packages/template-retail-react-app/app/pages/cart/index.jsx b/packages/template-retail-react-app/app/pages/cart/index.jsx index 0a057ee70a..771a53c081 100644 --- a/packages/template-retail-react-app/app/pages/cart/index.jsx +++ b/packages/template-retail-react-app/app/pages/cart/index.jsx @@ -33,6 +33,7 @@ import useBasket from '../../commerce-api/hooks/useBasket' // Constants import { API_ERROR_MESSAGE, + EINSTEIN_RECOMMENDERS, TOAST_ACTION_VIEW_WISHLIST, TOAST_MESSAGE_ADDED_TO_WISHLIST } from '../../constants' @@ -302,7 +303,7 @@ const Cart = () => { id="cart.recommended_products.title.recently_viewed" /> } - recommender={'viewed-recently-einstein'} + recommender={EINSTEIN_RECOMMENDERS.CART_RECENTLY_VIEWED} mx={{base: -4, sm: -6, lg: 0}} /> @@ -313,7 +314,7 @@ const Cart = () => { id="cart.recommended_products.title.may_also_like" /> } - recommender={'product-to-product-einstein'} + recommender={EINSTEIN_RECOMMENDERS.CART_MAY_ALSO_LIKE} products={basket?.productItems} shouldFetch={() => basket?.basketId && basket.productItems?.length > 0 diff --git a/packages/template-retail-react-app/app/pages/product-detail/index.jsx b/packages/template-retail-react-app/app/pages/product-detail/index.jsx index acf512a56c..e1cb1a0823 100644 --- a/packages/template-retail-react-app/app/pages/product-detail/index.jsx +++ b/packages/template-retail-react-app/app/pages/product-detail/index.jsx @@ -31,6 +31,7 @@ import {HTTPNotFound} from 'pwa-kit-react-sdk/ssr/universal/errors' // constant import { API_ERROR_MESSAGE, + EINSTEIN_RECOMMENDERS, MAX_CACHE_AGE, TOAST_ACTION_VIEW_WISHLIST, TOAST_MESSAGE_ADDED_TO_WISHLIST @@ -294,7 +295,7 @@ const ProductDetail = ({category, product, isLoading}) => { id="product_detail.recommended_products.title.complete_set" /> } - recommender={'complete-the-set'} + recommender={EINSTEIN_RECOMMENDERS.PDP_COMPLETE_SET} products={[product]} mx={{base: -4, md: -8, lg: 0}} shouldFetch={() => product?.id} @@ -307,7 +308,7 @@ const ProductDetail = ({category, product, isLoading}) => { id="product_detail.recommended_products.title.might_also_like" /> } - recommender={'pdp-similar-items'} + recommender={EINSTEIN_RECOMMENDERS.PDP_MIGHT_ALSO_LIKE} products={[product]} mx={{base: -4, md: -8, lg: 0}} shouldFetch={() => product?.id} @@ -320,7 +321,7 @@ const ProductDetail = ({category, product, isLoading}) => { id="product_detail.recommended_products.title.recently_viewed" /> } - recommender={'viewed-recently-einstein'} + recommender={EINSTEIN_RECOMMENDERS.PDP_RECENTLY_VIEWED} mx={{base: -4, md: -8, lg: 0}} /> diff --git a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx index 5649996554..95b6350f13 100644 --- a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx +++ b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx @@ -12,6 +12,7 @@ import {Link as RouteLink} from 'react-router-dom' import {defineMessage, FormattedMessage, useIntl} from 'react-intl' import {SearchIcon} from '../../../components/icons' import RecommendedProducts from '../../../components/recommended-products' +import {EINSTEIN_RECOMMENDERS} from "../../../constants"; const contactUsMessage = defineMessage({ id: 'empty_search_results.link.contact_us', @@ -88,7 +89,7 @@ const EmptySearchResults = ({searchQuery, category}) => { id="empty_search_results.recommended_products.title.top_sellers" /> } - recommender={'home-top-revenue-for-category'} + recommender={EINSTEIN_RECOMMENDERS.EMPTY_SEARCH_RESULTS_TOP_SELLERS} mx={{base: -4, md: -8, lg: 0}} /> @@ -99,7 +100,7 @@ const EmptySearchResults = ({searchQuery, category}) => { id="empty_search_results.recommended_products.title.most_viewed" /> } - recommender={'products-in-all-categories'} + recommender={EINSTEIN_RECOMMENDERS.EMPTY_SEARCH_RESULTS_MOST_VIEWED} mx={{base: -4, md: -8, lg: 0}} /> From 0a99af12c9de460110edb020a7696321976642be Mon Sep 17 00:00:00 2001 From: Charles Lavery Date: Fri, 12 May 2023 12:59:53 -0400 Subject: [PATCH 3/3] linting --- .../app/pages/product-list/partials/empty-results.jsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx index 95b6350f13..e6885c6030 100644 --- a/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx +++ b/packages/template-retail-react-app/app/pages/product-list/partials/empty-results.jsx @@ -12,7 +12,7 @@ import {Link as RouteLink} from 'react-router-dom' import {defineMessage, FormattedMessage, useIntl} from 'react-intl' import {SearchIcon} from '../../../components/icons' import RecommendedProducts from '../../../components/recommended-products' -import {EINSTEIN_RECOMMENDERS} from "../../../constants"; +import {EINSTEIN_RECOMMENDERS} from '../../../constants' const contactUsMessage = defineMessage({ id: 'empty_search_results.link.contact_us', @@ -103,7 +103,6 @@ const EmptySearchResults = ({searchQuery, category}) => { recommender={EINSTEIN_RECOMMENDERS.EMPTY_SEARCH_RESULTS_MOST_VIEWED} mx={{base: -4, md: -8, lg: 0}} /> - )}