vholik / medusa-custom-attributes

Plugin that extends MedusaJs with custom attributes API
88 stars 20 forks source link

Products doesnt load due MedusaV2Flag.key undefined #30

Closed kocendavid closed 5 months ago

kocendavid commented 5 months ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch medusa-custom-attributes@1.0.17 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/medusa-custom-attributes/dist/services/product.js b/node_modules/medusa-custom-attributes/dist/services/product.js
index 36bd11d..b6a6854 100644
--- a/node_modules/medusa-custom-attributes/dist/services/product.js
+++ b/node_modules/medusa-custom-attributes/dist/services/product.js
@@ -80,7 +80,7 @@ class ProductService extends medusa_1.ProductService {
         delete selector.attributes;
         delete selector.int_attributes;
         const hasSalesChannelsRelation = (_a = config.relations) === null || _a === void 0 ? void 0 : _a.includes("sales_channels");
-        if (this.featureFlagRouter_.isFeatureEnabled(utils_1.MedusaV2Flag.key) &&
+        if (utils_1?.MedusaV2Flag?.key && this.featureFlagRouter_.isFeatureEnabled(utils_1.MedusaV2Flag.key) &&
             hasSalesChannelsRelation) {
             config.relations = (_b = config.relations) === null || _b === void 0 ? void 0 : _b.filter((r) => r !== "sales_channels");
         }
@@ -93,7 +93,7 @@ class ProductService extends medusa_1.ProductService {
         else {
             [products, count] = await productRepo.findWithRelationsAndCount(relations, query);
         }
-        if (this.featureFlagRouter_.isFeatureEnabled(utils_1.MedusaV2Flag.key) &&
+        if (utils_1?.MedusaV2Flag?.key && this.featureFlagRouter_.isFeatureEnabled(utils_1.MedusaV2Flag.key) &&
             hasSalesChannelsRelation) {
             // @ts-expect-error
             await this.decorateProductsWithSalesChannels(products);

This issue body was partially generated by patch-package.

kocendavid commented 5 months ago

I may have lower medusa version than the library does

kocendavid commented 5 months ago

version mismatch