Feat: Medusa react price list (#1258)

* export everything from price lists in core

* medusa-js price list

* feat: add product list for price lists

* feat: add product list for price lists

* add price list to admin module

* add price list hooks initial

* refactor: product list controller

* fix: add integration test for price list products

* update types

* add tests for price lists

* update medusa react tests

* update update request for price lists

* Apply suggestions from code review

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>

* rename methods

* pr feedback

* list products from price list

* fix errors after merge

* update medusa react with medusa-js method name changes

* redo changes

* update hook names

* fix: routes in msw handler

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
Co-authored-by: Zakaria El Asri <zakaria.elas@gmail.com>
This commit is contained in:
Philip Korsholm
2022-04-03 20:48:49 +02:00
committed by GitHub
parent fb33dbaca3
commit b164977a19
24 changed files with 838 additions and 276 deletions

View File

@@ -120,8 +120,8 @@ yarn global add create-strapi-app@3.6.8
create-strapi-app strapi-medusa --template https://github.com/Deathwish98/strapi-medusa-template.git
```
> Note: The plugin expects node version to be '>= 10.16.0 and <=14.x.x', otherwise it will throw an error.
> Note: The plugin expects node version to be '>= 10.16.0 and <=14.x.x', otherwise it will throw an error.
After running the command, you have a full Strapi project configured to synchronize with Medusa. Upon the initial start of the Strapi server, all the required models will be created. They will correlate with models from Medusa to allow for two-way synchronization.

View File

@@ -8,7 +8,6 @@
</video>
</div>
### Introduction
Handling payments is at the core of every commerce system; it allows us to run our businesses. Consequently, a vast landscape of payment providers has developed, each with varying cost models, implementational specifications, and analytical capabilities.

View File

@@ -24,7 +24,7 @@ export default () => {
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
@@ -53,8 +53,8 @@ Then, create an object that will hold the CORS configurations:
```js
const corsOptions = {
origin: projectConfig.admin_cors.split(","),
credentials: true,
origin: projectConfig.admin_cors.split(","),
credentials: true,
}
```
@@ -64,7 +64,7 @@ Finally, for each route you add, create an `OPTIONS` request:
router.options("/admin/hello", cors(corsOptions))
router.get("/admin/hello", (req, res) => {
//...
});
})
```
## Multiple Endpoints
@@ -76,13 +76,13 @@ You can add more than one endpoints in `src/api/index.js`:
```js
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
router.get("/admin/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
```
@@ -97,7 +97,7 @@ To do that with the previous example, first, create the file `src/api/hello.js`
export default (router) => {
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
}
@@ -111,7 +111,7 @@ Next, create the file `src/api/bye.js` with the following content:
export default (router) => {
router.get("/admin/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
}
@@ -148,17 +148,15 @@ You can retrieve any registered service in your endpoint using `req.scope.resolv
Heres an example of an endpoint that retrieves the count of products in your store:
```js
router.get('/admin/products/count', (req, res) => {
const productService = req.scope.resolve('productService')
router.get("/admin/products/count", (req, res) => {
const productService = req.scope.resolve("productService")
productService
.count()
.then((count) => {
res.json({
count
})
})
productService.count().then((count) => {
res.json({
count,
})
})
})
```
The `productService` has a `count` method that returns a Promise. This Promise resolves to the count of the products. You return a JSON of the product count.
@@ -170,13 +168,13 @@ Protected routes are routes that should be accessible by logged-in users only.
To make a route protected, first, import the `authenticate` middleware:
```js
import authenticate from '@medusajs/medusa/dist/api/middlewares/authenticate'
import authenticate from "@medusajs/medusa/dist/api/middlewares/authenticate"
```
Then, add the middleware to your route:
```js
router.get('/store/products/count', authenticate(), (req, res) => {
router.get("/store/products/count", authenticate(), (req, res) => {
//...
})
```

View File

@@ -24,7 +24,7 @@ export default () => {
router.get("/store/hello", (req, res) => {
res.json({
message: "Welcome to My Store!"
message: "Welcome to My Store!",
})
})
@@ -47,13 +47,13 @@ You can add more than one endpoints in `src/api/index.js`:
```js
router.get("/store/hello", (req, res) => {
res.json({
message: "Welcome to My Store!"
message: "Welcome to My Store!",
})
})
router.get("/store/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
```
@@ -68,7 +68,7 @@ To do that with the previous example, first, create the file `src/api/hello.js`
export default (router) => {
router.get("/store/hello", (req, res) => {
res.json({
message: "Welcome to My Store!"
message: "Welcome to My Store!",
})
})
}
@@ -82,7 +82,7 @@ Next, create the file `src/api/bye.js` with the following content:
export default (router) => {
router.get("/store/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
}
@@ -119,17 +119,15 @@ You can retrieve any registered service in your endpoint using `req.scope.resolv
Heres an example of an endpoint that retrieves the count of products in your store:
```js
router.get('/store/products/count', (req, res) => {
const productService = req.scope.resolve('productService')
router.get("/store/products/count", (req, res) => {
const productService = req.scope.resolve("productService")
productService
.count()
.then((count) => {
res.json({
count
})
})
productService.count().then((count) => {
res.json({
count,
})
})
})
```
The `productService` has a `count` method that returns a Promise. This Promise resolves to the count of the products. You return a JSON of the product count.
@@ -141,13 +139,13 @@ Protected routes are routes that should be accessible by logged-in customers onl
To make a route protected, first, import the `authenticate` middleware:
```js
import authenticate from '@medusajs/medusa/dist/api/middlewares/authenticate'
import authenticate from "@medusajs/medusa/dist/api/middlewares/authenticate"
```
Then, add the middleware to your route:
```jsx
router.get('/store/products/count', authenticate(), (req, res) => {
router.get("/store/products/count", authenticate(), (req, res) => {
//...
})
```

View File

@@ -1,7 +1,5 @@
---
title: Create a Service
---
# Create a Service
@@ -31,7 +29,7 @@ To create a service, you should create a JavaScript file in `src/services` to ho
For example, if you want to create a service `helloService`, create the file `hello.js` in `src/services` with the following content:
```js
import { BaseService } from "medusa-interfaces";
import { BaseService } from "medusa-interfaces"
class HelloService extends BaseService {
getMessage() {
@@ -39,7 +37,7 @@ class HelloService extends BaseService {
}
}
export default HelloService;
export default HelloService
```
## Service Constructor
@@ -85,10 +83,10 @@ constructor({ helloService }) {
To use your custom service in an endpoint, you can use `req.scope.resolve` passing it the services registration name:
```js
const helloService = req.scope.resolve('helloService');
const helloService = req.scope.resolve("helloService")
res.json({
message: helloService.getMessage()
message: helloService.getMessage(),
})
```

View File

@@ -1,7 +1,5 @@
---
title: Introduction
---
## Architecture overview
@@ -18,11 +16,11 @@ Your Medusa server will include all functionalities related to your stores ch
### Admin Dashboard
The admin dashboard is accessible by store operators. Store operators can use the admin dashboard to view, create, and modify data such as orders and products.
The admin dashboard is accessible by store operators. Store operators can use the admin dashboard to view, create, and modify data such as orders and products.
Medusa provides a beautiful [admin dashboard](https://demo.medusajs.com) that you can use right off the bat. Our admin dashboard provides a lot of functionalities to manage your store including Order management, product management, user management and more.
You can also create your own admin dashboard by utilizing the [Admin REST APIs](https://docs.medusajs.com/api/admin/auth).
You can also create your own admin dashboard by utilizing the [Admin REST APIs](https://docs.medusajs.com/api/admin/auth).
### Storefront