andriinuts / medusa-plugin-variant-images

29 stars 21 forks source link

Error when clicking the any of the products in the products section in the Admin App #7

Closed stanley-tarce closed 1 year ago

stanley-tarce commented 1 year ago

Hello! I'm currently having an issue where I couldn't access the product edit page on the admin dashboard due to an error. When I removed the plugin in the config, it worked again. Would there be a fix for this? Thank you!

Also to help, I've also extended the product variant entity with custom relations in the modules folder. I'm not sure if this will disrupt the flow of the plugin.

Screenshot 2023-10-21 at 1 34 28 PM
andriinuts commented 1 year ago

@stanley-tarce what version are you using? update to the latest version (and run migrations) and try it one more time. I guess every plugin works independently so you should not have any conflicts I guess

stanley-tarce commented 1 year ago

I'm using this version "medusa-plugin-variant-images": "^1.0.4" and all the other dependencies are at within or above minimum required. 🤔

Edit: I've reinstalled the plugin and it still the same

andriinuts commented 1 year ago

@stanley-tarce can you share how you extended the entity because it can be a reason?

stanley-tarce commented 1 year ago

I just mainly followed the documentation on Medusa. Here are some snapshots on how I extended the entity and added Type Definitions.

code-snapshot-5 code-snapshot-4

stanley-tarce commented 1 year ago

Hello! I've tried to extend the ProductVariant Record instead from the package and it worked. Although when I tried to link an image to a variant, I got this error:

error:   Cannot query across many-to-many for property images
Error: Cannot query across many-to-many for property images
    at UpdateQueryBuilder.createPropertyPath (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/QueryBuilder.js:945:27)
    at UpdateQueryBuilder.createUpdateExpression (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:303:18)
    at UpdateQueryBuilder.getQuery (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:34:21)
    at UpdateQueryBuilder.getQueryAndParameters (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/QueryBuilder.js:274:28)
    at UpdateQueryBuilder.execute (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:81:50)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
andriinuts commented 1 year ago

It should work independently. What version of Medusa you are using? Because there was an issue with overriding extended entities but it was fixed in the latest versions.

stanley-tarce commented 1 year ago

I'm using the following packages:

"@medusajs/medusa": "1.16.0",
"@medusajs/admin": "7.0.1"
"medusa-react": "^9.0.4",
"@medusajs/ui": "1.0.0",

"typeorm": "^0.3.16",
andriinuts commented 1 year ago

This can be an issue, please try to use at least @medusajs/medus: 1.17.0

stanley-tarce commented 1 year ago

Hi @andriinuts, tried to use that version and the issue still persists 🤔

andriinuts commented 1 year ago

@stanley-tarce ok, I'll try to investigate it in this week

andriinuts commented 1 year ago

@stanley-tarce I just checked locally and I have extended the product except for this plugin and everything works as expected, I can't say what could be wrong because I don't see your code. Also, I see that you are using admin 7.0.1, try to use 7.1.2

stanley-tarce commented 1 year ago

Hi @andriinuts,

I managed to make it work by the following:

  1. Import the Product Variant Entity in the package's dist/models folder
  2. Deleting dist folder
  3. Running yarn dev or medusa develop

With this approach, I was able to access the product and link variants to it's images. However, when I tried to do a build yarn build then run the service again, I get an error such as this:

error:   Cannot query across many-to-many for property images
Error: Cannot query across many-to-many for property images
    at UpdateQueryBuilder.createPropertyPath (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/QueryBuilder.js:945:27)
    at UpdateQueryBuilder.createUpdateExpression (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:303:18)
    at UpdateQueryBuilder.getQuery (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:34:21)
    at UpdateQueryBuilder.getQueryAndParameters (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/QueryBuilder.js:274:28)
    at UpdateQueryBuilder.execute (/Users/stanleytarce/pttbisg/medusa-tribedrops-backend/node_modules/typeorm/query-builder/UpdateQueryBuilder.js:81:50)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
![code-snapshot](https://github.com/andriinuts/medusa-plugin-variant-images/assets/79818058/08095568-a6a6-4434-9a85-157944fc4d51)

Should the plugin work as normal when building it? I fear that it might not work when running this on production instances. Also do let me know if need for further clarification

code-snapshot

andriinuts commented 1 year ago

@stanley-tarce I got your idea, but still I guess medusa handling this case to merge multiple extensions of the same model. Maybe try to create a help thread in the medusa discord server or ticket in the medusa repository to clarify why that happens

stanley-tarce commented 1 year ago

Hi @andriinuts, thank you so much for the help!

I've also managed to fix my issue with the error specified above when updating the variant with images. I've also imported the service file from your package to my extended ProductVariant service then it solved the issue. I think I also forgot to tell you that I've also extended the product variant service and added new methods

Now that my issue has been resolved, I do agree they should work independently. I'll address this one on Medusa's end.

code-snapshot-2