* initialized next.js project * finished markdown sections * added operation schema component * change page metadata * eslint fixes * fixes related to deployment * added response schema * resolve max stack issue * support for different property types * added support for property types * added loading for components * added more loading * type fixes * added oneOf type * removed console * fix replace with push * refactored everything * use static content for description * fixes and improvements * added code examples section * fix path name * optimizations * fixed tag navigation * add support for admin and store references * general enhancements * optimizations and fixes * fixes and enhancements * added search bar * loading enhancements * added loading * added code blocks * added margin top * add empty response text * fixed oneOf parameters * added path and query parameters * general fixes * added base path env variable * small fix for arrays * enhancements * design enhancements * general enhancements * fix isRequired * added enum values * enhancements * general fixes * general fixes * changed oas generation script * additions to the introduction section * added copy button for code + other enhancements * fix response code block * fix metadata * formatted store introduction * move sidebar logic to Tags component * added test env variables * fix code block bug * added loading animation * added expand param + loading * enhance operation loading * made responsive + improvements * added loading provider * fixed loading * adjustments for small devices * added sidebar label for endpoints * added feedback component * fixed analytics * general fixes * listen to scroll for other headings * added sample env file * update api ref files + support new fields * fix for external docs link * added new sections * fix last item in sidebar not showing * move docs content to www/docs * change redirect url * revert change * resolve build errors * configure rewrites * changed to environment variable url * revert changing environment variable name * add environment variable for API path * fix links * fix tailwind settings * remove vercel file * reconfigured api route * move api page under api * fix page metadata * fix external link in navigation bar * update api spec * updated api specs * fixed google lint error * add max-height on request samples * add padding before loading * fix for one of name * fix undefined types * general fixes * remove response schema example * redesigned navigation bar * redesigned sidebar * fixed up paddings * added feedback component + report issue * fixed up typography, padding, and general styling * redesigned code blocks * optimization * added error timeout * fixes * added indexing with algolia + fixes * fix errors with algolia script * redesign operation sections * fix heading scroll * design fixes * fix padding * fix padding + scroll issues * fix scroll issues * improve scroll performance * fixes for safari * optimization and fixes * fixes to docs + details animation * padding fixes for code block * added tab animation * fixed incorrect link * added selection styling * fix lint errors * redesigned details component * added detailed feedback form * api reference fixes * fix tabs * upgrade + fixes * updated documentation links * optimizations to sidebar items * fix spacing in sidebar item * optimizations and fixes * fix endpoint path styling * remove margin * final fixes * change margin on small devices * generated OAS * fixes for mobile * added feedback modal * optimize dark mode button * fixed color mode useeffect * minimize dom size * use new style system * radius and spacing design system * design fixes * fix eslint errors * added meta files * change cron schedule * fix docusaurus configurations * added operating system to feedback data * change content directory name * fixes to contribution guidelines * revert renaming content * added api-reference to documentation workflow * fixes for search * added dark mode + fixes * oas fixes * handle bugs * added code examples for clients * changed tooltip text * change authentication to card * change page title based on selected section * redesigned mobile navbar * fix icon colors * fix key colors * fix medusa-js installation command * change external regex in algolia * change changeset * fix padding on mobile * fix hydration error * update depedencies
4.8 KiB
description
| description |
|---|
| In this document, you’ll learn about the inventory module, how it works, and its relation to other processes in your commerce application. |
Stock Level Module
In this document, you’ll learn about the Stock Level module and how it works.
Overview
A stock location indicates a physical address that stock-kept items can be stored in. The stock location module handles functionalities related to managing stock locations and their addresses.
Medusa's Stock Location module is a standalone module that can be used in any commerce application, not just in a Medusa backend. This document gives a general overview of how the stock location module is designed, and highlights how the Medusa core orchestrates relations around this module when it's used with the Medusa backend.
StockLocation Entity
The StockLocation entity represents a stock location. It has minimal attributes including a name attribute. It’s associated with the StockLocationAddress entity.
StockLocationAddress Entity
The StockLocationAddress is an entity that contains address-related fields, such as city or country_code.
The StockLocationAddress entity belongs to the StockLocation entity. It is used to store the address details of a stock location.
How the Module Integrates into Medusa
This section explains how the Medusa backend uses the stock location module along with its entities and other modules.
Entities Relation Overview
The following entities in the Medusa backend each have an attribute that is used to associate them with a stock location:
Fulfillment: Thelocation_idattribute within theFulfillmententity is used to indicate from which stock location an order item is fulfilled.Return: Thelocation_idattribute within theReturnentity is used to indicate to which stock location an order item is returned.Store: Thedefault_location_idattribute within theStoreentity is used to indicate the default stock location to use in the ecommerce store.SalesChannelLocation: This entity is used to attach a stock location to aSalesChannel. The relation between these two entities is explained further in the Relation to Sales Channel section.
When the Medusa's Stock Location module is used with the Medusa backend, the ID that is associated with the attributes mentioned above is from the StockLocation module.
The Medusa backend also orchestrates between different modules. The Inventory Module's entities contain the following attributes to handle associations between them and a stock location:
InventoryLevel: This entity is used to indicate the stocked quantity of an inventory item in a stock location. As explained in the Inventory Module documentation, theInventoryLevelentity has an attributelocation_id.ReservationItem: This entity is used to indicate the reserved quantity of an inventory item in a stock location. As explained in the Inventory Module documentation, theReservationItementity has an attributelocation_id.
When both modules are used within the Medusa backend, the Medusa backend bridges between these modules by passing the ID of a StockLocation from the stock location module to the inventory module, and the inventory module uses the ID in its entities.
Relation to SalesChannel
A stock location can be associated with more than one sales channel. For example, a physical store and an online store can use the same stock location.
As the StockLocation and SalesChannel entities are available in separate modules, the Medusa backend handles attaching the stock location with the sales channel within the SalesChannelLocation entity.
This relation is used across the Medusa backend and within checkout and order workflows:
- When checking the availability of an inventory item during checkout, the Medusa backend retrieves the location IDs that are associated with the cart’s sales channel using the
SalesChannelLocation, then passes it along to the inventory module to perform the quantity check. - When an order is placed, the Medusa backend retrieves the location IDs that are associated with the cart’s sales channel using the
SalesChannelLocationentity, and passes it to the inventory module that reserves the ordered quantity of the inventory item from that location. The admin can later change the stock location if necessary. - When an item in an order is fulfilled, the admin chooses a stock location to fulfill the item from. Similarly, when an item in an order is returned, the admin can choose a stock location to return the item to. The Medusa backend then passes the ID of the location from the stock module to the inventory module to perform inventory management functionalities.