### What
Creating a swap on an order with a discount leads to an incorrect difference due.
**Scenario**
- Create a store with minimum 2 products (Prod A, Prod B)
- Create a discount that only works for Prod A
- Create an order for Prod A with the discount applied
- Create a swap between Prod A and Prod B
**Expected outcome**
We would expect the difference_due amount to come out to the sum of:
- -1 * (price of prod a - discount applied to prod a)
- price of prod b
**Actual outcome**
Instead the discount is applied across both products when calculating difference due. This results in a total that is instead the sum of:
- -1 * (price of prod a - discount applied to prod a)
- price of prod b - discount on prod b ignoring the condition
### How
Adds `line_item.adjustments` to relations in cart retrieval prior to setting the difference_due to car total
Fixes CORE-361
**What**
Naive fix to allow carts with 100% discount to be completed.
**Why**
Discount total is wrongly calculated if `items` and `items.adjustments` is not included in relations upon retrieving the cart.
**Thought**
This is yet another example of why we need to rethink and refactor totals computation to not depend on what is provided by the user.
* feat(medusa): Allow to create/update object sales channels assignment
* feat(medusa): cleanup
* feat(medusa): Update oas
* feat(medusa): Only add relation if required
* feat(medusa): Add feature flag decorators
* style(medusa): PR feedback
* feat(medusa): Remove circular by moving sales channel product existence check to the repo layer
* feat(medusa): Reduce selected column as they are not necessary
* feat(medusa): Refactor repository and usage
* feat(medusa): Improve entity name formatting
* feat(medusa): Add feature flag to the service
* fix(medusa): typo
* test(medusa): fix unit tests
* feat(medusa): include feedback
* feat(medusa): Adds validator pipe for Sales Channel existence (#1930)
* feat(medusa): Allow to create/update object sales channels assignment
* feat(medusa): cleanup
* feat(medusa): Update oas
* feat(medusa): Only add relation if required
* feat(medusa): Add feature flag decorators
* style(medusa): PR feedback
* feat(medusa): Remove circular by moving sales channel product existence check to the repo layer
* feat(medusa): Reduce selected column as they are not necessary
* feat(medusa): Refactor repository and usage
* feat(medusa): Improve entity name formatting
* feat(medusa): Add feature flag to the service
* fix(medusa): typo
* test(medusa): fix unit tests
* feat(medusa): Adds validator pipe for Sales Channel existence
* feat: Move product payload classes to types file
* fix unit tests
* fix integration test
Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
* feat(medusa): Revert base repository and related
* feat(medusa): cleanup
* remove base repo export
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
* wip: validate line item SC
* fix: repository type, remove relation, use sc id, check if cart has associated sc
* feat: setup tests and seeder, change entity retrieval in cart service method
* feat: remove repo usage and method, use Adrien's method from product service to check sc association, add test cases, add seeder entities, accept flag for validating sc on the endpoint
* feat: add a unit test to ensure validation method is called if flag is passed
* feat: allow `validate_sales_channels` flag in other relevant endpoints
* fix: typo
* fix: flag rename
* fix: correct FF in test suites
* fix: address PR feedback
* fix: change error message
* feat: remove query params, guard with FF, refactor
* feat: guard validation in the service
* refactor: rename validation method
* refactor: reorganise tests
* wip: cleanup test file
* wip: revert cart seeder changes use factories
* fix: remove seeder, update mocks
* fix: method name
* fix: units, validate by default
* git: resolve merge conflicts
* refactor: separate line item sales chanel units
Co-authored-by: fPolic <frane@medusajs.com>
What
Allow to create a cart with a sales channel, otherwise the default one is attached.
Also allow to update the sales channel on an existing cart and in that case the line items that does not belongs to the new sales channel attached are removed
How
Updating existing end points and service method to integrate the new requirements
Tests
Add new integration tests
Fixes CORE-270
Fixes CORE-272
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
**What**
Allow to query the products and orders by sales channels
**How**
Updating the existing end points and repositories (if necessary) to take a new query params that is sales_channel_id as an array of string
**Tests**
Add new integration tests
Fixes CORE-295
Fixes CORE-288
What
Support sales channel remove product batch in medusa, medusa-js and medusa-react
How
By implementing a new endpoint and the associated service method as well as the repository methods.
Medusa-js new removeProductd method in the resource
Medusa-react new hook in the mutations
Tests
Endpoint test
Service test
Integration test
Hook tests
Fixes CORE-292
**What**
Support sales channel list in medusa, medusa-js and medusa-react
**How**
By implementing a new endpoint and the associated service method as well as the repository methods.
Medusa-js new list method in the resource
Medusa-react new hook in the queries
**Tests**
Endpoint test
Service test
Integration test
Hook tests
Fixes CORE-280
**What**
- Add `transformQuery` to get endpoints for product, order and cart
- ensure that the default relations (when getting a singular entity) includes sales channels when enabled
- Add `EmptyQueryParams` class in common types to prevent query parameters while using `transformQuery`
- update product-, order- and cartFactory to include sales channels if provided
- remove `packages/medusa/src/controllers/products/admin-list-products.ts`
**Testing**
- expands sales channel for single order
- expands sales channels for orders with expand parameter
- returns single product with sales channel
- expands sales channels for products with expand parameter
- returns cart with sales channel for single cart
Fixes CORE-293
Co-authored-by: Sebastian Rindom <7554214+srindom@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
**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>
* fix: caching deps + add true parallelization to integration tests api
* fix: github action
* chore: upgrade to yarn berry (#1762)
* init migration
* remove: yarn.lock from all pkgs
* fix: build script in pkgs
* adjust yarn config
* fix: yarn.lock and yarnrc.yml
* fix: github actions
* fix: wrong type
* fix (medusa-react): use dts-cli instead of tsdx
* fix: yarn.lock
* fix: yarn v
* fix: prepare script
* add: comment on why we need to downgrade yarn before medusa-dev
* chore: move to Turborepo (#1763)
* increase number of parallel nodes
* fix (medusa-fulfillment-webshipper): build script
* fix: use new version of medusa-dev
* fix: rename cache-bootstrap to cache-deps
* 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>
* add initial testing files
* prepare for github
* remove empty files
* remove ids
* set user and password for postgres service
* remove node setup
* remove unused flag from yarn install
* correct medusajs package
* arguments for create-medusa project
* make create command into one line
* working directory update
* update workflow
* add build
* run scripts from medusa-cli
* move scripts to medusa-cli
* add install
* get server output
* rename build to install
* update login script to get feedback
* add arguments to login script
* add argument for directory to get-product
* pass cli-test to get-products script
* add wait command
* fix waiting
* update wait-for-server
* echo status
* update start testing
* refactor code into test-action
* add list config for testing
* include shell
* update get-products script
* test to see if action fails when given wrong input
* use custom action for testing devleopment server and extend waiting for server to spin up
* update actions
* remove cache version
* yarn and build in cli-test directory
* update core
* update working directories
* test working dir after cd up
* update
* fix directories
* update directories
* use setup server action
* invoke correct action
* test
* update cli action
* remove action
* test with medusa-dev
* remove medusa dev for now
* test
* include medusa-dev
* remove invalid medusa new command
* try moving project one dir up
* add silent to curl output from live server wait
* update seed data directory
* test
* remove sub workflow
* add matrix and postgres override for medusa-config
* fix matrix syntax
* add database url to job
* update yaml
* cli should fail on logging in
* create setup server action
* update test-server
* update scripts
* run scripts directory instead of cli scripts
* make directories current
* remove tests from cli
* run only on pr
* update name
* remove batch job model (for testing purposes)
* remove ls from test server action
* get content from develop
* undo changes to generate reference
* remove comments from scripts
* test failing command
* redo migrate command failing
* move scripts into interation tests
* Apply suggestions from code review
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>