-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Custom LineItem is dependent on a Product Variants #10099
Comments
@AlexAntonides, any chance you can share what you have now in a repository? I think it would help in understanding what you are trying to achieve. Two things I'll say:
Finally, have you read our Subscription Recipe? It might be helpful, although it seems the use case is slightly different. |
Hi @olivermrbl, thank you for the response. Unfortunately, I am not able to share the code due to company policy, however, I'll try to explain the intent as clear as possible with code snippets. First things first, we don't use the admin dashboard. We use our own front-end application that uses the Medusa backend, hence the reason why we do use draft orders on our side. Second, I'm glad that custom line items are on the roadmap, as this is necessary for us to support custom order-able items that are not typical We've checked the subscription recipe earlier and while it's useful, it doesn't support our use case, considering the recipe is more centred around implementing a recurring order (repeating the same order in an interval), rather than offering specific subscriptions products, such as cloud services, that can be bought alongside other products/variants. We've also thought about extending the product, however, this doesn't support our use case either, considering we need a more detailed subscription services that separates the billing from entitlement architecture, with tiers, various plans and different add-on packages. This is significantly different than the products/variants approach, and extending these entities would result in a bunch of dirty hacks to support our goals (i.e. the subscription/tier/plan layers, and some minor details, for example, a subscription doesn't have a SKU (which is mandatory for a variant)). So, our goal for now has been to create a module with this entire architecture, with the intend to extend the LineItem to support the order of these custom entities, considering the LineItems are fairly decoupled from the products/variants (LineItems do not require/do not depend on these entities), through the use of custom line items (Which only requires a title and some unit pricing details, according to the DTO) (except for the part that I described above, with the line that sets the We've seen in the DTO, that the products and variants are "attached" to these line items by adding the optional properties ( export interface OrderLineItemDTO extends OrderLineItemTotalsDTO {
[...]
title: string,
product_id?: string,
product_title?: string,
variant_id?: string,
variant_title?: string, // This time, undefined, when no variant data is supplied
variant_sku?: string, // This time, optional, rather than ""optional"" (secretly required)
[...]
additional_data?: {
subscription_id?: string,
subscription_title?: string,
[...]
tier_id?: string,
tier_title?: string,
[...]
plan_id?: string,
[...]
bundle_id?: string,
bundle_title?: string,
}
[...]
} With the thought that the LineItems would still work (because the required While we can wait for Medusa to support the extension of these custom line items, the requirement of variant data (sku/barcode) and setting the As to our understand, the |
@AlexAntonides, thanks for sharing your use case in detail. It helps a lot. I am currently scoping out the support for custom line items, and I have a few questions about your subscription and bundle use cases. Any chance we could jump on a call? If so, how can I reach you? We can summarise our conversation in the issue here afterward for transparency for the community. |
@olivermrbl, thank you for your response and interest in my use case. I'm happy to provide more details. I think the best way to reach me is through the Medusa Discord Community. My server nickname is "AlexAntonides"! |
@AlexAntonides, I couldn't find you on Discord. Can you ping me in private DMs? |
Any news on this? |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
This issue was closed because it has been stalled for 3 days with no activity. |
Package.json file
Node.js version
v20.17.0
Database and its version
PostgreSQL v10.4
Operating system name and version
macOS Sequoia 15.1
Browser name
No response
What happended?
I've been working on a Subscription module, with custom subscription models, rather than extending the product/variant entities with
additional_data
. However, I'd like to be able to attach these custom models to a LineItem of a cart/order, but I'm having a hard time to implement this.Similarly to how products/variants are linked to orders, my idea was to extend the OrderLineItem model to add the properties
{ subscription_id, subscription_title, [...], }
toadditional_data
.My hope for this is that I would be able to create a LineItem
{ title: subscription.title, [...] }
and add the subscription data to theadditional_data { subscription_title: subscription.title, [...] }
(which is how products/variants are linked to LineItems).However, while testing, I've noticed that LineItems are somewhat dependent on products/variants, rather than being standalone as promised.
When I create a DraftOrder through the API (
POST /admin/draft-orders
) with the following data,I receive the error,
Later on I figured out that this was because the
sku
property is required, even though both the validator and the DTO define the property as optional.But I also noticed that in the Order workflow, in the case of a "custom line item", the variant is attached and the variant_sku/variant_title properties are placed using the given item (
variant_title: item.title
).This gives me the feeling that the LineItem of the Order Module is not truly decoupled from the rest of the modules, because it still tries to link itself to a products/variants from the Product Module.
While I could try to make this work by adding a hack like adding a SKU to my subscription (which I don't want), or to set the SKU to a random value or to ignore all "variant_titles", it feels like it's better to not set the
variant_title
/variant_sku
/variant_barcode
on a custom line item, because according to the DTO, these properties are optional anyway.Expected behavior
I expect the
variant_title
/variant_sku
/variant_barcode
properties on the OrderLineItem to be optional, considering both the DTO and Validator says it is.So, when I
POST /admin/draft-orders
) with body,I expect a Custom LineItem to be created with,
Actual behavior
POST /admin/draft-orders
) with body,Returns
POST /admin/draft-orders
) with body,returns
Link to reproduction repo
The text was updated successfully, but these errors were encountered: