2021-03-12 12:14:18 +00:00
|
|
|
import { getProductDetails } from "../../apiRequests/storeFront/ProductDetails";
|
2021-02-12 14:36:13 +00:00
|
|
|
|
2021-03-04 14:51:55 +00:00
|
|
|
export const isProductVisible = (resp, name) => {
|
|
|
|
const product = resp.body.data.product;
|
|
|
|
return product !== null && product.name === name;
|
|
|
|
};
|
2021-02-25 10:40:07 +00:00
|
|
|
|
2021-03-04 14:51:55 +00:00
|
|
|
export const isProductAvailableForPurchase = resp => {
|
|
|
|
const product = resp.body.data.product;
|
|
|
|
return product.isAvailableForPurchase;
|
|
|
|
};
|
2021-03-04 12:35:45 +00:00
|
|
|
|
2021-03-04 14:51:55 +00:00
|
|
|
export const isProductVisibleInSearchResult = (resp, productName) => {
|
|
|
|
const productsList = resp.body.data.products;
|
|
|
|
return (
|
|
|
|
productsList.totalCount !== 0 &&
|
|
|
|
productsList.edges[0].node.name === productName
|
|
|
|
);
|
|
|
|
};
|
2021-03-01 11:54:08 +00:00
|
|
|
|
2021-03-12 14:57:02 +00:00
|
|
|
export const getProductVariants = (productId, channelSlug) => {
|
2021-03-12 12:14:18 +00:00
|
|
|
getProductDetails(productId, channelSlug).then(resp => {
|
2021-03-02 17:26:57 +00:00
|
|
|
const variantsList = resp.body.data.product.variants;
|
|
|
|
return variantsList.map(element => ({
|
|
|
|
name: element.name,
|
|
|
|
price: element.pricing.price.gross.amount
|
|
|
|
}));
|
|
|
|
});
|
2021-03-12 14:57:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getProductPrice = (productId, channelSlug) =>
|
|
|
|
getProductDetails(productId, channelSlug).then(
|
|
|
|
resp => resp.body.data.product.variants[0].pricing.price.gross.amount
|
|
|
|
);
|