Skip to content

Commit 2411b31

Browse files
glo82145glo11372
andauthored
PWA Product Recommendation venia (#4283)
* PWA Product Recommendation venia * adding item.prices * removing line * Product recommendation * change configure * Product recommendation * Product recommendation * Worked on modification * Worked on modification * Worked on modification --------- Co-authored-by: glo11372 <[email protected]>
1 parent e7eeba2 commit 2411b31

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

packages/peregrine/lib/hooks/useCustomerWishlistSkus/__tests__/useCustomerWishlistSkus.spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ test('pre-caches wishlist items', async () => {
4949
Object {
5050
"customerWishlistProducts": Array [
5151
"Dress",
52-
"Shirt",
5352
],
5453
}
5554
`);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const SUPPORTED_PRODUCT_TYPES = [
2+
'SimpleProduct',
3+
'ConfigurableProduct',
4+
'configurable',
5+
'simple'
6+
];
7+
8+
export const isSupportedProductType = productType => {
9+
return SUPPORTED_PRODUCT_TYPES.includes(productType);
10+
};

packages/peregrine/lib/talons/Gallery/useAddToCartButton.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ export const useAddToCartButton = props => {
3838

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

41-
const productType = item.__typename;
41+
const productType = item
42+
? item.__typename !== undefined
43+
? item.__typename
44+
: item.type
45+
: null;
46+
4247
const isUnsupportedProductType = UNSUPPORTED_PRODUCT_TYPES.includes(
4348
productType
4449
);
50+
4551
const isDisabled = isLoading || !isInStock || isUnsupportedProductType;
4652

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

5359
const handleAddToCart = useCallback(async () => {
5460
try {
55-
if (productType === 'SimpleProduct') {
61+
if (productType === 'SimpleProduct' || productType === 'simple') {
5662
setIsLoading(true);
5763

5864
const quantity = 1;
@@ -97,7 +103,10 @@ export const useAddToCartButton = props => {
97103
});
98104

99105
setIsLoading(false);
100-
} else if (productType === 'ConfigurableProduct') {
106+
} else if (
107+
productType === 'ConfigurableProduct' ||
108+
productType === 'configurable'
109+
) {
101110
const productLink = resourceUrl(
102111
`/${item.url_key}${urlSuffix || ''}`
103112
);

packages/peregrine/lib/talons/Gallery/useGalleryItem.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isSupportedProductType as isSupported } from '@magento/peregrine/lib/util/isSupportedProductType';
1+
import { isSupportedProductType as isSupported } from './isSupportedProductType';
22
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
33
import { useCallback, useEffect, useRef } from 'react';
44
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';
@@ -81,8 +81,11 @@ export const useGalleryItem = (props = {}) => {
8181
item
8282
]);
8383

84-
const productType = item ? item.__typename : null;
85-
84+
const productType = item
85+
? item.__typename !== undefined
86+
? item.__typename
87+
: item.type
88+
: null;
8689
const isSupportedProductType = isSupported(productType);
8790

8891
const wishlistButtonProps =

packages/venia-ui/lib/components/Gallery/item.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,21 @@ const GalleryItem = props => {
7070
</p>
7171
</div>
7272
);
73+
const currencyCode =
74+
price_range?.maximum_price?.final_price?.currency ||
75+
item.price.regularPrice.amount.currency;
7376

7477
// fallback to regular price when final price is unavailable
7578
const priceSource =
76-
price_range.maximum_price.final_price ||
77-
price_range.maximum_price.regular_price;
79+
(price_range?.maximum_price?.final_price !== undefined &&
80+
price_range?.maximum_price?.final_price !== null
81+
? price_range.maximum_price.final_price
82+
: item.prices.maximum.final) ||
83+
(price_range?.maximum_price?.regular_price !== undefined &&
84+
price_range?.maximum_price?.regular_price !== null
85+
? price_range.maximum_price.regular_price
86+
: item.prices.maximum.regular);
87+
const priceSourceValue = priceSource.value || priceSource;
7888

7989
// Hide the Rating component until it is updated with the new look and feel (PWA-2512).
8090
const ratingAverage = null;
@@ -112,11 +122,9 @@ const GalleryItem = props => {
112122
>
113123
<span>{name}</span>
114124
</Link>
125+
115126
<div data-cy="GalleryItem-price" className={classes.price}>
116-
<Price
117-
value={priceSource.value}
118-
currencyCode={priceSource.currency}
119-
/>
127+
<Price value={priceSourceValue} currencyCode={currencyCode} />
120128
</div>
121129

122130
<div className={classes.actionsContainer}>

0 commit comments

Comments
 (0)