Commit Graph

251 Commits

Author SHA1 Message Date
Oliver Windall Juhl
0ba63c70b0 fix(medusa): Complete cart with 100% discount (#2032)
**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.
2022-08-16 09:21:01 +00:00
Adrien de Peretti
bd031ef7ad feat(medusa:) Convert PaymentProvider + PaymentProviderInterface to TS + (#1773)
* feat(payments): Refactor core Payment related

* fix(medusa): typings

* test(unit): fix suite

* test(unit): fix suite

* feat(medusa): Improve payment provider container typings

* fix(medusa): typings

* styles(medusa): renove comments

* feat(medusa): cleanup

* feat(medusa): Add uniq constraint on payment session and idem key on create-payment-session end point

* fix(medusa): migration

* fix(medusa): create payment session

* feat(medusa): cleanup
2022-08-10 17:26:16 +02:00
Adrien de Peretti
b3b69d7117 fix(integration-tests): Use asymmetric matcher for arrays in tests (#1992) 2022-08-07 11:50:12 +02:00
Oliver Windall Juhl
b1f88f917b chore: Update yarn.lock + jest matchers in integration test (#1989) 2022-08-04 10:16:55 +02:00
Philip Korsholm
6251aecdaa Feat/convert return reason service to typescript (#1961)
**What**
- Convert return reason service to typescript

Fixes CORE-355
2022-08-02 11:40:11 +00:00
Adrien de Peretti
3b28998421 feat(medusa): Create/update Product Sales Channels (#1870)
* 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>
2022-07-28 20:19:30 +02:00
Philip Korsholm
5ce8839c54 add is_disabled to create sales channel (#1928)
**What**
- include `is_disabled` when creating a sales channel

**Why**
- To enable creation of draft sales channels
2022-07-28 14:17:11 +00:00
Frane Polić
3fbe8d7d08 feat(medusa): Validate LineItems in SalesChannel (#1871)
* 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>
2022-07-27 21:39:06 +02:00
Adrien de Peretti
df66378535 feat(medusa): Attach or update cart sales channel (#1873)
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>
2022-07-27 16:54:05 +00:00
Sebastian Rindom
8c283ac3b0 fix(medusa): Calculated price on cart shipping options (#1878) 2022-07-20 11:04:31 +02:00
Adrien de Peretti
110c995a6a feat(medusa): Allow to query order/product by SC (#1867)
**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
2022-07-19 16:54:20 +00:00
Adrien de Peretti
f35ea5156a feat(medusa, medusa-js, medusa-react): Bulk add Products to a SalesChannel (#1833) 2022-07-14 16:39:44 +02:00
Adrien de Peretti
cdd91974f9 feat(medusa, medusa-js, medusa-react): Start implementing remove batch products on a sales channel (#1842)
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
2022-07-13 19:40:23 +00:00
Oliver Windall Juhl
7162972318 fix(medusa): Free text search for PriceList Products (#1843)
**What**
Fixes #1831 and #1336
2022-07-13 14:06:33 +00:00
Adrien de Peretti
a1a5848827 feat(medusa, medusa-js, medusa-react): Implement Sales Channel list (#1815)
**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
2022-07-13 10:28:53 +00:00
Sebastian Rindom
c20d720040 fix(medusa-payment-klarna): Fix division by zero on free shipping (#1840) 2022-07-13 09:26:45 +02:00
Oliver Windall Juhl
4e375c2203 feat(medusa): Prevent default channel from being deleted (#1835)
**What**
Prevent the default channel from being deleted

Fixes CORE-317
2022-07-13 06:41:03 +00:00
Sebastian Rindom
e539bdc620 chore: Fix CI pipeline (#1839) 2022-07-12 20:14:34 +02:00
Philip Korsholm
19f35ba6aa Feat(medusa, medusa-js, medusa-react): Include sales channels in related queries as an optional expand parameter (#1816)
**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>
2022-07-11 16:45:01 +00:00
Sebastian Rindom
39f2c0c15e fix(medusa): calculates correct taxes and totals on order with gift cards (#1807)
**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.
2022-07-11 12:18:43 +00:00
Philip Korsholm
3e197e3adf feat(medusa): Add feature flags to store response (#1819)
**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>
2022-07-11 09:42:58 +00:00
Oliver Windall Juhl
02967f95b1 fix(medusa): Refresh adjustments when region on cart is changed (#1827)
* fix(medusa): Refresh adjustments when region on cart is changed

* fix test

* Fix unit test

* fix: integration tests

* fix: comment
2022-07-11 10:51:55 +02:00
Zakaria El Asri
9fa4238ee4 chore: improve ci pipeline (#1764)
* 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
2022-07-10 12:11:11 +02:00
Adrien de Peretti
2d03634cfc feat(medusa, medusa-js, medusa-react): Implement Sales Channel deletion (#1804) 2022-07-07 10:47:51 +02:00
Frane Polić
0d1624cf6a feat(medusa, medusa-js, medusa-react): Implement Sales Channel creation (#1795) 2022-07-06 22:18:05 +02:00
Philip Korsholm
9d19cc0818 feat(medusa, medusa-js, medusa-react): Implement Sales Channel update (#1797) 2022-07-06 15:44:09 +02:00
Adrien de Peretti
263a661031 feat(medusa, medusa-js, medusa-react): Implement Sales Channel retrieval (#1793) 2022-07-06 12:17:26 +02:00
Philip Korsholm
413b2850bf feat(medusa): SC service (#1784)
* add sales channel service and empty api index

* add integration testing file

* add tyeps

* remove ts directive

* add sales channel test

* update import

* remove unused import

* fix tests
2022-07-05 14:40:10 +02:00
Philip Korsholm
41681b45b1 Feat(medusa): implement feature flags (#1768)
* 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>
2022-07-04 15:39:30 +02:00
Adrien de Peretti
e53c06eab8 feat(medusa): Apply query transformers to Collection and CustomerGroups (#1667) 2022-07-02 13:01:52 +02:00
Sebastian Rindom
fee0f88a62 fix: add shipping taxes (#1759)
**What**
Adds taxes to the shipping prices when listing in admin. Allows store operators to see correct prices when processing returns.
2022-07-02 10:35:16 +00:00
Philip Korsholm
bf47d1aecd feat(medusa): Add batch strategy for order exports (#1603) 2022-06-29 09:54:37 +02:00
Adrien de Peretti
c0f624ad3b feat(medusa): Allow to filter the batch jobs with nullable date (#1747) 2022-06-29 09:44:56 +02:00
Adrien de Peretti
fb7abbf407 feat(medusa): Add file size calculation for product export (#1726) 2022-06-28 15:27:36 +02:00
Sebastian Rindom
c6dc9086cf feat(medusa): Add line item totals to cart totals decoration (#1740) 2022-06-28 12:11:47 +02:00
Sebastian Rindom
2a32609b74 fix(medusa): Normalizes email before saving customer (#1719) 2022-06-27 10:56:12 +02:00
Adrien de Peretti
89cb717461 fix(medusa): Product export strategy (#1713) 2022-06-27 10:48:56 +02:00
Adrien de Peretti
7b09b8c36c feat(medusa/product-export-strategy): Implement the Product export strategy (#1688) 2022-06-22 23:42:31 +02:00
Zakaria El Asri
f0be31120f refactor(medusa): Migrate ProductService to TS (#1625)
* refactor: product service

* fix: type errors in consumers

* fix: use Status enum instead of ProductStatus

* fix: remove ProductStatus

* fix: rename ProductStatus

* fix: product model nullable fields

* fix: explicit typecasting in listVariants

* fix: use atomicPhase in public methods

* fix: use transactionManager in protected methods

* fix: remove disable eslint rule comment

* fix: retrieveVariants relations

* fix: retrieveVariants

* fix: FilterableProductProps validation

* fix: nullable thumbnail

* fix: tests by making model column types more explicit

* move upsert method to repo layer

* fix: unit tests

* fix: integration tests

* fix: product tags query + integration test

* fix: rename FindWithRelationsOptions to FindWithoutRelationsOptions

* fix (productRepository): use string[] for relations

* refactor: extract price relation filtering logic into util

* fix: failing unit test

* rename DTO suffix to Input suffix

* fix: missing awaits

* fix: check for images and tags length

* fix: remove unneeded function

* extract types used in product service to types folder

* fix: use text instead of varchar

* remove: reorderOptions from ProductService

* fix: product model

* fix: add private retrieve method

* fix: conflicts

* fix: failing unit test

* fix: integration test

* fix: remove ProductSelector type

* fix: remove validateId

* fix: use spread operator

* fix: repo method typings

* fix: remove comment
2022-06-20 10:50:46 +01:00
olivermrbl
c85ef984cc Merge branch 'master' into develop 2022-06-19 12:59:08 +02:00
Oliver Windall Juhl
6b23208d63 fix(medusa): Include adjustments when authorizing payment (#1697) 2022-06-19 12:58:47 +02:00
Adrien de Peretti
453688682c feat(medusa): Support batch-job API (#1547)
* feat(medusa): Implement confirm batch job end point

* feat(medusa): Implement confirm batch-job end point

* feat(medusa): Add create batch job end point and implementation

* feat(medusa): remove cancelled related

* feat(medusa): Remove unrelated content for batch job creation

* feat(medusa): Cleanup migration

* feat(medusa): Cleanup context

* fix(medusa): Batch-job service import

* feat(medusa): Update migration

* test(medusa): Fix batch job tests

* feat(medusa): Start batch job end point

* feat(medusa): Continue end points

* feat(medusa): Continue end points

* feat(medusa): Finalize batch-job end points

* style(medusa): Lint

* feat(medusa): Cleanup

* feat(medusa): Fix list-batch-job endpoint column selection

* feat(medusa): Batch-job feedback

* feat(medusa): Update create-batch-job endpoint doc

* test(integration-tests): Fix batch-job integration reguarding the response status code

* feat(medusa): Finalize rebase from develop

* feat(medusa): Extend batch job status with ready_at and failed_at

* feat(medusa): Update migration and tests accordingly

* feat(medusa): Update status order on batchJob

* feat(medusa): Enhance batchJobService status update

* style(medusa): Cleanup

* style(medusa): Typo

* style(medusa): Remove unnecessary comment

* cleanup(medusa): Address feedback

* test(integration-tests): Update naming and snapshots

* fix(medusa): Update validator

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>

* Fix(medusa): update validator

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>

* test(intergration-tests): Fix creates batch job

* test(integration-tests): Fix snapshot

* feat(medusa): Re-work status

* tests(integration-tests): Fix batch job

* feat(medusa): Addresses feedback

* fix(medusa): Revert package.json script

* feat(medusa/batch-job-api): Improve status management

* feat(medusa): Improve batch job status and remove some context validation from the service

* feat(medusa): BatchJob api merge params

* feat(medusa): Apply last changes on the batch job service

* Update packages/medusa/src/services/batch-job.ts

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>

* feat(medusa): BatchJobStrategy and loaders (#1434)

* add batch job strategy interface

* update plugin loaders

* remove comment

* make map async

* ensure that only one of each strategy is registered

* register strategies plural

* add identifier and batchType properties

* extend batch job strategy identification method

* initial test

* update loaders to accomodate different ways of accessing batch job strategies

* identifier batch type field

* redo merge in plugins

* update interface and load only js files

* use switches instead of elif

* remove comments

* use static properties for strategy registration

* update tests

* fix unit tests

* update test names

* update isBatchJobStrategy method

* add check for TransactionBaseService in services for plugins

* update interfaces export

* update batchjob strategy interface with a prepare script

* update loaders

* update batchjob strategy interface

* remove everything but public interface methods from batchJobStrategy

* add default implementation to prepareBathJobForProcessing

* remove unused import

* docs: Add Services reference (#1548)

* added events reference

* add upgrade guide for 1.3.0

* Update 1-3-0.md

* merge 1.3.0 with 1.3.1

* rename to 1.3.0

* added paypal documentation

* Improve storefront quickstart documents

* chore(deps): bump sqlite3 from 5.0.2 to 5.0.3 (#1453)

Bumps [sqlite3](https://github.com/TryGhost/node-sqlite3) from 5.0.2 to 5.0.3.
- [Release notes](https://github.com/TryGhost/node-sqlite3/releases)
- [Changelog](https://github.com/TryGhost/node-sqlite3/blob/master/CHANGELOG.md)
- [Commits](https://github.com/TryGhost/node-sqlite3/compare/v5.0.2...v5.0.3)

* fix: Issue with cache in CI pipeline

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Shahed Nasser <shahednasser@gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-16 13:57:18 +02:00
Sebastian Rindom
14366f536d fix: adds tax calculation to product pricing (#1354)
* fix: adds tax calculation to product pricing

* fix: dedupe

* fix: merge inconsistencies

* fix: merge inconsistencies
2022-06-14 10:11:18 +02:00
Adrien de Peretti
9a3ff32b42 refactor(medusa): Convert DraftOrderService to TS (#1259) 2022-06-13 20:29:23 +02:00
Adrien de Peretti
5172b21d09 refactor(medusa): Refactor and fix EventBusService (#1377) 2022-06-09 17:18:22 +01:00
Zakaria El Asri
247ad6dc6d fix: includes variant prices when listing products using a search query (#1607)
* fix: return prices when lsiting products with a query

* add: integration test

* fix: integration test

* fix: move WithRequiredProperty to common.ts

* fix: comment
2022-06-05 21:52:31 +01:00
Philip Korsholm
3f23edea23 fix(medusa): Allow de-selecting configurations in price lists (#1596) 2022-05-30 19:34:34 +02:00
Kasper Fabricius Kristensen
083ab09361 fix(medusa): Prevent discount type updates (#1584) 2022-05-30 09:44:53 +02:00
Adrien de Peretti
fa031fd28b feat(medusa): Support deleting prices from a price list by product or variant (#1555) 2022-05-30 09:41:57 +02:00
Kasper Fabricius Kristensen
5414148254 fix(medusa): Post /admin/discounts/:id not updating condition operator (#1573) 2022-05-24 12:28:40 +02:00