Skip to content

Commit 5ef7953

Browse files
authored
chore(medusa,core-flows): include variant images in product export (#14886)
## Summary **What** — What changes are introduced in this PR? Include variant images in product exports. **Why** — Why are these changes relevant or necessary? Information is incomplete. **How** — How have these changes been implemented? Added logic to handle constructing the wildcard columns for variant images. **Testing** — How have these changes been tested, or how can the reviewer test the feature? Integration tests. --- ## Examples Provide examples or code snippets that demonstrate how this feature works, or how it can be used in practice. This helps with documentation and ensures maintainers can quickly understand and verify the change. ```ts // Example usage ``` --- ## Checklist Please ensure the following before requesting a review: - [x] I have added a **changeset** for this PR - Every non-breaking change should be marked as a **patch** - To add a changeset, run `yarn changeset` and follow the prompts - [x] The changes are covered by relevant **tests** - [x] I have verified the code works as intended locally - [x] I have linked the related issue(s) if applicable --- ## Additional Context Add any additional context, related issues, or references that might help the reviewer understand this PR.
1 parent 76343de commit 5ef7953

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.changeset/lovely-lemons-repeat.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@medusajs/core-flows": patch
3+
"@medusajs/medusa": patch
4+
---
5+
6+
chore(medusa,core-flows): include variant images in product export

integration-tests/http/__tests__/product/admin/product-export.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,8 @@ medusaIntegrationTestRunner({
306306
"Variant Material": "",
307307
"Variant Metadata": "",
308308
"Variant Mid Code": "",
309+
"Variant Image 1": "test-image.png",
310+
"Variant Image 2": "test-image-2.png",
309311
"Variant Option 1 Name": "size",
310312
"Variant Option 1 Value": "large",
311313
"Variant Option 2 Name": "color",
@@ -365,6 +367,8 @@ medusaIntegrationTestRunner({
365367
"Variant Material": "",
366368
"Variant Metadata": "",
367369
"Variant Mid Code": "",
370+
"Variant Image 1": "test-image.png",
371+
"Variant Image 2": "test-image-2.png",
368372
"Variant Option 1 Name": "size",
369373
"Variant Option 1 Value": "small",
370374
"Variant Option 2 Name": "color",
@@ -424,7 +428,8 @@ medusaIntegrationTestRunner({
424428
"Variant Material": "",
425429
"Variant Metadata": "",
426430
"Variant Mid Code": "",
427-
"Variant Thumbnail": "",
431+
"Variant Image 1": "test-image.png",
432+
"Variant Image 2": "test-image-2.png",
428433
"Variant Option 1 Name": "size",
429434
"Variant Option 1 Value": "large",
430435
"Variant Option 2 Name": "color",
@@ -516,6 +521,8 @@ medusaIntegrationTestRunner({
516521
"Variant Material": "",
517522
"Variant Metadata": "",
518523
"Variant Mid Code": "",
524+
"Variant Image 1": "test-image.png",
525+
"Variant Image 2": "test-image-2.png",
519526
"Variant Option 1 Name": "size",
520527
"Variant Option 1 Value": "large",
521528
"Variant Option 2 Name": "color",
@@ -576,6 +583,8 @@ medusaIntegrationTestRunner({
576583
"Variant Material": "",
577584
"Variant Metadata": "",
578585
"Variant Mid Code": "",
586+
"Variant Image 1": "test-image.png",
587+
"Variant Image 2": "test-image-2.png",
579588
"Variant Option 1 Name": "size",
580589
"Variant Option 1 Value": "small",
581590
"Variant Option 2 Name": "color",
@@ -699,6 +708,8 @@ medusaIntegrationTestRunner({
699708
"Variant Metadata": "",
700709
"Variant Mid Code": "",
701710
"Variant Thumbnail": "",
711+
"Variant Image 1": "test-image.png",
712+
"Variant Image 2": "test-image-2.png",
702713
"Variant Option 1 Name": "size",
703714
"Variant Option 1 Value": "large",
704715
"Variant Option 2 Name": "color",
@@ -790,6 +801,8 @@ medusaIntegrationTestRunner({
790801
"Variant Metadata": "",
791802
"Variant Mid Code": "",
792803
"Variant Thumbnail": "",
804+
"Variant Image 1": "test-image.png",
805+
"Variant Image 2": "test-image-2.png",
793806
"Variant Option 1 Name": "size",
794807
"Variant Option 1 Value": "large",
795808
"Variant Option 2 Name": "color",

packages/core/core-flows/src/product/helpers/normalize-for-export.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,23 @@ const normalizeVariantForExport = (
148148
{}
149149
)
150150

151+
const flattenedImages = variant.images?.reduce(
152+
(acc: Record<string, string>, image, idx) => {
153+
acc[beautifyKey(`variant_image_${idx + 1}`)] = image.url
154+
return acc
155+
},
156+
{}
157+
)
158+
151159
const res = {
152160
...prefixFields(variant, "variant"),
153161
...flattenedPrices,
154162
...flattenedOptions,
163+
...flattenedImages,
155164
} as any
156165
delete res["Variant Price Set"]
157166
delete res["Variant Options"]
167+
delete res["Variant Images"]
158168

159169
return res
160170
}

packages/medusa/src/api/admin/products/query-config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export const defaultAdminProductFields = [
7575
"variants.prices.price_rules.value",
7676
"variants.prices.price_rules.attribute",
7777
"*variants.options",
78+
"*variants.images",
7879
"*sales_channels",
7980
]
8081

0 commit comments

Comments
 (0)