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