2021-02-04 11:15:27 +00:00
|
|
|
class Product {
|
|
|
|
getFirstProducts(first, search) {
|
2021-02-16 14:19:46 +00:00
|
|
|
const filter = search
|
|
|
|
? `, filter:{
|
|
|
|
search:"${search}"
|
|
|
|
}`
|
|
|
|
: "";
|
2021-02-04 11:15:27 +00:00
|
|
|
const query = `query{
|
2021-02-02 11:34:10 +00:00
|
|
|
products(first:${first}${filter}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
variants{
|
2021-02-04 11:15:27 +00:00
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
2021-02-16 14:19:46 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(query)
|
|
|
|
.then(resp => resp.body.data.products.edges);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateChannelInProduct(
|
|
|
|
productId,
|
|
|
|
channelId,
|
2021-02-18 15:28:29 +00:00
|
|
|
isPublished = true,
|
|
|
|
isAvailableForPurchase = true,
|
|
|
|
visibleInListings = true
|
2021-02-04 11:15:27 +00:00
|
|
|
) {
|
|
|
|
const mutation = `mutation{
|
|
|
|
productChannelListingUpdate(id:"${productId}",
|
|
|
|
input:{
|
|
|
|
addChannels:{
|
|
|
|
channelId:"${channelId}"
|
|
|
|
isPublished:${isPublished}
|
|
|
|
isAvailableForPurchase:${isAvailableForPurchase}
|
2021-02-08 09:23:12 +00:00
|
|
|
visibleInListings:${visibleInListings}
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
}){
|
|
|
|
product{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-02-18 18:28:01 +00:00
|
|
|
cy.sendRequestWithQuery(mutation);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateChannelPriceInVariant(variantId, channelId) {
|
|
|
|
const mutation = `mutation{
|
2021-02-18 15:28:29 +00:00
|
|
|
productVariantChannelListingUpdate(id: "${variantId}", input: {
|
|
|
|
channelId: "${channelId}"
|
2021-02-04 11:15:27 +00:00
|
|
|
price: 10
|
|
|
|
costPrice: 10
|
2021-02-18 15:28:29 +00:00
|
|
|
}){
|
|
|
|
productChannelListingErrors{
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} `;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
createProduct(attributeId, name, productType, category) {
|
|
|
|
const mutation = `mutation{
|
2021-02-02 11:34:10 +00:00
|
|
|
productCreate(input:{
|
|
|
|
attributes:[{
|
|
|
|
id:"${attributeId}"
|
|
|
|
}]
|
|
|
|
name:"${name}"
|
|
|
|
productType:"${productType}"
|
|
|
|
category:"${category}"
|
|
|
|
}){
|
|
|
|
product{
|
|
|
|
id
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-02 11:34:10 +00:00
|
|
|
productErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
createVariant(
|
|
|
|
productId,
|
|
|
|
sku,
|
|
|
|
warehouseId,
|
|
|
|
quantity,
|
|
|
|
channelId,
|
|
|
|
price = 1,
|
|
|
|
costPrice = 1
|
|
|
|
) {
|
|
|
|
const mutation = `mutation{
|
2021-02-18 15:28:29 +00:00
|
|
|
productVariantBulkCreate(product: "${productId}", variants: {
|
|
|
|
attributes: []
|
|
|
|
sku: "${sku}"
|
|
|
|
channelListings: {
|
|
|
|
channelId: "${channelId}"
|
|
|
|
price: "${price}"
|
|
|
|
costPrice: "${costPrice}"
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
2021-02-18 15:28:29 +00:00
|
|
|
stocks: {
|
|
|
|
warehouse: "${warehouseId}"
|
|
|
|
quantity: ${quantity}
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-18 18:28:01 +00:00
|
|
|
}) {
|
|
|
|
productVariants{
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
bulkProductErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
2021-02-02 11:34:10 +00:00
|
|
|
}`;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
createTypeProduct(name, attributeId, slug = name) {
|
|
|
|
const mutation = `mutation{
|
2021-02-18 15:28:29 +00:00
|
|
|
productTypeCreate(input: {
|
|
|
|
name: "${name}"
|
2021-02-02 11:34:10 +00:00
|
|
|
slug: "${slug}"
|
2021-02-18 15:28:29 +00:00
|
|
|
isShippingRequired: true
|
|
|
|
productAttributes: "${attributeId}"
|
|
|
|
}){
|
|
|
|
productErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
productType{
|
|
|
|
id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} `;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteProduct(productId) {
|
|
|
|
const mutation = `mutation{
|
2021-02-18 15:28:29 +00:00
|
|
|
productDelete(id: "${productId}"){
|
|
|
|
productErrors{
|
|
|
|
field
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} `;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
|
|
|
|
getProductTypes(first, search) {
|
|
|
|
const query = `query{
|
2021-02-02 11:34:10 +00:00
|
|
|
productTypes(first:${first}, filter:{
|
|
|
|
search:"${search}"
|
|
|
|
}){
|
|
|
|
edges{
|
|
|
|
node{
|
|
|
|
id
|
|
|
|
name
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
|
|
|
}`;
|
2021-02-16 14:19:46 +00:00
|
|
|
return cy
|
|
|
|
.sendRequestWithQuery(query)
|
|
|
|
.then(resp => resp.body.data.productTypes.edges);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
deleteProductType(productTypeId) {
|
|
|
|
const mutation = `mutation{
|
2021-02-02 11:34:10 +00:00
|
|
|
productTypeDelete(id:"${productTypeId}"){
|
|
|
|
productErrors{
|
|
|
|
field
|
|
|
|
message
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|
2021-02-02 11:34:10 +00:00
|
|
|
}
|
|
|
|
}`;
|
2021-02-04 11:15:27 +00:00
|
|
|
return cy.sendRequestWithQuery(mutation);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Product;
|