Skip to content
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

Issue with Override createFromCart of OrderService. #4151

Open
NitishGameChanges opened this issue May 22, 2023 · 3 comments
Open

Issue with Override createFromCart of OrderService. #4151

NitishGameChanges opened this issue May 22, 2023 · 3 comments

Comments

@NitishGameChanges
Copy link

Bug report

Describe the bug

The issue with Override createFromCart of OrderService.

Code - `async createFromCart(cartOrId: string | Cart): Promise<Order | never> {
return await this.atomicPhase_(async (manager) => {
let order = await super.withTransaction(manager).createFromCart(cartOrId);

        const store_id = getCurrentStoreId(this.container);
        const orderRepo = manager.withRepository(this.container.orderRepository)
         const cartRepo = manager.withRepository(this.container.cartRepository)
        if (!order.store_id && store_id) {
            let data = {
                store_id: store_id,
                source: 'customer',
                store_view_code: this.container.storeViewCode
            };
            Logger.info("BEFORE")
            try {
                if (this.container?.loggedInUser) {
                    data.source = "merchant";
                }
            } catch (e) {
                Logger.error("error ", e)
            }
            Logger.info("AFTER")
            await orderRepo.update({id: order.id}, data)
            await cartRepo.update({id: typeof(cartOrId) == 'string'? cartOrId: cartOrId.id}, {is_active: false})
            Logger.info("done")
        }
        Logger.info("createFromCart order final ", order)
        return order;
    })
}`

A clear and concise description of what the bug is.
Bug / error :
<html>TS2345: Argument of type 'Repository&lt;Order&gt; &amp; { target: EntityTarget&lt;Order&gt; &amp; typeof Order; manager: EntityManager; queryRunner?: QueryRunner; findWithRelations(relations?: FindOptionsRelations&lt;...&gt;, optionsWithoutRelations?: Omit&lt;...&gt;): Promise&lt;...&gt;; findOneWithRelations(relations?: FindOptionsRelations&lt;...&gt;, optionsWithoutRelations?: Omit&lt;...' is not assignable to parameter of type 'Repository&lt;any&gt; &amp; Repository&lt;ObjectLiteral&gt;'.<br/>Type 'Repository&lt;Order&gt; &amp; { target: EntityTarget&lt;Order&gt; &amp; typeof Order; manager: EntityManager; queryRunner?: QueryRunner; findWithRelations(relations?: FindOptionsRelations&lt;...&gt;, optionsWithoutRelations?: Omit&lt;...&gt;): Promise&lt;...&gt;; findOneWithRelations(relations?: FindOptionsRelations&lt;...&gt;, optionsWithoutRelations?: Omit&lt;...' is missing the following properties from type 'Repository&lt;any&gt;': sum, average, minimum, maximum

System information

Medusa version (including plugins):
Node.js version: v16.19.0
Database: Postgres
Operating system: MacOS
Browser (if relevant):

Steps to reproduce the behavior

  1. Cart Complete API call

Expected behavior

I want line const orderRepo = manager.withRepository(this.container.orderRepository) to work.

Screenshots

Screenshot 2023-05-22 at 7 38 27 PM

If applicable, add screenshots to help explain your problem

Code snippets

If applicable, add code samples to help explain your problem

Additional context

Add any other context about the problem here

@PlasticLizard
Copy link

PlasticLizard commented May 24, 2023

I'm also somewhat desperately trying to do exactly the same thing - attach a store ID to an order during the cart completion process. With this code I get a stack overflow:

` async createFromCart(cartOrId: string | Cart): Promise<Order | never> {
return await this.atomicPhase_(async (manager) => {
let order = await super.withTransaction(manager).createFromCart(cartOrId);

  const store_id = this.currentStore_?.id;
  const orderRepo = manager.withRepository(this.orderRepository_);
  if (!order.store_id && store_id) {
    let data = {
      store_id: store_id,
    };
    await orderRepo.update({ id: order.id }, data);
  }
  return order;
});

}
}`

@PlasticLizard
Copy link

PlasticLizard commented May 24, 2023

Hey @NitishGameChanges - I just saw this in the "marketplace" article on the MedusaJS blog under 'Next Steps':

Associate an order to a store: This requires listening to the
order.created
event in a subscriber. The implementation can include creating child orders of an order if in your use case you support have products from multiple stores in one product. In this case, you’d also need to extend the order entity to create a parent-child relation. You can learn more about subscribers in the documentation.

I think the supported approach for that kind of multi-tenancy with orders is going to be the subscriber. Trying that next.

Copy link
Contributor

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.

@github-actions github-actions bot added the Stale label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants