Skip to content

Commit

Permalink
fix(medusa): Product option values in CSV Export (#5781)
Browse files Browse the repository at this point in the history
* #5712

* fix-5712 added a comment

* fix/5712 - changing to context object

* Create yellow-games-reflect.md

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
  • Loading branch information
mortenengel and olivermrbl authored Dec 6, 2023
1 parent 7d04f95 commit 9b447f9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/yellow-games-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): Product option values in CSV Export
12 changes: 9 additions & 3 deletions packages/medusa/src/strategies/batch-jobs/product/export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,17 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy {

const columnNameNameValue = columnNameValueBuilder(i)

// option values are not guaranteed to keep the same order as options on product. Pick them in the same order as product options
this.columnsDefinition[columnNameNameValue] = {
name: columnNameNameValue,
exportDescriptor: {
accessor: (variant: ProductVariant) =>
variant?.options[i]?.value ?? "",
accessor: (
variant: ProductVariant,
context?: { product?: Product }
) =>
variant?.options.find(
(ov) => ov.option_id === context!.product!.options[i]?.id
)?.value ?? "",
entityName: "variant",
},
}
Expand Down Expand Up @@ -597,7 +603,7 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy {
}
if (columnSchema.entityName === "variant") {
const formattedContent = csvCellContentFormatter(
columnSchema.accessor(variant)
columnSchema.accessor(variant, { product: product })
)
variantLineData.push(formattedContent)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ export type ProductExportDescriptor =
entityName: Extract<ProductExportColumnSchemaEntity, "product">
}
| {
accessor: (variant: ProductVariant) => string
accessor: (
variant: ProductVariant,
context?: { product?: Product }
) => string
entityName: Extract<ProductExportColumnSchemaEntity, "variant">
}

Expand Down

0 comments on commit 9b447f9

Please sign in to comment.