Commit Graph

153 Commits

Author SHA1 Message Date
Frane Polić
78ff64e783 fix(medusa): validate customer for group discount (#3797)
* fix: validate customer for group discount

* fix: remove logger

* fix: add generated desc

* fix: add an integration test case

* refactor: update error message

* fix: typo

* refactor: move condition

---------

Co-authored-by: fPolic <frane@medusajs.com>
2023-04-11 14:16:18 +02:00
Oliver Windall Juhl
7f6dc44beb fix(medusa): Add totals when retrieving order by cart id (#3777)
* fix(medusa): Add totals when retrieving order by cart id

* fix: Unit test

* Create .changeset/stupid-rockets-smile.md
2023-04-11 11:40:13 +02:00
Riqwan Thamir
d533caa4c2 feat(medusa, admin-ui): add description field to product categories (#3768)
* feat(medusa): add description field to product categories

* chore: set nullable to false

* chore: added UI for description

* chore: added codegen files
2023-04-08 18:29:12 +02:00
Oliver Windall Juhl
809ab2e0eb chore: Merge master to develop (#3653) 2023-03-31 13:09:57 +02:00
Philip Korsholm
5fd74b38ae feat(medusa): remove created reservations on subsequent failure for cart completion (#3554)
**What**
- If cart completion fails after creating reservations, remove those reservations

**Why**
- To avoid hanging reservations if something fails at a later point
2023-03-29 17:03:53 +00:00
Philip Korsholm
aed7805c0e fix(medusa): Error messages for reset tokens (#3514)
* initial

* reset password token handling

* Create .changeset/old-planes-cross.md

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-03-19 10:52:10 +01:00
Patrick
522e306e2e feat(oas): declare x-expanded-relations - Store (#3482)
* feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* fixup! feat(oas): declare x-expanded-relations - Store

* chore(changeset): patch

* fix(tests): update store auth integration test

* fix: pr feedback

* fix(test): match response code
2023-03-16 09:08:20 +01:00
Riqwan Thamir
2f42ed35d6 feat(medusa, admin-ui): increase tree depth + scope categories on store + allow categories relation in products API (#3450)
What:
- increase tree depth in react nestable
- scope categories on store queries
- allow categories relation in products API

RESOLVES CORE-1238
RESOLVES CORE-1237
RESOLVES CORE-1236
2023-03-13 17:30:21 +00:00
Riqwan Thamir
1d09a266be feat(medusa): category list API can return all descendant (#3392)
* chore: category list API can return all descendant

* chore: category handle is no longer required via api

* chore: added treescope to sorting

* chore: address feedback on PR
2023-03-07 15:54:49 +01:00
Riqwan Thamir
0a6aa0e624 feat(medusa): categories can be ranked based on position (#3341)
* chore: categories can be ranked based on position

* chore: fix tests

* chore: sort categories by order

* chore: fix bug where mpath relationship is messed up

* chore: enable linting - lint changes

* Update packages/medusa/src/repositories/product-category.ts

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>

* chore: fixed specs

* chore: cleanup repository to new typeorm interfaces + cleanup

* chore: revert repository changes due to incorrect sql

* chore: addressed pr reviews

---------

Co-authored-by: Frane Polić <16856471+fPolic@users.noreply.github.com>
Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
2023-03-06 15:49:16 +01:00
Adrien de Peretti
cbbf3ca054 fix(medusa): Clean response data usage for admin and store fields/expand (#3323)
* fix(medusa): Clean response data usage for admin and store fields/expand

* cleanup

* Create mighty-ads-fold.md

* fix integration

* fix integration

* refactor transform query and cleanup

* fix missing re naming

* Update packages/medusa/src/api/middlewares/transform-query.ts

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-28 09:48:08 +01:00
Adrien de Peretti
46547f29c7 chore(medusa): Improve store list products (#3252)
* chore(medusa): Improve list products by 46.5 percents

* fix handler

* todo's

* Create tricky-terms-wash.md

---------

Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2023-02-20 12:45:05 +01:00
Riqwan Thamir
121b42acfe chore(medusa): Typeorm upgrade to 0.3.11 (#3041) 2023-02-15 16:25:30 +01:00
Adrien de Peretti
4cb44a3a2e fix(medusa): Discount allocation precision issues (#3244) 2023-02-13 17:22:18 +01:00
Frane Polić
61b0b2f3aa fix(medusa): Pass query transformer config in storefront controllers (#3219) 2023-02-09 17:52:04 +01:00
Adrien de Peretti
bfa33f444c fix(medusa): Applying Discounts (with Conditions) on DraftOrders and Carts (#3197) 2023-02-08 19:01:23 +01:00
Frane Polić
e22a383f47 fix(medusa): fields params usage in the storefront endpoints (#2980) 2023-02-06 16:18:23 +01:00
Riqwan Thamir
4105405f28 feat(medusa): Filter products by category params in store/admin (#3155)
What:

Products can be filtered through the API by category parameters

Why:

To filter products by category

How:

- adds 2 params in admin/store route
- updates repository to accept 2 new parameters

RESOLVES CORE-1032
RESOLVES CORE-1033
2023-02-01 17:25:07 +00:00
Adrien de Peretti
e581d3bd90 chore(integration-tests): Flaky tests (#3126) 2023-01-27 17:45:54 +01:00
Kasper Fabricius Kristensen
150696de99 feat(medusa, medusa-js, medusa-react): Add endpoint to retrieve product tags from the storefront (#3051) 2023-01-18 10:47:15 +01:00
Riqwan Thamir
7d4b8b9cc5 feat(medusa): List (service + controller) product categories #3004 (#3023)
**What:**

Introduces a store endpoint to retrieve a list of product categories

**Why:**

This is part of a greater goal of allowing products to be added to multiple categories.

**How:**

- Creates an endpoint in store routes

RESOLVES CORE-968
2023-01-16 19:20:42 +00:00
Oliver Windall Juhl
9e3beaf531 chore(feature-flags): Remove OrderEditing feature flag (#3006) 2023-01-13 11:10:09 +00:00
Riqwan Thamir
b2839e2e4d feat(medusa): Retrieve (service + controller) a product category (#3004)
What:

Introduces a store endpoint to retrieve a product category

Why:

This is part of a greater goal of allowing products to be added to multiple categories.

How:

- Creates an endpoint in store routes

RESOLVES CORE-967
2023-01-12 16:19:06 +00:00
Oliver Windall Juhl
3308766389 chore(feature-flags): Sales Channels enabled by default (#2966) 2023-01-10 16:45:23 +00:00
Philip Korsholm
b9680b641f feat(medusa): Add ProductVariantInventoryService (#2883)
* add mw feature flag

* add services

* add types

* add module interfaces

* add interface export

* add models for mw

* to be ammended

* remove featureflag

* use correct count

* update cart completion strategy

* swap service conversion

* update return service

* update order service

* update claim service

* add exception to claim item

* update cart service

* add indicies

* add changeset

* nullable changes in store

* store model update

* fix unit tests

* remove old inventory service

* format integration test

* update snapshots

* remove old inventory service tests

* update snapshots

* remove old code

* option updates

* naming

* add jsdoc to pv inventory service

* rename class variables

* pr feedback

* rename option to context

* if(variant_id) instead of if(typeof varia...)

* update tests

* add jsdoc

* go for custom

* update code for readability
2022-12-30 11:30:04 +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
Riqwan Thamir
8a60a73389 fix(medusa): gift card values & taxes are calculated correctly (#2777)
* chore: tax_rate is added to giftcards

* chore: minor

* chore: update gift card tax calculations to look at giftCard.tax_rate

* chore: gift card transactions use tax rate from gift card for legacy

* fix: gift cart total check for transaction should check the length

* chore: use tax exclusive cost + use giftcard tax rate for gctransactions + refactor

* chore: fix integration test

* chore: address issues brought up in comments

* chore: move gift card creation as a part of order service on order placed

* chore: add type handling for gift card creation

* chore: fix specs

* chore: use taxLines to calculate tax of a gift card

* chore: specs for line items containing gift cards and without

* chore: add integration specs + fix tax rate bug

* chore: round totaling + add GC application specs

* chore: cleanup trialables

* chore: write migration script to backfill gift cards with null tax_rate

* chore: update legacy totals service for gift cards

* chore: add changeset

* chore: address PR review changes

* chore: fix tests based on new totals calc

* chore: address review comments

Co-authored-by: adrien2p <adrien.deperetti@gmail.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-12-20 22:24:25 +01:00
Kasper Fabricius Kristensen
33aa3edb80 fix(medusa): keep country_code when partially updating cart addresses (#2683)
**What**
- Fixes a bug where `country_code` was dropped when partially updating a shipping or billing address on a cart.
2022-12-12 14:03:54 +00:00
Adrien de Peretti
d68e81fb3d fix(medusa): Update line item adjustments upon cart discount removal (#2751)
**What**

When a discount is deleted from a cart, the line item adjustments must be refreshed. Now, the cart service `removeDiscount` includes updating the adjustments.

**Tests**

**Add a new integration test which:**
- create a cart with a discount 
- add a line item
- validate the adjustments
- remove the discount
- check that the adjustments are not present anymore

**Update unit tests**
The actual tests cases now check that the adjustments repository is called when needed

FIXES CORE-890
2022-12-12 09:53:40 +00:00
Kasper Fabricius Kristensen
72f70bc789 fix(medusa): Decorate order with totals in store domain (#2747) 2022-12-09 09:42:53 +01:00
Philip Korsholm
a6243618fe feat(medusa): Claim customer orders (#2710) 2022-12-08 17:48:49 +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
Philip Korsholm
70a8d3450f fix(medusa): Use correct auth middleware in GET /store/auth (#2687)
* use correct authentication middleware

* remove guard from get-session since it's guarded by middleware doing the same check

* Add integration tests

* Create lazy-swans-agree.md

Co-authored-by: olivermrbl <oliver@mrbltech.com>
Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
2022-11-29 15:46:55 +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
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
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
Philip Korsholm
434b11af46 Fix(medusa): make shipping option requirements tax inclusive if the shipping option is (#2544)
**What**
- validate shipping option requirements including tax if the shipping option is tax inclusive

**Testing**
- " given a cart with total above min-threshold and subtotal below min-threshold shipping option with tax inclusive pricing is available and can be applied"
- "given a cart with total above max-threshold and subtotal below max-threshold shipping option with tax inclusive pricing is not available"

Fixes CORE-752
2022-11-04 14:04:07 +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
Adrien de Peretti
c717442451 feat(medusa): Allow to filter collections by discount condition id (#2411) 2022-10-11 16:14:10 +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
Oliver Windall Juhl
edd35631f7 fix(medusa): Add sales channel to order on creation (#2374) 2022-10-07 09:12:25 +02:00
Adrien de Peretti
95c0dc653a feat(medusa, medusa-js, medusa-react): Implement store complete order… (#2275)
**What**

Allow a customer to complete a requested order edit.

**Test**
- Unit tests complete flow
- Unit tests medusa react
- Integration tests of order edit completion

FIXES CORE-501
2022-09-29 17:06:45 +00:00
Oliver Windall Juhl
8797a1441b fix(medusa): Query SalesChannel Products in storefront (#2272) 2022-09-29 14:40:24 +02:00
Adrien de Peretti
9a532de7bd feat(medusa): Improve transform middleware (#2271)
**What**

Improve transform query middleware management of the allowed fields and relations in order to improve security upon access data

FIXES CORE-651
2022-09-29 09:41:09 +00:00
Adrien de Peretti
d138baf460 feat(medusa): refactor the way the order edit handle the items (#2255)
* feat(medusa): Reftor the way the order edit works
2022-09-26 16:01:20 +02:00
Philip Korsholm
c661cc789b Feat/decline order edit (#2234)
**What**
- Decline an order edit from a store endpoint
- Refactor totals setting to a service method

Fixes CORE-502
2022-09-21 11:02:10 +00:00
Adrien de Peretti
f7177c9033 feat(medusa): Implement premises of the creation flow of an order edit (#2187)
**What**
- Implements the admin create end point 
- Service implementation of the create method and the retrieveActive as well as the totals computation
- Improve compute line items
- client
  - medusa-js api
  - medusa-react mutations hooks

**Tests**
- Unit tests of the create end points
- Unit tests of the service create method
- Integration tests for admin that also take into account totals computations
- client
  - medusa-js tests
  - medusa-react hooks tests

FIXES CORE-491
2022-09-16 08:29:40 +00:00