2021-02-12 14:36:13 +00:00
|
|
|
import ProductDetails from "../../apiRequests/frontShop/ProductDetails";
|
|
|
|
import Search from "../../apiRequests/frontShop/Search";
|
|
|
|
|
|
|
|
class FrontShopProductUtils {
|
|
|
|
isProductVisible(productId, channelSlug, name) {
|
|
|
|
const productDetails = new ProductDetails();
|
|
|
|
return productDetails
|
|
|
|
.getProductDetails(productId, channelSlug)
|
2021-02-19 09:57:25 +00:00
|
|
|
.then(productDetailsResp => {
|
|
|
|
const product = productDetailsResp.body.data.product;
|
|
|
|
return product !== null && product.name === name;
|
|
|
|
});
|
2021-02-12 14:36:13 +00:00
|
|
|
}
|
|
|
|
isProductAvailableForPurchase(productId, channelSlug) {
|
|
|
|
const productDetails = new ProductDetails();
|
|
|
|
return productDetails
|
|
|
|
.getProductDetails(productId, channelSlug)
|
2021-02-19 09:57:25 +00:00
|
|
|
.then(
|
|
|
|
productDetailsResp =>
|
|
|
|
productDetailsResp.body.data.product.isAvailableForPurchase
|
2021-02-12 14:36:13 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
isProductVisibleInSearchResult(productName, channelSlug) {
|
|
|
|
const search = new Search();
|
|
|
|
return search
|
|
|
|
.searchInShop(productName, channelSlug)
|
2021-02-19 09:57:25 +00:00
|
|
|
.then(
|
|
|
|
resp =>
|
|
|
|
resp.body.data.products.totalCount !== 0 &&
|
|
|
|
resp.body.data.products.edges[0].node.name === productName
|
|
|
|
);
|
2021-02-12 14:36:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
export default FrontShopProductUtils;
|