Custom Line Items Without Storing Products in MedusaJS Backend #9538
Unanswered
jkuzmanovik
asked this question in
Q&A
Replies: 1 comment
-
hi @jkuzmanovik - I do not know if it is yet available, but Medusa v2 contains a lot of commerce modules, including the Product Module: https://docs.medusajs.com/v2/resources/commerce-modules/product. Probably you would need to completely replace this package by your own module, so it means you would need to implement all logic related to product module, including methods which are needed there. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem:
I'm building an eCommerce site using MedusaJS v2 for the backend and a frontend framework (like Next.js). The products I'm working with are fetched from an external API and not stored in my Medusa backend. The reason is that these products change frequently in availability, pricing, and other details, and there are millions of them, which makes it impractical to store them directly in the Medusa product catalog.
However, I still want to allow users to add these external products to the cart and proceed to checkout through MedusaJS. But as I understand, Medusa requires products and variants to be stored in the backend in order to add them to the cart.
What I've Tried:
Fetching product data dynamically from the external API: This works well for displaying products on the frontend, but when trying to add them to the cart, I run into issues since they aren't stored in the Medusa backend.
Adding custom line items: I came across a note in the documentation that says a custom line item can be added to the cart without a variant. However, I couldn't find any detailed instructions or examples on how to implement this, and attempts to add custom items without a variant_id result in errors.
The Solution I'm Looking For:
I need a way to add dynamically fetched products to the cart without storing them as products or variants in the Medusa backend. Ideally, I want to be able to:
Add a custom item to the cart by passing product information (e.g., price, description, metadata) directly to the POST /store/carts/:id/line-items API.
Skip creating or storing the product/variant in the backend for each item, as the data will be fetched in real-time from the external source.
Questions:
Is it possible to bypass the need for storing products in the Medusa backend and use custom line items to handle this kind of use case?
If the API enforces a variant_id, is there a workaround to treat a placeholder variant as a "shell" for custom items and store product data (such as price, description, etc.) in the metadata field? Is this an intended use case for Medusa?
Are there any plans to introduce better support for scenarios where products are fetched externally but still need to go through the cart and checkout flow?
Any guidance on how I can achieve this would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions