Commit Graph

242 Commits

Author SHA1 Message Date
Philip Korsholm
645e0d0ec5 Feat(medusa): search orders by customer phone and name (#2913)
* add support for customer first- and last names and phone

* test for querying customer first_name, last_name and phone

* add customer as prop for querying orders

* polishing before pr

* changeset
2022-12-29 15:20:18 +01:00
Adrien de Peretti
463f83ffdd feat(medusa): Ordering products on retrieval (#2815)
**What**

Move to transformQuery which adds a default ordering and also allows to order the product list from the store API

**How**
Among other things, fix the product repo to allow ordering by either a key from the product or a key from a relation

FIXES CORE-911
FIXES CORE-901
2022-12-22 10:33:53 +00:00
Adrien de Peretti
e27b1940c7 fix(medusa): Include items.variant relation in order calculation (#2869)
**What**

When an order require to decorate the totals, the variant relation should be added

FIXES CORE-930
2022-12-22 09:32:49 +00:00
josetr
3113d8024f feat(medusa): Allow creating DraftOrders without items (#2719) 2022-12-20 18:37:42 +01:00
Adrien de Peretti
c8724da503 feat(medusa,medusa-payment-stripe): Move database mutation from plugin to core (#2743)
**what**
The goal of that PR is to first refactor the payment provider and payment plugin to support the new API that removes the data mutation from within the plugin to be done by the core instead. In any case, this pr does not include the steps of the deeper refactoring. The last part will come in later pr.

**How**
- The payment plugin is now capable to handle both the deprecated and new API and the plugin works the same as it use to works.
- The mutation made by the plugin have been moved into the core as well as the subscriber
- The tests have been updated to reflect the changed
- Remove all new methods introduced by the payment collections
  - Mutualise types
  - Update provider and payment collection services
  - cleanup around all those refactoring including cleanup of the payment collection
  - refactor stripe payment plugin

FIXES CORE-887
2022-12-19 14:37:35 +00:00
Kasper Fabricius Kristensen
9e05fef4b9 fix(medusa): Fix q param on /admin/price-lists/:id/products (#2813) 2022-12-18 20:11:38 +01:00
Philip Korsholm
c16522d6ce feat(medusa): Add has_account to list-customers query params (#2811) 2022-12-16 12:16:34 +01:00
Philip Korsholm
6283010fd6 Fix(medusa): Totals on draft orders (#2785)
* test subtotals on draft order operations

* fetch cart with subtotals when doing draft order operations

* write test for updating discounts seeing changes in totals

* formatting

* udpate test

* force taxes

* missing select

* add import

* rm force_taxes
2022-12-16 10:21:53 +01:00
Frane Polić
ea460b4e0b feat(medusa): add q param to PKs sales channels retrieval (#2810)
**What**
- enable to filter sales channels of a Publishable API Key with a free text search param

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-12-15 19:12:44 +00:00
Frane Polić
2d22b17b49 feat(medusa): Allow all relations on /admin/* endpoints (#2763) 2022-12-15 09:07:07 +01:00
Frane Polić
3464617553 fix(medusa): Payment status on refunds (#2770) 2022-12-12 19:04:36 +01:00
Oliver Windall Juhl
b2ea8b7d45 fix(medusa): Throw on flat rate shipping options with no amount (#2628) 2022-12-12 18:34:30 +01:00
Philip Korsholm
a6243618fe feat(medusa): Claim customer orders (#2710) 2022-12-08 17:48:49 +01:00
Riqwan Thamir
5240972cef chore: remove expectations in callbacks 2022-12-07 17:03:51 +01:00
Riqwan Thamir
c1cdb80436 chore: use splat instead of lodash to clone, remove unnecessary expectations 2022-12-07 16:42:32 +01:00
Riqwan Thamir
66bec2f54d test: add a case when regions only contain invalid region Ids 2022-12-07 16:42:32 +01:00
Riqwan Thamir
bcc1edbf2b chore: addressing review - move repeated strings and objects to constants 2022-12-07 16:42:32 +01:00
Riqwan Thamir
f22e063ed8 test: fix existing integration tests and add a new test that validates regions inclusion and validity 2022-12-07 16:42:32 +01:00
Carlos R. L. Rodrigues
15c667fbd3 feat(medusa,medusa-react): PaymentCollection support (#2659)
* chore: medusa react, order edit complete fix and single payment session
2022-12-07 12:39:35 -03:00
Adrien de Peretti
42d9c7222b feat(medusa): Performance improvements of Carts domain (#2648)
**What**

I have created a new method on the cart service which is `addLineItems`, allowing a user to add one or multiple items in an optimized way. Also updated the `generate` method from the line item service which now also accept a object data or a collection of data which. Various places have been optimized and cache support has been added to the price selection strategy.

The overall optimization allows to reach another 9000% improvement in the response time as a median (Creating a cart with 6 items):

|   | Min (ms)  | Median (ms)  | Max (ms)  | Median Improvement (%)
|---|:-:|---|---|---|
| Before optimisation  | 1200  | 9999 | 12698  |  N/A
| After optimisation | 63  | 252  | 500  | 39x
| After re optimisation | 56 | 82  | 399  | 121x
| After including addressed feedback | 65 | 202  | 495  | 49x

FIXES CORE-722
2022-12-07 14:39:12 +00:00
Frane Polić
322d462311 feat(medusa): PublishableApiKeys SC scopes (#2590)
**What**
-  add/ remove sales channels to/from PublishableApiKey in batch
- associate created cart with SC defined by PK
- filter products if PK with SC association is present
- retrieve a list of sales channels for a PK
- implement 3 new middleware
  - `extendRequestParams`
    -  _extend req object with PK scopes (a list of sales channels) if a publishable key is present in the header of the request_
  - `validateProductSalesChannelAssociation`
    -  _validate if the passed product id belongs to a SC from the PK's scope_
  - `validateSalesChannelParam`
    -  _validate that passed SC ids in the req body/query are within the scope of the PK_

**How**
- The general idea was to reuse existing logic in the controller layer which expects `sales_channel_id` array to be passed. The middleware sets associated SC ids in the request context if a PK is present. These ids are then merged in the controller and passed to the service layer.

**TODO**
- filter response from the search endpoint (CORE-824)

**Testing**
- _integration tests_
  - add sales channels to the publishable API key scope
  - remove sales channels from the publishable API key scope
  - returns products from a specific channel associated with a publishable key
  - returns products from multiples sales channels associated with a publishable key
  - returns all products if PK is not passed
  - returns all products if passed PK doesn't have associated channels
  - should assign sales channel to order on cart completion if PK is present in the header
  - list sales channels from the publishable api key
  -  throws because sales channel in query/body is not in the scope of passed PK 

---

**Discussion**
- what about the other endpoints (e.g. GET /store/product/:id - do we return 404 if the product is not in the SC associated with passed PK)
- what about products search route
- what about `/admin/products` & `/admin/orders` routes (do we add the middleware there as well)

---

RESOLVES CORE-792
RESOLVES CORE-793
RESOLVES CORE-816
2022-12-07 07:50:20 +00:00
Oliver Windall Juhl
d7997ef256 feat(medusa): Module Resolution API (#2597) 2022-11-20 22:01:46 +01:00
Carlos R. L. Rodrigues
01a879ac94 chore: markAsAuthorized and payment collection tests (#2620)
* chore: markAsAuthorized and payment collection tests
2022-11-18 11:23:35 -03:00
Patrick
022a84691e fix(draft-order): create tax-inclusive with discount (#2579)
**What**
Fix system error (500) with DraftOrder create operation when payload includes discount in a tax-inclusive context.

**How**
* Ensure newly created cart contains all required relation in order to calculate line item tax-inclusive pricing with discounts.
* Add resilience to TotalsService.getLineDiscounts()
* Ensure newly generate line items have variant relation loaded.
* fix TotalsService.getLineItemTotals to use the passed lineItem instead of relying on cartOrOrder.items.

**Test**
* Unit:
  *  TotalsService.getLineDiscounts - coverage
* Integration:
  * Admin API draft-order - coverage
  * Admin API draft-order create w/ discount in tax-inclusive

Resolves: CORE-771

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
2022-11-16 15:34:18 +00:00
Frane Polić
03fc9e18e9 feat(medusa, medusa-js, medusa-react): PublishableApiKey "update" endpoint & add "title" property (#2609)
**What**
- update PK endpoint
  - medusa-js/react implementation
- add a title property to the entity
  - update the migration file
  - pass a title on create
  - list PKs by title
  - update the client libs with new param signatures
- change id prefix to: "pk_"
2022-11-16 04:35:22 +00:00
Frane Polić
d0809bdf25 feat(medusa): PublishableApiKeys CRUD (#2567) 2022-11-14 19:30:24 +01:00
Adrien de Peretti
d2b1848e52 feat(medusa): Cart and totals computational optimizations (#2475) 2022-11-14 15:45:47 +01:00
Carlos R. L. Rodrigues
755ba90c05 feat(medusa): Payment Collection endpoints (#2525) 2022-11-11 18:28:45 +01:00
Adrien de Peretti
699bb1d57b hotfix(medusa): Deleted region are missing on order retrieval (#2583) 2022-11-10 14:44:35 +01:00
Patrick
7b0ceeffb4 feat: /store api product types (#2552)
## What
Allow users to fetch ProductTypes from the storefront API.

## Why
This endpoint will allow developers to implement better faceted product search in Medusa without the need for search plugin. Developers will be able to use this to render refinement lists based on types, like this:
![image](https://user-images.githubusercontent.com/116003638/200417828-863065de-3607-49db-bd72-62a6815129fa.png)

## How
Endpoint `GET /store/products/types` and `GET /store/product-types` (use [product types listing in admin](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/api/routes/admin/products/list-types.ts) as reference)

Support added in @medusajs/medusa-js
Support added in medusa-react

## Testing
Similar automated tests as `GET /admin/products/types` and `GET /admin/product-types`

---

Resolves CORE-699
2022-11-09 16:10:17 +00:00
Adrien de Peretti
129ad4b687 fix(medusa): Order/Cart decorate totals should assign the items totals (#2546)
**What**

If `total` or `subtotal` are selected then get the line item totals and assign them to the items.

I also had to remove the totals from the cart update service since they are not used and that by having them the items get the tax lines attached and since the update is performed by passing the entire cart, it is trying to insert the tax lines with the cart update

**Tests**

Add an integration tests to validate that the items includes the totals in the order and draft order

FIXES CORE-687
2022-11-07 13:54:41 +00:00
Philip Korsholm
15d6f92964 Fix(medusa): Swaps in tax inclusive regions (#2557)
**What**
- Ensure that swaps can be created for orders with discounts in tax inclusive regions

**How**
- Retrieve cart with discounts and region before creating adjustments for line items in cart. 
  - In `discountService.calculateDiscountForLineItem` we used the method `totalsService.getLineItemTotals` if a line-item is tax inclusive. This method uses some fields from the cart that aren't populated on cart creation (such a `items` which caused the original error).

**Testing**
- add integration test `swaps > tax inclusive > "Complete swap flow with discount"` that creates a swap in the following environment
  - tax inclusive region 
  - tax inclusive line item to be swapped
  - fixed type discount with allocation: total

Fixes CORE-748
2022-11-07 10:47:26 +00:00
Philip Korsholm
38d4a7db3d Feat(Medusa): Allow custom shipping price on draft orders (#2531)
* create custom shipping option for cart to have custom shipping price on draft orders

* Create moody-chefs-stare.md
2022-11-03 08:44:47 +01:00
Frane Polić
591668d332 fix(medusa): draft order set payment as captured (#2479)
**What**
- when an order is created from a draft order, set the payment of the order as captured

FIXES CORE-592
2022-10-31 12:24:59 +00:00
Kasper Fabricius Kristensen
4de4f20b46 feat(medusa): add analytics config (#2442)
**What**
- Adds new entity AnalyticsConfig
- Adds new service AnalyticsConfigService
- Adds new repository AnalyticsConfigRepository
- Adds new endpoints to get, create, update, and delete analytics configs

**Why**
As we begin gathering usage insights to help us improve Medusa, we want to give each individual users the ability to control what data they share with us, or not share any data with us at all. The AnalyticsConfig holds information that is used to check if the user wishes for their data to be anonymized or if they have opted out of sharing usage data.

The entire feature can be disabled on a store level by setting the feature flag `MEDUSA_FF_ANALYTICS=false` in their environment variables, the feature is enabled by default. 

**Testing**
Adds integration test for each of the new endpoints

Resolves CORE-656, CORE-655, CORE-654

Also resolves CORE-574
2022-10-21 13:04:46 +00:00
Kasper Fabricius Kristensen
fcfb7d167b fix(medusa): Allow AddressPayload or string on DraftOrder creation (#1902) 2022-10-19 18:01:08 +02:00
Adrien de Peretti
8be67c734c feat(medusa): Filter product list by discount condition id (#2464) 2022-10-19 11:23:33 +02:00
Frane Polić
73db8cfca6 feat: list OE by order id (#2457)
**What**
- allow passing `order_id` param to OE list endpoint
2022-10-17 15:34:20 +00:00
Adrien de Peretti
48411157b1 feat(medusa): Support batch remove resources on discount condition (#2444)
**what**
- Add support to remove resources by batch on discount conditions
- Add support on medusa-js and medusa-react

**Tests**
- Add integration tests to validate that the resources have been deleted and the length is the one expected
- Add unit tests on medusa react

FIXES CORE-609
2022-10-17 09:03:38 +00:00
Adrien de Peretti
765a2cccda Feat/add discount condition batch (#2430)
* feat(medusa): Allow to add items to a discount condition by batch + cleanup of discounts and discount conditions end points

* style(medusa): cleanup catch and log

* feat(medusa-react, medusa-js): Add support to add item batch to discount condition

* cleanup

* cleanup

* rename items to resources

* fix(medusa-js): url

* Create fast-suns-repair.md

* update naming

* tests(integration): Update tests to reflect API changes

* feat(medusa): Delete a condition should be idempotent on discount and condition

* revert
2022-10-13 16:34:06 +02:00
Adrien de Peretti
143f8543e5 feat(medusa, medusa-js, medusa-react): Support listing order edits (#2436)
* feat(medusa, medusa-js, medusa-react): Support listing order edits

* feat(medusa): Update OAS

* fix oas

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-10-13 14:44:08 +02:00
Kasper Fabricius Kristensen
69e579758f fix(medusa, medusa-js): Use price selection strategy for GET /admin/variants (#2270)
**What**
- Adds the use of price selection strategy to the endpoint `GET /admin/variants`
- Updates medusa-js to reflect this change (expanding the parameters).

**Testing**
- Adds a new integration test validating that returned variants are now of type PricedVariant, with the expected fields: original_price, calculated_price, etc.

**Why**
- Our current RMA flows (in our admin dashboard) relied heavily on simply using `order.tax_rate` to calculate variant prices in the different RMA menus. As taxes in Medusa, have become feature complete this approach had become very naive and has several potential issues. Moving the responsibility for calculating the correct prices guarantees that we always show the correct prices to admins.
2022-10-13 08:54:03 +00:00
Kasper Fabricius Kristensen
211720f24c fix(medusa): List products by type_id (#2427)
**What**
- Fixes `GET /products` in both admin and store API so they no longer accept the param `type?: string`, but instead accept `type_id?: string[]`

**Why**
- Filtering by type would never return any products as `ptyp_:id` !== `ProductType`.

**Testing**
- Added an integration test for each endpoint.

Closes CORE-695
2022-10-12 18:56:56 +00:00
Philip Korsholm
bb75a0bc5e fix(medusa): Ensure no orphan product option values (#2408) 2022-10-12 12:48:50 +02:00
Frane Polić
69ef713854 fix(medusa): remove changes when deleting order edits (#2420)
**What**
- when deleting an OE cloned items are deleted, this would fail if there were changes associated with the OE since line items were referenced from the item changes and couldn't be deleted

**How**
- when deleting an order edit also remove it's item changes

Fixes CORE-689
2022-10-12 08:04:29 +00:00
Adrien de Peretti
c717442451 feat(medusa): Allow to filter collections by discount condition id (#2411) 2022-10-11 16:14:10 +02:00
Adrien de Peretti
a9c703d56c feat(medusa): Allow to query product tags by condition id (#2340) 2022-10-11 11:24:50 +02:00
Adrien de Peretti
94c242f476 feat(medusa): Allow to filter customer groups by discount condition id (#2346) 2022-10-11 08:39:21 +02:00
Adrien de Peretti
19ca18e71c feat(medusa): Allow to query product types by discount condition id (#2359) 2022-10-11 08:36:08 +02:00
Sebastian Rindom
3d255302b0 fix(medusa): Optimize Cart totals calculation (#2372)
**What**

The existing totals calculations are extremely heavy and perform an enormous amount of duplicate work. The changes here remove large parts of the overhead and improves response times for cart endpoints up to 30x.
2022-10-07 08:44:06 +00:00