Skip to content

Commit

Permalink
fix(medusa): export product prices in human-readable format (medusajs…
Browse files Browse the repository at this point in the history
…#3739)

* fix: export product prices in human-readable format

* feat: add changesets

* fix: update snaps

* fix: update more snaps

---------

Co-authored-by: fPolic <frane@medusajs.com>
  • Loading branch information
fPolic and fPolic authored Apr 7, 2023
1 parent d55d865 commit 08f85fa
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/gold-garlics-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): invalidate price selection cache on update
5 changes: 5 additions & 0 deletions .changeset/nine-chicken-cheat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/medusa": patch
---

fix(medusa): align prices formating in the import & export strategies
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Array [
"product-export-strategy-product-1;test-product-product-1;Test product;;\\"test-product-description-1
test-product-description-1 second line
test-product-description-1 third line
forth line\\";draft;;;;;;;;;;Test collection 1;test-collection1;test-type-1;123_1;true;;profile_1;profile_type_1;product-export-strategy-variant-1;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;100;110;130;;test-option-1;option 1 value 1;test-option-2;option 2 value 1;test-image.png
forth line\\";draft;;;;;;;;;;Test collection 1;test-collection1;test-type-1;123_1;true;;profile_1;profile_type_1;product-export-strategy-variant-1;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;1;1.1;1.3;;test-option-1;option 1 value 1;test-option-2;option 2 value 1;test-image.png
",
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-2;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;;;110;test-option;Option 1 value 1;;;test-image.png
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-2;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;;;1.1;test-option;Option 1 value 1;;;test-image.png
",
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-3;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;120;;;test-option;Option 1 Value 1;;;test-image.png
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-3;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;1.2;;;test-option;Option 1 Value 1;;;test-image.png
",
]
`;
Expand All @@ -23,14 +23,14 @@ Array [
"product-export-strategy-product-1;test-product-product-1;Test product;;\\"test-product-description-1
test-product-description-1 second line
test-product-description-1 third line
forth line\\";draft;;;;;;;;;;Test collection 1;test-collection1;test-type-1;123_1;true;;profile_1;profile_type_1;product-export-strategy-variant-1;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;100;110;130;;test-option-1;option 1 value 1;test-option-2;option 2 value 1;test-image.png;SC 1;SC 1;\\"SC 1
forth line\\";draft;;;;;;;;;;Test collection 1;test-collection1;test-type-1;123_1;true;;profile_1;profile_type_1;product-export-strategy-variant-1;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;1;1.1;1.3;;test-option-1;option 1 value 1;test-option-2;option 2 value 1;test-image.png;SC 1;SC 1;\\"SC 1
SC 1 second line
SC 1 third line
SC 1 forth line\\";;;
",
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-2;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;;;110;test-option;Option 1 value 1;;;test-image.png;SC 1;SC 1;SC 1;SC 2;SC 2;SC 2
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-2;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;;;1.1;test-option;Option 1 value 1;;;test-image.png;SC 1;SC 1;SC 1;SC 2;SC 2;SC 2
",
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-3;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;120;;;test-option;Option 1 Value 1;;;test-image.png;SC 1;SC 1;SC 1;SC 2;SC 2;SC 2
"product-export-strategy-product-2;test-product-product-2;Test product;;test-product-description;draft;;;;;;;;;;Test collection;test-collection2;test-type;123;true;;profile_2;profile_type_2;product-export-strategy-variant-3;Test variant;test-sku;test-barcode;10;false;true;;;;;;;;;;1.2;;;test-option;Option 1 Value 1;;;test-image.png;SC 1;SC 1;SC 1;SC 2;SC 2;SC 2
",
]
`;
19 changes: 16 additions & 3 deletions packages/medusa/src/strategies/batch-jobs/product/export.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { EntityManager } from "typeorm"

import { humanizeAmount } from "medusa-core-utils"

import { AbstractBatchJobStrategy, IFileService } from "../../../interfaces"
import { Product, ProductVariant } from "../../../models"
import { BatchJobService, ProductService } from "../../../services"
Expand Down Expand Up @@ -460,7 +463,12 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy {
priceData.currency_code.toLowerCase()
)
})
return price?.amount?.toString() ?? ""
return price?.amount
? humanizeAmount(
price?.amount,
priceData.currency_code!
).toString()
: ""
},
entityName: "variant",
},
Expand All @@ -487,7 +495,12 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy {
priceData.region?.id?.toLowerCase()
)
})
return price?.amount?.toString() ?? ""
return price?.amount
? humanizeAmount(
price?.amount,
priceData.region!.currency_code!
).toString()
: ""
},
entityName: "variant",
},
Expand Down Expand Up @@ -546,7 +559,7 @@ export default class ProductExportStrategy extends AbstractBatchJobStrategy {
}

/**
* Return the maximun number of each relation that must appears in the export.
* Return the maximum number of each relation that must appears in the export.
* The number of item of a relation can vary between 0-Infinity and therefore the number of columns
* that will be added to the export correspond to that number
* @param products - The main entity to get the relation shape from
Expand Down

0 comments on commit 08f85fa

Please sign in to comment.