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

PWA Product Recommendation venia #4283

Merged
merged 11 commits into from
Jun 27, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ test('pre-caches wishlist items', async () => {
Object {
"customerWishlistProducts": Array [
"Dress",
"Shirt",
],
}
`);
Expand Down
10 changes: 10 additions & 0 deletions packages/peregrine/lib/talons/Gallery/isSupportedProductType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const SUPPORTED_PRODUCT_TYPES = [
'SimpleProduct',
'ConfigurableProduct',
'configurable',
'simple'
];

export const isSupportedProductType = productType => {
return SUPPORTED_PRODUCT_TYPES.includes(productType);
};
15 changes: 12 additions & 3 deletions packages/peregrine/lib/talons/Gallery/useAddToCartButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ export const useAddToCartButton = props => {

const isInStock = item.stock_status === 'IN_STOCK';

const productType = item.__typename;
const productType = item
? item.__typename !== undefined
? item.__typename
: item.type
: null;

const isUnsupportedProductType = UNSUPPORTED_PRODUCT_TYPES.includes(
productType
);

const isDisabled = isLoading || !isInStock || isUnsupportedProductType;

const history = useHistory();
Expand All @@ -52,7 +58,7 @@ export const useAddToCartButton = props => {

const handleAddToCart = useCallback(async () => {
try {
if (productType === 'SimpleProduct') {
if (productType === 'SimpleProduct' || productType === 'simple') {
setIsLoading(true);

const quantity = 1;
Expand Down Expand Up @@ -97,7 +103,10 @@ export const useAddToCartButton = props => {
});

setIsLoading(false);
} else if (productType === 'ConfigurableProduct') {
} else if (
productType === 'ConfigurableProduct' ||
productType === 'configurable'
) {
const productLink = resourceUrl(
`/${item.url_key}${urlSuffix || ''}`
);
Expand Down
9 changes: 6 additions & 3 deletions packages/peregrine/lib/talons/Gallery/useGalleryItem.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSupportedProductType as isSupported } from '@magento/peregrine/lib/util/isSupportedProductType';
import { isSupportedProductType as isSupported } from './isSupportedProductType';
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
import { useCallback, useEffect, useRef } from 'react';
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';
Expand Down Expand Up @@ -81,8 +81,11 @@ export const useGalleryItem = (props = {}) => {
item
]);

const productType = item ? item.__typename : null;

const productType = item
? item.__typename !== undefined
? item.__typename
: item.type
: null;
const isSupportedProductType = isSupported(productType);

const wishlistButtonProps =
Expand Down
20 changes: 14 additions & 6 deletions packages/venia-ui/lib/components/Gallery/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,21 @@ const GalleryItem = props => {
</p>
</div>
);
const currencyCode =
price_range?.maximum_price?.final_price?.currency ||
item.price.regularPrice.amount.currency;

// fallback to regular price when final price is unavailable
const priceSource =
price_range.maximum_price.final_price ||
price_range.maximum_price.regular_price;
(price_range?.maximum_price?.final_price !== undefined &&
price_range?.maximum_price?.final_price !== null
? price_range.maximum_price.final_price
: item.prices.maximum.final) ||
(price_range?.maximum_price?.regular_price !== undefined &&
price_range?.maximum_price?.regular_price !== null
? price_range.maximum_price.regular_price
: item.prices.maximum.regular);
const priceSourceValue = priceSource.value || priceSource;

// Hide the Rating component until it is updated with the new look and feel (PWA-2512).
const ratingAverage = null;
Expand Down Expand Up @@ -112,11 +122,9 @@ const GalleryItem = props => {
>
<span>{name}</span>
</Link>

<div data-cy="GalleryItem-price" className={classes.price}>
<Price
value={priceSource.value}
currencyCode={priceSource.currency}
/>
<Price value={priceSourceValue} currencyCode={currencyCode} />
</div>

<div className={classes.actionsContainer}>
Expand Down