**What**
Since the release of the Tax API the line item totals calculations on orders with gift cards have been wrong. To understand the bug consider the below order:
Region:
- tax_rate: 25%
- gift_cards_taxable: true
Order:
- applied gift card: 1000
- items:
- A: unit_price: 1000
- B: unit_price: 500
- Subtotal: 1500
**Previous calculation method**
1. Determine how much of the gift card is used for each item using `item_total / subtotal * gift_card_amount`:
- Item A: 1000/1500 * 1000 = 666.67
- Item B: 500/1500 * 1000 = 333.33
2. Calculate line item totals including taxes using `(unit_price - gift_card) * (1 + tax_rate)`
- Item A: 1000 - 666.67 = 333.33; vat amount -> 83.33
- Item B: 500 - 333.33 = 166.67; vat amount -> 41.67
3. Add up the line item totals: order subtotal = 500; vat amount = 125; total = 625
This is all correct at the totals level; but at the line item level we should still use the "original prices" i.e. the line item total for item a should be (1000 * 1.25) = 1250 with a tax amount of 250.
**New calculation method**
1. Use default totals calculations
- Item A: subtotal: 1000, tax_total: 250, total: 1250
- Item B: subtotal: 500, tax_total: 125, total: 625
2. Add up the line item totals: subtotal: 1500, tax_total: 375, total: 1875
3. Reduce total with gift card: subtotal: 1500 - 1000 = 500, tax_total: 375 - 250 = 125, total = 625
Totals can now be forwarded correctly to accounting plugins.
Fixes CORE-310.
**What**
- Add `feature_flags` string array to store response
**Why**
- to provide conditional ui in admin corresponding to enabled features
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
* feat: add feature flag loading in projects
* fix: make feature flag consume itself
* fix: rename container registration to featureFlagRouter
* fix: refactor
* behavioral feature flags
* add environment to server
* limit "useTemplateDb" to non feature flagged migrations
* filter migrations and entities according to those which are enabled in the environment
* run only migrations that are enabled when running 'medusa migrations run'
* add logging to the featureflag loader
* initial implementation of featureFlagEntity
* column descriptors
* initial startServerWithEnv (to be refactored)
* update commands
* final touches
* update loaders to fix unit tests
* enable all batch job tests
* update seed method
* add api test capabilities
* revert batch job test
* revert formatting changes
* pr feedback
* pr feedback
* remove unused imports
* rename feature flag decorators
* pr feedback
Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
* fix: return prices when lsiting products with a query
* add: integration test
* fix: integration test
* fix: move WithRequiredProperty to common.ts
* fix: comment
* feat(medusa): Add /admin/products/:id/variants end point
* test(medusa): Fix get-variants test casees
* feat(medusa): Include the config to the ProdutService#retrieveVariants as a method parameter
* feat(medusa): Improve get-variants endpoint
* feat(medusa): Improve get-variants endpoint
* test(medusa): Fix unit tests
* test(medusa): Fix unit tests
* feat(medusa): Improve typings
* feat(medusa): Update according to feedback
* feat(medusa): Update according to feedback
* test(medusa): Fix list-variants tests
* feat(medusa): Getting the variants from the product end point should use the productVariantService
* fix(medusa): list-variants expand possibly undefined
* Fix(medusa): List-variants endpoint
* fix(medusa): Tests suite for list-variant
* test(integration-tests): Fix yarn lock
* test(integration-tests): Fix yarn lock
* add customer groups to price list factory
* add integration test for filtering price lists by customer group
* normalize list price list query
* add customer groups to list-price-list queryparameters
* query based on customergroups if they exist for price lists
* remove verbose flag
* add another price list with a customer group
* remove console.log
* pr feedback
* add query type to repository
* add query type to repository
* set groups to undefined instead of deleting parameter
* remove wildcard destructing
* make buildQuery type specific to price lists
* steal Adriens types
* fix(medusa): support searching for price lists (#1407)
* delete instead of settting groups to undefined
* add groups to query with q
* use simple customer group factory instead of manual creation
* Update simple-customer-group-factory.ts
* remove comma that breaks integration-tests
Co-authored-by: Zakaria El Asri <33696020+zakariaelas@users.noreply.github.com>
* refactor(medusa): Cleanup + fix
* styles(medusa): Lint
* refactor(medusa): Finalize cleanup
* feat(medusa): Prefer the usage of bulk operations instead of sequential/conccurent operations
* feat(medusa): Improve cart service
* refactor(medusa): Explicitly specifying protected methods when needed as well as enfore the usage of the local transactionManager_ in those methods
* tests(medusa): Fix tests according to the new changes
* feat(medusa): Cleanup after rebase
* test(medusa): Fix cart service tests