#To extend an inventory service I have to create a custom inventory module?

12 messages · Page 1 of 1 (latest)

trail finch
#

I just noticed import { InventoryService as MedusaInventoryService } from '@medusajs/inventory/dist/services';

#

seems like the service is not exported

#

in inventory/index.ts

#

nope, this gives container errors

#
- Initializing subscribers
error:   Error starting server
AwilixResolutionError: Could not resolve 'inventoryItemService'.
Resolution path: productVariantInventoryService -> salesChannelInventoryService -> inventoryService -> inventoryItemService
faint palm
#

up

trail finch
#

@faint palm you have to extend all of them, even if. you don't add or override any logic, the core app needs to have all the services above

faint palm
trail finch
#

correct

faint palm
#

thx!

faint palm
# trail finch correct

can you share your example? because I'm trying and it's not overriding anything
I added file services/inventory/index.ts
and inside I'm overriding functionality like:

  InventoryService as MedusaInventoryService,
  InventoryItemService,
  InventoryLevelService,
  ReservationItemService,
} from '@medusajs/inventory/dist/services';
import { InternalModuleDeclaration } from '@medusajs/modules-sdk';

class InventoryService extends MedusaInventoryService {
  constructor(
    dependencies: any,
    options?: unknown,
    moduleDeclaration?: InternalModuleDeclaration | undefined
  ) {
    super(dependencies, options, moduleDeclaration);
    console.log('OVERRIDING CORRECTLY');
  }
}

export {
  InventoryItemService,
  InventoryLevelService,
  ReservationItemService,
  InventoryService,
};
scarlet root
#

you need to create a new module where you re export everything that is exported except your service which will replace the existing one. You might also need to update the loader container from your modukle