Extend the Store Service
Build your own marketplace from scratch using Medusa
In this part of our Medusa marketplace journey, we’ll continue building on the groundwork we established in the previous sections. This time, our focus will be on extending the StoreService
and ProductService
to ensure a seamless user experience.
What is the goal here ?
The core objective here is to guarantee that when a user logs into the admin ui, they can seamlessly access their own store based on their store_id
.
This level of personalization is crucial for providing a tailored experience within our marketplace. As you’ve noted, the approach involves extending the existing services to achieve this functionality. Let’s dive into the details.
Extend the Store Service
We’ll create a new file in the services
folder, named store.ts
, where we’ll extend the StoreService
to override the retrieve
function.
In this extended StoreService
, we override the retrieve
method to check if the logged-in user is defined and have a store_id
associated with their account. If so, we use that store_id
to retrieve that specific store information. Otherwise, we fall back to the default behavior of the StoreService
(which will just use the default store created by the Medusa core loaders)
I recommend that you adjust the store names you currently have in your database so that when you log in with a vendor account, you see the correct shop name. In reality, the default store name is Medusa Store, thus it might be easier for you to have alternative names so you don’t struggle with it.
GitHub Branch
You can access the complete part’s code here.
Next Steps
Well done, now that the right store is displayed, we will extend the products in the next part!
Was this page helpful?