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

[Bug]: Missing Hooks for createProductCategoriesWorkflow and createInventoryItemsWorkflow #10230

Closed
okechukwu0127 opened this issue Nov 22, 2024 · 4 comments · May be fixed by #10383
Closed

Comments

@okechukwu0127
Copy link

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v2.0.4

Database and its version

PostgreSQL 13.5 (Debian 13.5-1.pgdg110+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Operating system name and version

MacBook Pro , Sonoma 14.5

Browser name

Chrome

What happended?

I am having trouble accessing hooks when inventoryItem and productCategory are created.

WHAT I WAS ABLE TO DO
I was able to access the following hooks

  1. createProductsWorkflow.hooks.productsCreated
  2. createOrdersWorkflow.hooks.orderCreated
image image

Medusa 2.0.4 seems not to have hooks that handles `createProductCatgeory` and `createInventoryItem` yet, so it became difficult for me to detect when a productCategory and InventoryItem is been created.

WHAT I WAS EXPECTING
I want to be able to access create hooks for

  1. createProductCategoriesWorkflow.hooks
  2. createInventoryItemsWorkflow.hooks

image image

Kindly let me know if I miss anything here or how I can access these hooks

Expected behavior

  1. createProductCategoriesWorkflow.hooks.createProductCatgeory should be available
  2. createInventoryItemsWorkflow.hooks.createInventoryItem should be available

Actual behavior

createProductCatgeory hook is missing from createProductCategoriesWorkflow
createInventoryItem hook is missing from createInventoryItemsWorkflow

Link to reproduction repo

https://github.com/okechukwu0127/medusa-2.0.4

@sradevski
Copy link
Member

@okechukwu0127 thanks for the detailed ticket description!

We are adding hooks as we go, but we are always open for PRs contributing such changes, it will definitely ensure this gets merged and released sooner.

@okechukwu0127
Copy link
Author

@okechukwu0127 thanks for the detailed ticket description!

We are adding hooks as we go, but we are always open for PRs contributing such changes, it will definitely ensure this gets merged and released sooner.

Hi @sradevski

I would love to contribute but I am not familier with Medusa architecture.

  • What file to effect changes on
  • What changes to add

I would be flad to take a fork and effeect changes on my end.

I wait your feedback on my direction.

Kind regards

@sradevski
Copy link
Member

@okechukwu0127 here's an example PR for adding a hook, you can also find other places that use createHook in the codebase: #8878

@sradevski
Copy link
Member

I'll close the issue for now as we keep Issues for bug reports. Feel free to open a PR and we'll have it reviewed

workylus added a commit to workylus/medusa that referenced this issue Dec 1, 2024
### What
This commit introduces the `productCategoriesCreated` hook to the `createProductCategoriesWorkflow`.
It also fixes inconsistent variable names within the workflow.

### Why
The hook was missing and necessary to improve the workflow's extensibility.
- Variable names like `createdProducts` were misleading and did not match the context. They were updated to `createdProductCategories` for clarity.

### How
Added the `productCategoriesCreated` hook and updated related logic within the workflow.
- Renamed variables from `createdProducts` to `createdProductCategories` to reflect their actual purpose.

Fixes: medusajs#10230
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants