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

Feature: Extract einstein RefArch-specific values to constant #1200

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 12 additions & 0 deletions packages/template-retail-react-app/app/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <RecommendedProducts/>
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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}
Expand Down
5 changes: 3 additions & 2 deletions packages/template-retail-react-app/app/pages/cart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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}}
/>

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -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}
Expand All @@ -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}}
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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}}
/>

Expand All @@ -99,20 +100,10 @@ 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}}
/>

<RecommendedProducts
title={
<FormattedMessage
defaultMessage="Most Viewed"
id="empty_search_results.recommended_products.title.most_viewed"
/>
}
recommender={'products-in-all-categories'}
mx={{base: -4, md: -8, lg: 0}}
/>
</Stack>
</Fragment>
)}
Expand Down