2021-04-01 12:33:36 +00:00
|
|
|
import * as attributeRequest from "../../apiRequests/Attribute";
|
|
|
|
import * as categoryRequest from "../../apiRequests/Category";
|
|
|
|
import * as productRequest from "../../apiRequests/Product";
|
2021-07-05 10:21:35 +00:00
|
|
|
import {
|
|
|
|
createTypeProduct,
|
|
|
|
deleteProductType,
|
|
|
|
getProductTypes
|
|
|
|
} from "../../apiRequests/productType";
|
2021-07-09 09:43:45 +00:00
|
|
|
import { deleteAttributesStartsWith } from "../attributes.js/attributeUtils";
|
2021-02-04 11:15:27 +00:00
|
|
|
|
2021-03-12 12:14:18 +00:00
|
|
|
export function createProductInChannel({
|
|
|
|
name,
|
|
|
|
channelId,
|
|
|
|
warehouseId = null,
|
|
|
|
quantityInWarehouse = 10,
|
|
|
|
productTypeId,
|
|
|
|
attributeId,
|
|
|
|
categoryId,
|
|
|
|
price = 1,
|
|
|
|
isPublished = true,
|
|
|
|
isAvailableForPurchase = true,
|
2021-04-21 08:02:48 +00:00
|
|
|
visibleInListings = true,
|
|
|
|
collectionId = null,
|
2021-06-07 11:35:26 +00:00
|
|
|
description = null,
|
2021-07-12 08:50:50 +00:00
|
|
|
trackInventory = true,
|
|
|
|
weight = 1
|
2021-03-12 12:14:18 +00:00
|
|
|
}) {
|
|
|
|
let product;
|
2021-04-28 13:10:47 +00:00
|
|
|
let variantsList;
|
|
|
|
return productRequest
|
|
|
|
.createProduct({
|
|
|
|
attributeId,
|
|
|
|
name,
|
|
|
|
productTypeId,
|
|
|
|
categoryId,
|
|
|
|
collectionId,
|
|
|
|
description
|
|
|
|
})
|
2021-03-12 12:14:18 +00:00
|
|
|
.then(productResp => {
|
|
|
|
product = productResp;
|
|
|
|
productRequest.updateChannelInProduct({
|
|
|
|
productId: product.id,
|
|
|
|
channelId,
|
|
|
|
isPublished,
|
|
|
|
isAvailableForPurchase,
|
|
|
|
visibleInListings
|
2021-02-04 11:15:27 +00:00
|
|
|
});
|
2021-03-12 12:14:18 +00:00
|
|
|
})
|
|
|
|
.then(() => {
|
2021-04-28 13:10:47 +00:00
|
|
|
productRequest.createVariant({
|
2021-03-12 12:14:18 +00:00
|
|
|
productId: product.id,
|
|
|
|
sku: name,
|
2021-04-16 11:36:24 +00:00
|
|
|
attributeId,
|
2021-02-16 14:19:46 +00:00
|
|
|
warehouseId,
|
2021-03-12 12:14:18 +00:00
|
|
|
quantityInWarehouse,
|
2021-02-16 14:19:46 +00:00
|
|
|
channelId,
|
2021-06-07 11:35:26 +00:00
|
|
|
price,
|
2021-07-12 08:50:50 +00:00
|
|
|
trackInventory,
|
|
|
|
weight
|
2021-03-12 12:14:18 +00:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(variantsResp => {
|
2021-04-28 13:10:47 +00:00
|
|
|
variantsList = variantsResp;
|
|
|
|
return { product, variantsList };
|
2021-03-12 12:14:18 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function createTypeAttributeAndCategoryForProduct(
|
|
|
|
name,
|
|
|
|
attributeValues
|
|
|
|
) {
|
|
|
|
let attribute;
|
|
|
|
let productType;
|
|
|
|
let category;
|
2021-04-28 13:10:47 +00:00
|
|
|
return attributeRequest
|
2021-07-15 11:22:04 +00:00
|
|
|
.createAttribute({ name, attributeValues })
|
2021-03-12 12:14:18 +00:00
|
|
|
.then(attributeResp => {
|
|
|
|
attribute = attributeResp;
|
2021-07-05 10:21:35 +00:00
|
|
|
createTypeProduct({ name, attributeId: attributeResp.id });
|
2021-03-12 12:14:18 +00:00
|
|
|
})
|
|
|
|
.then(productTypeResp => {
|
|
|
|
productType = productTypeResp;
|
2021-04-28 13:10:47 +00:00
|
|
|
categoryRequest.createCategory(name);
|
2021-03-12 12:14:18 +00:00
|
|
|
})
|
|
|
|
.then(categoryResp => {
|
|
|
|
category = categoryResp;
|
|
|
|
return { attribute, category, productType };
|
|
|
|
});
|
|
|
|
}
|
|
|
|
export function deleteProductsStartsWith(startsWith) {
|
2021-07-09 09:43:45 +00:00
|
|
|
deleteAttributesStartsWith(startsWith);
|
2021-07-05 10:21:35 +00:00
|
|
|
cy.deleteElementsStartsWith(deleteProductType, getProductTypes, startsWith);
|
2021-03-12 12:14:18 +00:00
|
|
|
cy.deleteElementsStartsWith(
|
|
|
|
attributeRequest.deleteAttribute,
|
|
|
|
attributeRequest.getAttributes,
|
2021-03-23 10:15:39 +00:00
|
|
|
startsWith
|
2021-03-12 12:14:18 +00:00
|
|
|
);
|
|
|
|
cy.deleteElementsStartsWith(
|
|
|
|
categoryRequest.deleteCategory,
|
|
|
|
categoryRequest.getCategories,
|
2021-03-23 10:15:39 +00:00
|
|
|
startsWith
|
2021-03-12 12:14:18 +00:00
|
|
|
);
|
2021-02-04 11:15:27 +00:00
|
|
|
}
|