Merge branch 'master' into develop

This commit is contained in:
olivermrbl
2022-12-22 10:43:29 +01:00
21 changed files with 1026 additions and 114 deletions
+1 -18
View File
@@ -55,24 +55,7 @@ You can learn about all of the ecommerce features that Medusa provides [in our d
## Roadmap
Write-ups for all features will be made available in [Github discussions](https://github.com/medusajs/medusa/discussions) before starting the implementation process.
### **2022**
- [x] Admin revamp
- [x] Tax API
- [x] Tax Calculation Strategy
- [x] Cart Calculation Strategy
- [x] Customer Groups API
- [x] Promotions API
- [x] Price Lists API
- [x] Price Selection Strategy
- [x] Import / Export API
- [x] Sales Channel API
- [ ] Extended Order API (managing placed orders)
- [ ] PaymentCollection API (collecting payments separate from carts and draft orders)
- [ ] Multi-warehouse API
- [ ] Extended Product API (custom fields, publishing control, and more)
You can view our roadmap with features that are planned, started, and completed on the [Roadmap discussion](https://github.com/medusajs/medusa/discussions/categories/roadmap) category.
## Plugins
+100
View File
@@ -0,0 +1,100 @@
# Customize Medusa Admin
In this document, youll learn how to customize the Medusa admin by forking it, and how to keep it updated with changes from the main repository.
## Overview
Although Medusa provides an intuitive admin that should cover all your ecommerce needs, you are free to customize the Medusa admin as you see fit.
For customization and development, its recommended that you fork the main Medusa admin repository. That way, you can configure your forked repository to pull changes from the main Medusa admin repository for any latest updates.
In this document, youll learn how to:
- Fork the Medusa admin repository.
- Configure the Medusa admin repository as an upstream repository.
- Pull changes from the upstream repository to keep your fork synced with the Medusa admin repository.
---
## Prerequisites
### Required Tools
[Git CLI tool](../tutorial/0-set-up-your-development-environment.mdx#git)
### Required Accounts
[GitHub](https://github.com/)
---
## Fork the Medusa Admin Repository
To fork the Medusa admin:
1. Go to the [Medusa admin repository](https://github.com/medusajs/admin).
2. Click on the Fork button at the top right.
3. You can optionally change the name of the repository and description.
4. Once done, click on the Create fork button.
5. After your fork is created, you can clone it using the following command:
```bash
git clone <REPOSITORY_URL>
```
Where `<REPOSITORY_URL>` is the HTTPS URL of your repository. You can obtain it from your forked repositorys GitHub page by clicking on the Code button and copying the URL.
---
## Configure Upstream Repository
To configure the Medusa admin as the upstream repository:
1. Change to the directory of your cloned forked repository.
2. Run the following command to add the Medusa admin repository as an upstream repository:
```bash
git remote add upstream https://github.com/medusajs/admin
```
1. You can verify that it has been added by running the following command:
```bash
git remote -v
```
You should see an `origin` repository which is your forked repository, and an `upstream` repository which is the Medusa admin repository.
---
## Update your Fork with Latest Changes
To update your fork with the latest changes from the Medusa admin repository:
1. Change to the directory of your cloned forked repository.
2. Run the following command to fetch the latest changes from the Medusa admin repository:
```bash
git fetch upstream
```
1. Make sure youre on your `main` or `master` branch of the forked repository:
```bash
git checkout main
```
1. Merge the changes from the `main` branch of the Medusa admin repository:
```bash
git merge upstream/main
```
If your forked repository doesnt have any conflicts with the changes from the Medusa admin repository, the merge will be done successfully. Otherwise, youll need to [resolve these conflicts](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line).
---
## Whats Next
- Check out the [Admin API reference](/api/admin).
- Learn about [local development of the Medusa server](../usage/local-development.md).
+3 -2
View File
@@ -103,10 +103,10 @@ This will create a new user that you can use to log into your admin panel.
## Changing the Default Port
The default port is set in `package.json` in the `develop` script:
The default port is set in `package.json` in the `dev` script:
```json
"develop": "gatsby develop -p 7000",
"dev": "vite --port 7000",
```
If you wish to change the port you can simply change the `7000` to your desired port.
@@ -135,5 +135,6 @@ You can learn more about Medusa admin and its features in the [User Guide](../us
## Whats Next
- Learn how to [Customize Medusa Admin](./development.md)
- Install the [Next.js](../starters/nextjs-medusa-starter.md) or [Gatsby](../starters/gatsby-medusa-starter.md) storefront starters.
- [Learn how you can use `create-medusa-app` to install all of Medusas 3 components.](../usage/create-medusa-app.mdx)
@@ -0,0 +1,403 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Manage Regions using Admin APIs
In this document, youll learn how to manage regions using the Admin APIs.
## Overview
Using the [region admin REST APIs](/api/admin/#tag/Region), you can manage regions in your store, including creating, updating, and deleting regions.
### Scenario
You want to add or use the following admin functionalities:
- List regions
- Create a region
- Update a region
- Add shipping options to a region
- Delete a Region
:::info
You can use Medusas Admin APIs to achieve more functionalities as well. Check out the [API reference](/api/admin/#tag/Region) to learn more.
:::
---
## Prerequisites
### Medusa Components
It is assumed that you already have a Medusa server installed and set up. If not, you can follow the [quickstart guide](../../quickstart/quick-start.md) to get started.
### JS Client
This guide includes code snippets to send requests to your Medusa server using Medusas JS Client, JavaScripts Fetch API, or cURL.
If you follow the JS Client code blocks, its assumed you already have [Medusas JS Client](../../js-client/overview.md) installed and have [created an instance of the client](../../js-client/overview.md#configuration).
### Authenticated Admin User
You must be an authenticated admin user before following along with the steps in the tutorial.
You can learn more about [authenticating as an admin user in the API reference](/api/admin/#section/Authentication).
---
## List Regions
You can retrieve regions available on your server using the [List Regions](/api/admin/#tag/Region/operation/GetRegions) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.admin.regions.list()
.then(({ regions, limit, offset, count }) => {
console.log(regions.length);
//display regions
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/admin/regions`, {
credentials: 'include',
})
.then((response) => response.json())
.then(({ regions, limit, offset, count }) => {
console.log(regions.length);
//display regions
});
```
</TabItem>
<TabItem value="curl" label="cURL">
```bash
curl -L -X GET '<SERVER_URL>/admin/regions' \
-H 'Authorization: Bearer <API_TOKEN>'
```
</TabItem>
</Tabs>
This request returns an array of regions, as well as [pagination fields](/api/admin/#section/Pagination).
You can also pass filters and other selection query parameters to the request. Check out the [API reference](/api/admin/#tag/Region/operation/GetRegions) for more details on available query parameters.
---
## Create a Region
You can create a region by sending a request to the [Create a Region](/api/admin/#tag/Region/operation/PostRegions) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.admin.regions.create({
name: 'Europe',
currency_code: 'eur',
tax_rate: 0,
payment_providers: [
'manual'
],
fulfillment_providers: [
'manual'
],
countries: [
'DK'
]
})
.then(({ region }) => {
console.log(region.id);
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/admin/regions`, {
credentials: 'include',
method: 'POST',
body: JSON.stringify({
name: 'Europe',
currency_code: 'eur',
tax_rate: 0,
payment_providers: [
'manual'
],
fulfillment_providers: [
'manual'
],
countries: [
'DK'
]
})
})
.then((response) => response.json())
.then(({ region }) => {
console.log(region.id);
});
```
</TabItem>
<TabItem value="curl" label="cURL">
```bash
curl -L -X POST '<SERVER_URL>/admin/regions' \
-H 'Authorization: Bearer <API_TOKEN>' \
-H 'Content-Type: application/json' \
--data-raw '{
"name": "Europe",
"currency_code": "eur",
"tax_rate": 0,
"payment_providers": [
"manual"
],
"fulfillment_providers": [
"manual"
],
"countries": [
"DK"
]
}'
```
</TabItem>
</Tabs>
This request requires the following body parameters:
- `name`: The name of the region.
- `currency_code`: The 3 character ISO currency code.
- `tax_rate`: The tax rate in the Region.
- `payment_providers`: An array of payment provider IDs. The array must contain at least one item.
- `fulfillment_providers`: An array of fulfillment provider IDs. The array must contain at least one item.
- `countries`: An array of the 2 character ISO code of the countries included in the region.
This request also accepts optional parameters, which you can view in the [API reference](/api/admin/#tag/Region/operation/PostRegions).
The request returns the created region in the response.
---
## Update a Region
You can update any of the regions fields and configurations. The REST APIs offer different APIs for updating specific configurations, such as the [Add Country](/api/admin/#tag/Region/operation/PostRegionsRegionCountries) endpoint.
Alternatively, you can update the details of a region using the [Update a Region](/api/admin/#tag/Region/operation/PostRegionsRegion) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.admin.regions.update(regionId, {
countries: [
"DK",
"DE"
]
})
.then(({ region }) => {
console.log(region.id);
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/admin/regions/${regionId}`, {
credentials: 'include',
method: 'POST',
body: JSON.stringify({
countries: [
'DK',
'DE'
]
})
})
.then((response) => response.json())
.then(({ region }) => {
console.log(region.id);
});
```
</TabItem>
<TabItem value="curl" label="cURL">
```tsx
curl -L -X POST '<SERVER_URL>/admin/regions/<REGION_ID>' \
-H 'Authorization: Bearer <API_TOKEN>' \
-H 'Content-Type: application/json' \
--data-raw '{
"countries": [
"DK",
"DE"
]
}'
```
</TabItem>
</Tabs>
This request accepts in its body parameters any of the regions fields that you want to update. In the example above, you update the list of countries that are included in that region.
You can see the list of accepted fields in the [API reference](/api/admin/#tag/Region/operation/PostRegionsRegion).
This request returns the full object of the updated region.
:::tip
In the example above, the list of countries replace any countries that were previously in the region. So, if youre adding a country, make sure to include previously added countries as well.
:::
---
## Add a Shipping Option to a Region
You can add a shipping option to a region by sending a request to the [Create Shipping Option](/api/admin/#tag/Shipping-Option/operation/PostShippingOptions) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.admin.shippingOptions.create({
name: 'PostFake',
region_id: regionId,
provider_id: "manual",
data: {
},
price_type: 'flat_rate',
amount: 1000
})
.then(({ shipping_option }) => {
console.log(shipping_option.id);
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/admin/shipping-options`, {
credentials: 'include',
method: 'POST',
body: JSON.stringify({
name: 'PostFake',
region_id: regionId,
provider_id: "manual",
price_type: 'flat_rate',
data: {
},
amount: 1000
})
})
.then((response) => response.json())
.then(({ shipping_option }) => {
console.log(shipping_option.id);
});
```
</TabItem>
<TabItem value="curl" label="cURL">
```tsx
curl -L -X POST '<SERVER_URL>/admin/shipping-options' \
-H 'Authorization: Bearer <API_TOKEN>' \
-H 'Content-Type: application/json' \
--data-raw '{
"name": "PostFake",
"region_id": "<REGION_ID>",
"provider_id": "manual",
"price_type": "flat_rate",
"data": {},
"amount": 1000
}'
```
</TabItem>
</Tabs>
This request requires the following body parameters:
- `name`: The name of the shipping option.
- `region_id`: The ID of the region.
- `provider_id`: The ID of the fulfillment provider. The fulfillment provider must be enabled in the region.
- `data`: An object of data needed for the fulfillment provider to handle shipping with this shipping option. If none is required, you can pass an empty object.
- `price_type`: The price type of the shipping option. Can be `flat_rate` for fixed price, or `calculated` for prices that are calculated using custom logic.
- If `price_type` is `flat_rate`, the `amount` field is then required. It is the price of the shipping option. If `price_type` is `calculated`, `amount` is not required.
The `is_return` body parameter can also be passed if the shipping option is a return shipping option. Its boolean value indicates whether the shipping option is a return option or not.
This request accepts other optional body parameters, which you can learn more about in the [API reference](/api/admin/#tag/Shipping-Option/operation/PostShippingOptions).
This request returns the created shipping option.
:::tip
You can also manage shipping options such as list, update, and delete. You can learn more in the [API reference](/api/admin/#tag/Shipping-Option).
:::
---
## Delete a Region
You can delete a region by sending a request to the [Delete a Region](/api/admin/#tag/Region/operation/DeleteRegionsRegion) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.admin.regions.delete(regionId)
.then(({ id, object, deleted }) => {
console.log(id);
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/admin/regions/${regionId}`, {
credentials: 'include',
method: 'DELETE'
})
.then((response) => response.json())
.then(({ id, object, deleted }) => {
console.log(id);
});
```
</TabItem>
<TabItem value="curl" label="cURL">
```tsx
curl -L -X DELETE '<SERVER_URL>/admin/regions/<REGION_ID>' \
-H 'Authorization: Bearer <API_TOKEN>'
```
</TabItem>
</Tabs>
This request requires the region ID as a path parameter. It deletes the region and returns the following fields:
- `id`: The ID of the deleted region.
- `object`: The type of object that was deleted. In this case, the value will be `region`.
- `deleted`: A boolean value indicating whether the region was deleted.
---
## Whats Next
- Learn more about [Regions architecture](../backend/regions/overview.md).
- Learn [how to use Regions on the storefront](../storefront/use-regions.mdx).
@@ -24,8 +24,6 @@ Discounts can be used in many use cases including:
2. Creating a sale within a specific period of time (for example, a summer sale).
3. Give your customers free shipping for a limited time.
![Discounts Architecture](https://res.cloudinary.com/dza7lstvk/image/upload/v1669900544/Medusa%20Docs/Diagrams/discounts_cdxec1.jpg)
---
## Discount Entity Overview
@@ -96,6 +94,8 @@ Based on the value of `type`, one of the following relations can be used to retr
- `product_tags` is an array of product types that this condition applies to if the conditions `type` is `product_tags`. Each item of the array would be a [`DiscountConditionProductTag`](../../../references/entities/classes/DiscountConditionProductTag.md).
- `customer_groups` is an array of product types that this condition applies to if the conditions `type` is `customer_groups`. Each item of the array would be a [`DiscountConditionCustomerGroup`](../../../references/entities/classes/DiscountConditionCustomerGroup.md).
![Discounts Architecture](https://res.cloudinary.com/dza7lstvk/image/upload/v1669900544/Medusa%20Docs/Diagrams/discounts_cdxec1.jpg)
---
## Whats Next
@@ -0,0 +1,117 @@
# Regions Overview
In this document, youll learn about Regions and their importance in your Medusa server.
## Introduction
Regions represent at least one country on your Medusa server. They're used to define different business logic and configurations for a set of countries.
For example, you can enable one payment provider for region A, and a different payment provider for region B. Customers can then use the payment provider enabled in their region.
This applies to other relations and entities in your store such as different currencies, fulfillment providers, and tax providers.
---
## Region Configurations
The following configurations can be set for each region:
1. The currency used.
2. The tax provider and rates.
3. The countries that belong to that region. A country can only belong to one region.
4. The enabled payment providers.
5. The enabled fulfillment providers.
6. The shipping and return shipping options.
---
## One vs Multiple Regions
Your store needs at least one region so that your customers can place orders.
If you serve customers in different countries that use the same configurations, such as the same currency and payment providers, then you can include more countries in the same region.
If you serve customers in different countries that have at least one different configuration, such as different payment providers, you need to create a new region for those countries.
There is no limit on how many regions you can create, and regions can share similar configurations.
---
## Region Entity Overview
A region is stored in the database as a [Region](../../../references/entities/classes/Region.md) entity. Some of its important attributes are:
- `name`: The name of the region. Customers will see this name on the storefront.
- `tax_rate`: A number that indicates the tax rate. The tax rate is a percentage.
- `tax_code`: An optional string that is used as the code for the default tax rate.
- `gift_cards_taxable`: A boolean value that indicates whether gift cards in a region are taxable or not.
- `automatic_taxes`: A boolean value that indicates whether taxes should be calculated during checkout automatically or manually for that region. You can learn more about manually calculating taxes in [this documentation](../taxes/manual-calculation.md).
---
## Relations to Other Entities
As regions are a core part of your Medusa server, there are many relations to other entities.
This section covers relations to entities that make up the configurations of a region.
![Regions Relations Overview](https://res.cloudinary.com/dza7lstvk/image/upload/v1671465082/Medusa%20Docs/Diagrams/Regions_cg8hsi.jpg)
### Country
A region must have at least one country. A country can belong to only one region.
The relation between the `Region` and `Country` entities is available on both entities:
- You can access the countries that belong to a region by expanding the `countries` relation and accessing `region.countries`.
- You can access the region of a country by expanding the `region` relation and accessing `country.region`. Also, you can access the ID of the region through `country.region_id`.
### Currency
A region must have one currency. A currency can be used for more than one region.
The relation is available on a region by expanding the `currency` relation and accessing `region.currency`. The 3 character currency code can also be accessed through `region.currency_code`.
### FulfillmentProvider
A region must have at least one fulfillment provider. A fulfillment provider can be used in more than one region.
The relation is available on a region by expanding the `fulfillment_providers` relation and accessing `region.fulfillment_providers`.
### PaymentProvider
A region must have at least one payment provider. A payment provider can be used in more than one region.
The relation is available on a region by expanding the `payment_providers` relation and accessing `region.payment_providers`.
### ShippingOption
:::info
Both shipping options and return shipping options are represented by the `ShippingOption` entity. You can learn more in the [Shipping Architecture documentation](../shipping/overview.md#shipping-option).
:::
More than one shipping option can belong to a region. The relation is available on a shipping option by expanding the `region` relation and accessing `shipping_option.region`.
### TaxProvider
A region can have one tax provider. A tax provider can be used for more than one region.
The relation is available on a region by expanding the `tax_provider` relation and accessing `region.tax_provider`. You can also access the ID of the tax provider through `region.tax_provider_id`.
### TaxRate
A region can have more than one tax rate, and a tax rate belongs to one region.
The relation between the `Region` and `TaxRate` entities is available on both entities:
- You can access the tax rates of a region by expanding the `tax_rates` relation and accessing `region.tax_rates`.
- You can access the region of a tax rate by expanding the `region` relation and accessing `tax_rate.region`. You can also access the ID of the region through `tax_rate.region_id`.
---
## Whats Next
- Learn [how to use regions in a storefront using the store REST APIs](../../storefront/use-regions.mdx).
- Learn how to [manage regions using the admin REST APIs](../../admin/manage-regions.mdx).
@@ -0,0 +1,57 @@
---
description: 'Actions Required for Vite Update'
---
# Updating Medusa Admin from Gatsby to Vite
Medusa Admin has been updated to Vite. Learn about breaking changes since the update.
## Overview
Medusa Admin previously was built using Gatsby. As of a recent update, the Admin is now migrated to Vite 3.
This introduced breaking changes related to environment variables used and the published directory. Read below for actions required following this update.
## Required Node.js Version
<!-- vale docs.Numbers = NO -->
Following the change to Vite 3, the required Node.js version for the Admin has changed. [Vite 3](https://vitejs.dev/guide/#scaffolding-your-first-vite-project) requires versions 14.8+ or 16+ of Node.js.
<!-- vale docs.Numbers = YES -->
## Changed Environment Variables
Previously, the Medusa Admin used the environment variables `GATSBY_MEDUSA_BACKEND_URL` or `GATSBY_STORE_URL` to store the Medusa servers URL.
After the update to Vite, the environment variable name changed to `MEDUSA_BACKEND_URL`.
The Medusa admin remains backward compatible, which means you can still use the same environment variables. However, it is advised to make the change to the new variable.
### Actions Required
Change your `GATSBY_MEDUSA_BACKEND_URL` or `GATSBY_STORE_URL` environment variables to be `MEDUSA_BACKEND_URL`:
```bash
MEDUSA_BACKEND_URL=<YOUR_MEDUSA_SERVER_URL>
```
## Changed Publish Directory
Previously, the build output of the Medusa Admin was placed in the `dist` directory. After this update, the build output is placed in the `public` directory.
For local usage and development, this shouldnt have an effect. However, this is a breaking change if you deployed Medusa admin.
### Actions Required
If you deployed your Medusa admin, you must change the Publish directory in your hosting.
For Netlify, you can do that by following these steps:
1. On your Medusa admin dashboard, click on “Site settings”.
2. From the sidebar, choose “Build & deploy”.
3. Find the “Build settings” section and click on the “Edit settings” button.
4. Change the “Publish directory” field to `public`.
5. Click on the Save button.
This should trigger a new deployment of your Medusa admin. If not, you must redeploy it manually for changes to take effect.
@@ -1,8 +1,19 @@
---
hide_table_of_contents: true
---
import DocCardList from '@theme/DocCardList';
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
import filterListItems from '@site/src/utils/filterListItems';
# Upgrade Guides
Find in this page the upgrade guides that require necessary steps when upgrading to a new version.
<DocCardList items={useCurrentSidebarCategory().items}/>
## Server
<DocCardList items={filterListItems(useCurrentSidebarCategory().items, /^(?!.*\/admin\/).*$/)}/>
## Admin
<DocCardList items={filterListItems(useCurrentSidebarCategory().items, /\/admin\//)}/>
@@ -0,0 +1,175 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
# Use Regions in the Storefront
In this document, youll learn how to use Regions in the storefront.
## Overview
Regions represent the supported countries and currencies in your store. Customers can use the region that fits them based on their country and currency.
### Scenario
You want to implement the following in your storefront:
- Show customers available regions.
- Show product prices based on the selected region.
- Set a carts region to the selected region.
---
## Prerequisites
### Medusa Components
It's assumed that you already have a Medusa server installed and set up. If not, you can follow our [quickstart guide](../../quickstart/quick-start.md) to get started.
It is also assumed you already have a storefront set up. It can be a custom storefront or one of Medusas storefronts. If you dont have a storefront set up, you can install either the [Next.js](../../starters/nextjs-medusa-starter.md) or [Gatsby](../../starters/gatsby-medusa-starter.md) storefronts.
### JS Client
This guide includes code snippets to send requests to your Medusa server using Medusas JS Client and JavaScripts Fetch API.
If you follow the JS Client code blocks, its assumed you already have [Medusas JS Client installed](../../js-client/overview.md) and have [created an instance of the client](../../js-client/overview.md#configuration).
---
## Show List of Regions
Customers should be able to see the list of available regions and select their region.
You can retrieve available regions by sending a request to the [List Regions](/api/store/#tag/Region/operation/GetRegions) endpoint:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.regions.list()
.then(({ regions }) => {
console.log(regions.length);
//show customers available regions
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/store/regions`, {
credentials: 'include',
})
.then((response) => response.json())
.then(({ regions }) => {
console.log(regions.length);
//show customers available regions
});
```
</TabItem>
</Tabs>
This request returns the list of available regions. You can show them to your customers to select their region.
When a customer selects a region, you should store that regions ID. Youll need it to show the customer product prices based on the selected region, and set the region of their cart.
---
## Show Product Prices Based on the Selected Region
To retrieve products with the prices based on the selected regions, you can pass the `region_id` query parameter to the [List Products](/api/store/#tag/Product/operation/GetProducts) or [Get a Product](/api/store/#tag/Product/operation/GetProductsProduct) endpoints.
For example:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.products.list({
region_id: regionId
})
.then(({ products, limit, offset, count }) => {
console.log(products.length);
//show customer the products
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/store/products?region_id=${regionId}`, {
credentials: 'include',
})
.then((response) => response.json())
.then(({ products, limit, offset, count }) => {
console.log(products.length);
//show customer the products
});
```
</TabItem>
</Tabs>
In this example, you send a request to the List Products endpoint, passing it the `region_id` query parameter. It is assumed that you have the ID of the region stored in the variable `regionId`.
This request returns the list of products along with [pagination fields](/api/store/#section/Pagination). The prices of the products are based on the selected region.
---
## Set a Carts Region
When the customer changes their region, you must also reflect that change on their cart.
You can set the carts region while creating it and later on by updating it.
:::tip
You can learn how to implement cart functionalities in your storefront in [this documentation](../../guides/carts-in-medusa.mdx).
:::
For example:
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```tsx
medusa.carts.update(cartId, {
region_id: regionId
})
.then(({ cart }) => {
console.log(cart.id);
});
```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```tsx
fetch(`<SERVER_URL>/store/carts/${cartId}`, {
method: 'POST',
credentials: 'include',
body: JSON.stringify({
region_id: regionId
})
})
.then((response) => response.json())
.then(({ cart }) => {
console.log(cart.id);
});
```
</TabItem>
</Tabs>
In this example, you send a request to the [Update Cart](/api/store/#tag/Cart/operation/PostCartsCart) endpoint. In the requests body, you pass the parameter `region_id` and set its value to the selected regions ID. It is assumed that you have the ID of the region stored in the variable `regionId`.
This request returns the full object of the updated cart.
---
## Whats Next
- Learn [how to implement cart functionalities in your storefront](../../guides/carts-in-medusa.mdx)
- Learn [how to implement checkout in your storefront](./how-to-implement-checkout-flow.mdx)
@@ -77,10 +77,10 @@ If you don't have a payment method set up in your Heroku account, you'll be aske
Add a Postgres add-on to your Heroku app with the following command:
```bash
heroku addons:create heroku-postgresql:hobby-basic
heroku addons:create heroku-postgresql:mini
```
This uses Heroku Postgres's basic plan. You can check out [the available plans and pricing of Heroku Postgres on Heroku's website.](https://elements.heroku.com/addons/heroku-postgresql#pricing)
This uses Heroku Postgres's smallest plan. You can check out [the available plans and pricing of Heroku Postgres on Heroku's website.](https://elements.heroku.com/addons/heroku-postgresql#pricing)
#### Redis
@@ -127,6 +127,12 @@ You can install Medusas CLI with the following command:
npm install @medusajs/medusa-cli -g
```
You can check that Medusa was installed by running the following command:
```bash noReport
medusa -v
```
:::note
If you run into any errors while installing the CLI tool, check out the [troubleshooting guide](../troubleshooting/cli-installation-errors.mdx).
@@ -1,70 +0,0 @@
---
title: Linking your local project with Medusa Cloud
---
<!-- vale off -->
# Linking your local project with Medusa Cloud
## Introduction
In this part of the tutorial you will learn how to link your local Medusa project to Medusa Cloud. Doing this will enhance you development experience as you will closely mimic how Medusa would work in a production environment. Furthermore, you will be able to easily manage orders and products in your local project directly from Medusa Cloud. Linking Medusa is easily done with the Medusa CLI which you should already be installed when you set up your development environment.
## Creating a Medusa Cloud account and CLI authentication
To link your local project you must first authenticate to Medusa using your CLI. Authenticating with the CLI is done by running:
```shell
medusa login
```
The `login` command will open your browser where you will be presented with the authentication options available. If you already have an account you can simply authenticate and you CLI will automatically be authenticated.
If you don't have an account yet you can easily create one as part of the CLI authentication. First, choose the method that you want to login with we support logging in with GitHub, Google or simple email/password authentication. If choosing GitHub or Google without an existing account you will be taken straight to the sign up form where you can fill in your details and create an account. If you wish to sign up with an email/password combination simply click "Log in with email" and at the bottom of the form click "Sign up". Once you have filled out the sign up form your CLI will be authenticated.
To test that you have successfully authenticated you can run:
```shell
medusa whoami
```
This will print out your account details.
## Linking your local project
Once you have authenticated your CLI for your Medusa Cloud account you are ready to perform local linking. To link your project first naviagate to your project root - where your `medusa-config.js` file is. You can now run the following command:
```shell
medusa link --develop
```
The `link` command will first check that you have authenticated your CLI which we did in the previous step. Then it will perform the local linking, which essentially adds an admin user in the local database specified in `medusa-config.js`. Finally, your browser will open Medusa Cloud to perform the linking there, which tells Medusa Cloud where your local server is running. On successful linking in the browser you will see a confirmation page with a "Go to orders" button. If you click this button you will be taken to an overview of the orders made in your local project.
You should note that the `--develop` flag is optional for the `link` command. If provided it tells the CLI to start up your server after linking is completed; you may leave it out if you'd rather start your server separately.
:::note
For local linking to work you must make sure to have your CORS settings configured correctly. This is done by adding `https://app.medusajs.com` to your `cors_admin` config in `medusa-config.js`.
:::
:::note
If you change the port that your local server is running on you will have to run `medusa link` again. `medusa link` uses your `PORT` environment variable to specify where Medusa Cloud should look for your local server.
:::
## Summary
You are now able to run a local development environment that is nearly identical to a production environment. This is made possible by linking your local project using the `medusa link` command. In Medusa Cloud you will be able to manage your store and test the features you are developing.
### What's next?
You are all set to start developing on your Medusa project. If you haven't already now would be a good time to add a front-end to your Medusa server. We have two starters that you can use to get going:
- [Nextjs Starter](https://github.com/medusajs/nextjs-starter-medusa)
- [Gatsby Starter](https://github.com/medusajs/gatsby-starter-medusa)
The final step to take from here is to deploy your Medusa project. We will cover how this is done in the next part of the tutorial (Coming soon!).
<!-- vale on -->
+8
View File
@@ -80,6 +80,14 @@ DATABASE_URL=<YOUR_DATABASE_URL>
Where `<YOUR_DATABASE_URL>` is the URL of your PostgreSQL database.
### Changing Database Type
Remember to run migrations after you change your database type to `postgres` from another type:
```bash
medusa migrations run
```
### Common Configuration
As Medusa internally uses [Typeorm](https://typeorm.io/) to connect to the database, the following configurations are also available:
+1 -1
View File
@@ -1,4 +1,4 @@
# Local Development
# Local Development of Medusa Server and Monorepo
In this document, youll learn how to customize Medusas core and run tests.
@@ -1,12 +0,0 @@
---
sidebar_position: 3
hide_footer: true
---
# Manage Custom Gift Cards
:::note
This guide is coming soon.
:::
@@ -0,0 +1,83 @@
---
sidebar_position: 3
---
import UiIcon from '@site/src/components/UiIcon';
# Manage Custom Gift Cards
In this document, youll learn how to manage custom gift cards, including how to create and update them.
## Create Custom Gift Card
To create a custom gift card:
1. Go to Gift Cards from the sidebar.
2. Click on the Custom Gift Card button at the top right of the History section.
3. In the new form that opens:
1. Select in the Region field the region this gift card works in. You can only pick one region. Based on the region you pick, the currency of the gift card will automatically change.
2. Enter in the Amount field the amount of the gift card.
3. Enter in the Email field the email of the customer that will receive this gift card.
4. You can optionally enter in the Personal Message field any message you want the customer to receive with this gift card.
4. Once done, click on Create & Send.
The gift card will be created with a random code. The customer will then receive an email with details about their gift card.
:::note
If the customer doesnt receive an email, please get in touch with your technical team to ensure an email service is set up correctly.
:::
---
## View a Custom Gift Cards Details
To view a custom gift cards details:
1. Go to Gift Cards from the sidebar.
2. In the History section, find the custom gift card and click on it.
This opens the gift cards details page.
---
## Edit a Custom Gift Card
### Change Region of Custom Gift Card
:::info
Changing the region of a custom gift card will change the currency of the gift card to the new regions currency.
:::
To change the region of a custom gift card:
1. Go to the custom gift cards details page.
2. Click on the <UiIcon lightIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999308/Medusa%20Docs/UI%20Icons/1ordBC6_ssysel.png" darkIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999326/Medusa%20Docs/UI%20Icons/dSwWYBH_stzgoi.png" alt="three dots" /> icon at the top right of the first section.
3. Click on Edit from the dropdown.
4. In the new window that opens:
1. Select in the Region field the region you want this gift card to work in.
5. Once done, click on the Save button.
### Update Balance of Custom Gift Card
To update the balance of a custom gift card:
1. Go to the custom gift cards details page.
2. Click on the <UiIcon lightIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999308/Medusa%20Docs/UI%20Icons/1ordBC6_ssysel.png" darkIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999326/Medusa%20Docs/UI%20Icons/dSwWYBH_stzgoi.png" alt="three dots" /> icon at the top right of the first section.
3. Click on “Update balance” from the dropdown.
4. In the new window that opens:
1. Enter in the Price field the new balance.
5. Once done, click on the Save button.
### Change Custom Gift Card Status
You can disable or activate a custom gift card. If you disable a gift card, customers cant use it during checkout.
To change a custom gift cards status:
1. Go to the custom gift cards details page.
2. Click on the <UiIcon lightIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999308/Medusa%20Docs/UI%20Icons/1ordBC6_ssysel.png" darkIcon="https://res.cloudinary.com/dza7lstvk/image/upload/v1667999326/Medusa%20Docs/UI%20Icons/dSwWYBH_stzgoi.png" alt="three dots" /> icon at the top right of the first section.
3. Click on Disable or Activate from the dropdown based on the current status.
+9 -1
View File
@@ -10,9 +10,17 @@ In this document, youll learn about how Gift Cards in Medusa work.
In Medusa, theres one main gift card. A gift card can have multiple denominations. For example, a Gift Card can have the amounts of $20 and $50, and customers can buy one of these denominations.
---
## Custom Gift Cards
You can also create custom gift cards in Medusa. These cards can be created and sent directly to a customers email.
To view the list of available custom gift cards, from the sidebar go to Gift Cards. You can find all custom gift cards in the History section.
---
## Learn More About Gift Cards
- [Manage Gift Cards](./manage.mdx)
- [Manage Custom Gift Cards](./custom.md)
- [Manage Custom Gift Cards](./custom.mdx)
+2 -1
View File
@@ -1,4 +1,5 @@
(?i)Medusa
(?i)Qovery
(?i)Netlify
(?i)s3
(?i)s3
(?i)vite
+1 -1
View File
@@ -1 +1 @@
{"id":"https://github.com/medusajs/medusa/releases/tag/v1.7.0","content":"v1.7.0 is out","isCloseable":true}
{}
+35 -3
View File
@@ -199,12 +199,29 @@ module.exports = {
id: "advanced/backend/upgrade-guides/1-7-0",
label: "v1.7.0"
},
{
type: "doc",
id: "advanced/backend/upgrade-guides/admin/admin-vite",
label: "Medusa Admin: Vite"
},
]
},
{
type: "doc",
id: "usage/local-development",
},
type: "category",
label: 'Local Development',
items: [
{
type: "doc",
id: "usage/local-development",
label: "Server and Monorepo"
},
{
type: "doc",
id: "admin/development",
label: "Medusa Admin"
}
]
}
]
},
{
@@ -215,6 +232,11 @@ module.exports = {
type: "category",
label: "Storefront",
items: [
{
type: "doc",
id: "advanced/storefront/use-regions",
label: "Use Regions"
},
{
type: "doc",
id: "guides/carts-in-medusa",
@@ -251,6 +273,11 @@ module.exports = {
type: "category",
label: "Admin",
items: [
{
type: "doc",
id: "advanced/admin/manage-regions",
label: "Manage Regions"
},
{
type: "doc",
id: "advanced/admin/import-products",
@@ -412,6 +439,11 @@ module.exports = {
id: "advanced/backend/batch-jobs/index",
label: "Batch Jobs"
},
{
type: "doc",
id: "advanced/backend/regions/overview",
label: "Regions"
},
{
type: "doc",
id: "advanced/backend/taxes/inclusive-pricing",
+9
View File
@@ -0,0 +1,9 @@
export default function filterListItems (items: any[], pathPattern: string | RegExp) {
if (!items.length) {
return items
}
let pattern = new RegExp(pathPattern)
return items.filter((item) => pattern.test(item.href))
}