fix(utils,core-flows): fix import erasing tags, categories and others (#13724)
* fix(utils,core-flows): fix import erasins tags, categories and others * Create pink-pumpkins-sin.md * fix changeset * fix tests
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/core-flows": patch
|
||||||
|
"@medusajs/utils": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix(utils,core-flows): fix import erasing tags, categories and others
|
||||||
@@ -26,7 +26,6 @@ describe("CSV processor", () => {
|
|||||||
{
|
{
|
||||||
"toCreate": {
|
"toCreate": {
|
||||||
"sweatshirt": {
|
"sweatshirt": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatshirt",
|
"handle": "sweatshirt",
|
||||||
@@ -52,7 +51,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
||||||
"title": "Medusa Sweatshirt",
|
"title": "Medusa Sweatshirt",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -99,7 +97,6 @@ describe("CSV processor", () => {
|
|||||||
{
|
{
|
||||||
"toCreate": {
|
"toCreate": {
|
||||||
"sweatshirt": {
|
"sweatshirt": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatshirt",
|
"handle": "sweatshirt",
|
||||||
@@ -127,7 +124,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
||||||
"title": "Medusa Sweatshirt",
|
"title": "Medusa Sweatshirt",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -216,7 +212,6 @@ describe("CSV processor", () => {
|
|||||||
{
|
{
|
||||||
"toCreate": {
|
"toCreate": {
|
||||||
"sweatshirt": {
|
"sweatshirt": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatshirt",
|
"handle": "sweatshirt",
|
||||||
@@ -251,7 +246,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
||||||
"title": "Medusa Sweatshirt",
|
"title": "Medusa Sweatshirt",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -343,7 +337,6 @@ describe("CSV processor", () => {
|
|||||||
{
|
{
|
||||||
"toCreate": {
|
"toCreate": {
|
||||||
"shorts": {
|
"shorts": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of classic shorts. With our cotton shorts, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of classic shorts. With our cotton shorts, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "shorts",
|
"handle": "shorts",
|
||||||
@@ -372,7 +365,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/shorts-vintage-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/shorts-vintage-front.png",
|
||||||
"title": "Medusa Shorts",
|
"title": "Medusa Shorts",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -464,7 +456,6 @@ describe("CSV processor", () => {
|
|||||||
"weight": 400,
|
"weight": 400,
|
||||||
},
|
},
|
||||||
"sweatpants": {
|
"sweatpants": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatpants",
|
"handle": "sweatpants",
|
||||||
@@ -493,7 +484,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatpants-gray-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatpants-gray-front.png",
|
||||||
"title": "Medusa Sweatpants",
|
"title": "Medusa Sweatpants",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -585,7 +575,6 @@ describe("CSV processor", () => {
|
|||||||
"weight": 400,
|
"weight": 400,
|
||||||
},
|
},
|
||||||
"t-shirt": {
|
"t-shirt": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of a classic T-shirt. With our cotton T-shirts, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of a classic T-shirt. With our cotton T-shirts, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "t-shirt",
|
"handle": "t-shirt",
|
||||||
@@ -627,7 +616,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/tee-black-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/tee-black-front.png",
|
||||||
"title": "Medusa T-Shirt",
|
"title": "Medusa T-Shirt",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -813,7 +801,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
"toUpdate": {
|
"toUpdate": {
|
||||||
"prod_01JSXX3ZVW4M4RS0NH4MSWCQWA": {
|
"prod_01JSXX3ZVW4M4RS0NH4MSWCQWA": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of a classic sweatshirt. With our cotton sweatshirt, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatshirt",
|
"handle": "sweatshirt",
|
||||||
@@ -843,7 +830,6 @@ describe("CSV processor", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatshirt-vintage-front.png",
|
||||||
"title": "Medusa Sweatshirt",
|
"title": "Medusa Sweatshirt",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -935,7 +921,6 @@ describe("CSV processor", () => {
|
|||||||
"weight": 400,
|
"weight": 400,
|
||||||
},
|
},
|
||||||
"prod_01JT598HEWAE555V0A6BD602MG": {
|
"prod_01JT598HEWAE555V0A6BD602MG": {
|
||||||
"categories": [],
|
|
||||||
"description": "Every programmer's best friend.",
|
"description": "Every programmer's best friend.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "coffee-mug-v3",
|
"handle": "coffee-mug-v3",
|
||||||
@@ -955,7 +940,6 @@ describe("CSV processor", () => {
|
|||||||
],
|
],
|
||||||
"sales_channels": [],
|
"sales_channels": [],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/coffee-mug.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/coffee-mug.png",
|
||||||
"title": "Medusa Coffee Mug",
|
"title": "Medusa Coffee Mug",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -983,7 +967,6 @@ describe("CSV processor", () => {
|
|||||||
"weight": 400,
|
"weight": 400,
|
||||||
},
|
},
|
||||||
"prod_01JT598HEX26EHDG7SRK37Q3FG": {
|
"prod_01JT598HEX26EHDG7SRK37Q3FG": {
|
||||||
"categories": [],
|
|
||||||
"description": "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
|
"description": "Reimagine the feeling of classic sweatpants. With our cotton sweatpants, everyday essentials no longer have to be ordinary.",
|
||||||
"discountable": true,
|
"discountable": true,
|
||||||
"handle": "sweatpants-v2",
|
"handle": "sweatpants-v2",
|
||||||
@@ -1009,7 +992,6 @@ describe("CSV processor", () => {
|
|||||||
],
|
],
|
||||||
"sales_channels": [],
|
"sales_channels": [],
|
||||||
"status": "published",
|
"status": "published",
|
||||||
"tags": [],
|
|
||||||
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatpants-gray-front.png",
|
"thumbnail": "https://medusa-public-images.s3.eu-west-1.amazonaws.com/sweatpants-gray-front.png",
|
||||||
"title": "Medusa Sweatpants",
|
"title": "Medusa Sweatpants",
|
||||||
"variants": [
|
"variants": [
|
||||||
@@ -1123,7 +1105,7 @@ describe("CSV processor", () => {
|
|||||||
const csvRow = {
|
const csvRow = {
|
||||||
"Product Handle": "test-product",
|
"Product Handle": "test-product",
|
||||||
"Variant Title": "Test Variant",
|
"Variant Title": "Test Variant",
|
||||||
"Variant Metadata": 'invalid json',
|
"Variant Metadata": "invalid json",
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalized = CSVNormalizer.preProcess(csvRow, 1)
|
const normalized = CSVNormalizer.preProcess(csvRow, 1)
|
||||||
@@ -1259,7 +1241,9 @@ describe("CSV processor", () => {
|
|||||||
const processor = new CSVNormalizer([normalized])
|
const processor = new CSVNormalizer([normalized])
|
||||||
const result = processor.proccess()
|
const result = processor.proccess()
|
||||||
|
|
||||||
expect(result.toCreate[`test-product-${value}`].is_giftcard).toBe(expected)
|
expect(result.toCreate[`test-product-${value}`].is_giftcard).toBe(
|
||||||
|
expected
|
||||||
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
isPresent,
|
isPresent,
|
||||||
tryConvertToNumber,
|
|
||||||
tryConvertToBoolean,
|
|
||||||
MedusaError,
|
MedusaError,
|
||||||
normalizeCSVValue,
|
normalizeCSVValue,
|
||||||
|
tryConvertToBoolean,
|
||||||
|
tryConvertToNumber,
|
||||||
} from "../common"
|
} from "../common"
|
||||||
import { AdminCreateProduct, AdminCreateProductVariant } from "@medusajs/types"
|
import { AdminCreateProduct, AdminCreateProductVariant } from "@medusajs/types"
|
||||||
|
|
||||||
@@ -89,11 +89,14 @@ function processAsJson<Output>(
|
|||||||
return (csvRow, _, rowNumber, output) => {
|
return (csvRow, _, rowNumber, output) => {
|
||||||
const value = csvRow[inputKey]
|
const value = csvRow[inputKey]
|
||||||
if (isPresent(value)) {
|
if (isPresent(value)) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === "string") {
|
||||||
try {
|
try {
|
||||||
output[outputKey] = JSON.parse(value);
|
output[outputKey] = JSON.parse(value)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw createError(rowNumber, `Invalid value provided for "${inputKey}". Expected a valid JSON string, received "${value}"`);
|
throw createError(
|
||||||
|
rowNumber,
|
||||||
|
`Invalid value provided for "${inputKey}". Expected a valid JSON string, received "${value}"`
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,18 +167,22 @@ function processAsCounterValue<Output extends Record<string, any[]>>(
|
|||||||
outputKey: keyof Output
|
outputKey: keyof Output
|
||||||
): ColumnProcessor<Output> {
|
): ColumnProcessor<Output> {
|
||||||
return (csvRow, rowColumns, _, output) => {
|
return (csvRow, rowColumns, _, output) => {
|
||||||
|
const matchingColumns = rowColumns.filter((rowKey) => inputMatcher.test(rowKey))
|
||||||
|
|
||||||
|
// Only initialize the array if there are matching columns in the CSV
|
||||||
|
if (matchingColumns.length > 0) {
|
||||||
output[outputKey] = output[outputKey] ?? []
|
output[outputKey] = output[outputKey] ?? []
|
||||||
|
|
||||||
const existingIds = output[outputKey].map((item) => item[arrayItemKey])
|
const existingIds = output[outputKey].map((item) => item[arrayItemKey])
|
||||||
|
|
||||||
rowColumns
|
matchingColumns.forEach((rowKey) => {
|
||||||
.filter((rowKey) => inputMatcher.test(rowKey))
|
|
||||||
.forEach((rowKey) => {
|
|
||||||
const value = csvRow[rowKey]
|
const value = csvRow[rowKey]
|
||||||
if (!existingIds.includes(value) && isPresent(value)) {
|
if (!existingIds.includes(value) && isPresent(value)) {
|
||||||
output[outputKey].push({ [arrayItemKey]: value })
|
output[outputKey].push({ [arrayItemKey]: value })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user