2021-04-21 08:02:48 +00:00
|
|
|
import { getValueWithDefault } from "../utils/Utils";
|
|
|
|
|
|
|
|
export function getProductDetails(productId, channelId, auth = "token") {
|
|
|
|
const privateMetadataLine = getValueWithDefault(
|
|
|
|
auth === "auth",
|
|
|
|
`privateMetadata{key value}`
|
|
|
|
);
|
2021-03-12 12:14:18 +00:00
|
|
|
const query = `fragment BasicProductFields on Product {
|
2021-03-12 14:57:02 +00:00
|
|
|
id
|
|
|
|
name
|
2021-04-21 08:02:48 +00:00
|
|
|
attributes{
|
|
|
|
attribute{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
category{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
collections{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
description
|
|
|
|
seoTitle
|
|
|
|
slug
|
|
|
|
seoDescription
|
|
|
|
rating
|
|
|
|
metadata{
|
|
|
|
key
|
|
|
|
value
|
|
|
|
}
|
|
|
|
${privateMetadataLine}
|
|
|
|
productType{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fragment Price on TaxedMoney {
|
|
|
|
gross {
|
|
|
|
amount
|
|
|
|
currency
|
2021-02-23 14:30:52 +00:00
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fragment ProductVariantFields on ProductVariant {
|
|
|
|
id
|
|
|
|
sku
|
|
|
|
name
|
|
|
|
pricing {
|
|
|
|
price {
|
|
|
|
...Price
|
2021-02-25 09:51:52 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
query ProductDetails{
|
|
|
|
product(id: "${productId}", channel: "${channelId}") {
|
|
|
|
...BasicProductFields
|
|
|
|
variants {
|
|
|
|
...ProductVariantFields
|
2021-02-25 09:51:52 +00:00
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
isAvailable
|
|
|
|
isAvailableForPurchase
|
|
|
|
availableForPurchase
|
2021-02-25 09:51:52 +00:00
|
|
|
}
|
2021-03-12 14:57:02 +00:00
|
|
|
}`;
|
2021-04-21 08:02:48 +00:00
|
|
|
return cy.sendRequestWithQuery(query, auth);
|
2021-02-23 14:30:52 +00:00
|
|
|
}
|