File tree Expand file tree Collapse file tree 4 files changed +12
-3
lines changed
Expand file tree Collapse file tree 4 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import React from 'react';
22import { useCompareProducts , useTranslation } from './app-state' ;
33import { ProductMainImage } from './ProductMainImage' ;
44import { Product } from './service' ;
5+ import { isProductAvailable } from './helper' ;
56import { ReactComponent as RecycleBinIcon } from './images/icons/ic_trash.svg' ;
67
78import './CompareProducts.scss' ;
@@ -42,7 +43,7 @@ export const CompareProducts: React.FC = () => {
4243 < td key = { product . id } >
4344 < div className = "compareproducts__name" > { product . name } </ div >
4445 < div className = "compareproducts__price" > { product . meta . display_price . without_tax . formatted } </ div >
45- < div className = "compareproducts__availability" > { product . meta . stock . availability === 'in-stock' ? t ( 'available' ) : t ( 'out-of-stock' ) } </ div >
46+ < div className = "compareproducts__availability" > { isProductAvailable ( product ) ? t ( 'available' ) : t ( 'out-of-stock' ) } </ div >
4647 < div className = "compareproducts__addtocart" >
4748 < span
4849 className = "moltin-buy-button"
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { loadProductBySlug } from './service';
55import { CompareCheck } from './CompareCheck' ;
66import { ProductMainImage } from './ProductMainImage' ;
77import { useTranslation , useCurrency } from './app-state' ;
8+ import { isProductAvailable } from './helper' ;
89
910import './Product.scss' ;
1011
@@ -37,7 +38,7 @@ export const Product: React.FC = () => {
3738 { product . meta . display_price . without_tax . formatted }
3839 </ div >
3940 < div className = "product__availability" >
40- { product . meta . stock . availability === 'in-stock' ? t ( 'available' ) : t ( 'out-of-stock' ) }
41+ { isProductAvailable ( product ) ? t ( 'available' ) : t ( 'out-of-stock' ) }
4142 </ div >
4243 < div className = "product__comparecheck" >
4344 < CompareCheck product = { product } />
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom';
55import { CompareCheck } from './CompareCheck' ;
66import { ProductMainImage } from './ProductMainImage' ;
77import { useTranslation } from './app-state' ;
8+ import { isProductAvailable } from './helper' ;
89
910import './ProductThumbnail.scss' ;
1011
@@ -33,7 +34,7 @@ export const ProductThumbnail: React.FC<ProductThumbnailProps> = (props) => {
3334 { props . product . meta . display_price . without_tax . formatted }
3435 </ div >
3536 < div className = "productthumbnail__availability" >
36- { props . product . meta . stock . availability === 'in-stock' ? t ( 'available' ) : t ( 'out-of-stock' ) }
37+ { isProductAvailable ( props . product ) ? t ( 'available' ) : t ( 'out-of-stock' ) }
3738 </ div >
3839 < div className = { `productthumbnail__comparecheck` } >
3940 < CompareCheck product = { props . product } />
Original file line number Diff line number Diff line change 1+ import { Product } from "./service" ;
2+
3+ export function isProductAvailable ( product : Product ) : boolean {
4+ // we assume that product is available if we are not managing the stock
5+ return ! product . manage_stock || product . meta ?. stock ?. availability === 'in-stock' ;
6+ }
You can’t perform that action at this time.
0 commit comments