@empty-complete-org/medusa-product-attributes 0.12.2 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -235,6 +235,7 @@ const ProductAttributeValuesWidget = ({
|
|
|
235
235
|
}) => {
|
|
236
236
|
var _a, _b, _c;
|
|
237
237
|
const productId = data.id;
|
|
238
|
+
const productHandle = data.handle || productId;
|
|
238
239
|
const categoryId = ((_b = (_a = data.categories) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) ?? null;
|
|
239
240
|
const qc = reactQuery.useQueryClient();
|
|
240
241
|
const [formValues, setFormValues] = react.useState({});
|
|
@@ -285,12 +286,20 @@ const ProductAttributeValuesWidget = ({
|
|
|
285
286
|
const attributesToUpdate = attributes2.filter((attr) => formValues[attr.id] !== void 0).map((attr) => ({ id: attr.id, value: formValues[attr.id] ?? "" }));
|
|
286
287
|
saveMutation.mutate({ attributes: attributesToUpdate });
|
|
287
288
|
};
|
|
288
|
-
const handleFileUpload = async (
|
|
289
|
+
const handleFileUpload = async (attr, file) => {
|
|
289
290
|
var _a2, _b2;
|
|
291
|
+
const attrId = attr.id;
|
|
290
292
|
setUploadingId(attrId);
|
|
291
293
|
try {
|
|
294
|
+
const dot = file.name.lastIndexOf(".");
|
|
295
|
+
const ext = dot > -1 ? file.name.slice(dot) : "";
|
|
296
|
+
const renamed = new File(
|
|
297
|
+
[file],
|
|
298
|
+
`${productHandle}_${attr.key}${ext}`,
|
|
299
|
+
{ type: file.type }
|
|
300
|
+
);
|
|
292
301
|
const formData = new FormData();
|
|
293
|
-
formData.append("files",
|
|
302
|
+
formData.append("files", renamed);
|
|
294
303
|
const response = await fetch(`/admin/uploads`, {
|
|
295
304
|
method: "POST",
|
|
296
305
|
credentials: "include",
|
|
@@ -368,7 +377,7 @@ const ProductAttributeValuesWidget = ({
|
|
|
368
377
|
onChange: (e) => {
|
|
369
378
|
var _a2;
|
|
370
379
|
const f = (_a2 = e.target.files) == null ? void 0 : _a2[0];
|
|
371
|
-
if (f) handleFileUpload(attr
|
|
380
|
+
if (f) handleFileUpload(attr, f);
|
|
372
381
|
}
|
|
373
382
|
}
|
|
374
383
|
),
|
|
@@ -232,6 +232,7 @@ const ProductAttributeValuesWidget = ({
|
|
|
232
232
|
}) => {
|
|
233
233
|
var _a, _b, _c;
|
|
234
234
|
const productId = data.id;
|
|
235
|
+
const productHandle = data.handle || productId;
|
|
235
236
|
const categoryId = ((_b = (_a = data.categories) == null ? void 0 : _a[0]) == null ? void 0 : _b.id) ?? null;
|
|
236
237
|
const qc = useQueryClient();
|
|
237
238
|
const [formValues, setFormValues] = useState({});
|
|
@@ -282,12 +283,20 @@ const ProductAttributeValuesWidget = ({
|
|
|
282
283
|
const attributesToUpdate = attributes2.filter((attr) => formValues[attr.id] !== void 0).map((attr) => ({ id: attr.id, value: formValues[attr.id] ?? "" }));
|
|
283
284
|
saveMutation.mutate({ attributes: attributesToUpdate });
|
|
284
285
|
};
|
|
285
|
-
const handleFileUpload = async (
|
|
286
|
+
const handleFileUpload = async (attr, file) => {
|
|
286
287
|
var _a2, _b2;
|
|
288
|
+
const attrId = attr.id;
|
|
287
289
|
setUploadingId(attrId);
|
|
288
290
|
try {
|
|
291
|
+
const dot = file.name.lastIndexOf(".");
|
|
292
|
+
const ext = dot > -1 ? file.name.slice(dot) : "";
|
|
293
|
+
const renamed = new File(
|
|
294
|
+
[file],
|
|
295
|
+
`${productHandle}_${attr.key}${ext}`,
|
|
296
|
+
{ type: file.type }
|
|
297
|
+
);
|
|
289
298
|
const formData = new FormData();
|
|
290
|
-
formData.append("files",
|
|
299
|
+
formData.append("files", renamed);
|
|
291
300
|
const response = await fetch(`/admin/uploads`, {
|
|
292
301
|
method: "POST",
|
|
293
302
|
credentials: "include",
|
|
@@ -365,7 +374,7 @@ const ProductAttributeValuesWidget = ({
|
|
|
365
374
|
onChange: (e) => {
|
|
366
375
|
var _a2;
|
|
367
376
|
const f = (_a2 = e.target.files) == null ? void 0 : _a2[0];
|
|
368
|
-
if (f) handleFileUpload(attr
|
|
377
|
+
if (f) handleFileUpload(attr, f);
|
|
369
378
|
}
|
|
370
379
|
}
|
|
371
380
|
),
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const utils_1 = require("@medusajs/framework/utils");
|
|
7
|
+
const transliteration_1 = require("transliteration");
|
|
7
8
|
const category_custom_attribute_1 = __importDefault(require("./models/category-custom-attribute"));
|
|
8
9
|
const product_custom_attribute_1 = __importDefault(require("./models/product-custom-attribute"));
|
|
9
10
|
const models = {
|
|
@@ -74,10 +75,7 @@ class CustomAttributeService extends (0, utils_1.MedusaService)(models) {
|
|
|
74
75
|
});
|
|
75
76
|
}
|
|
76
77
|
generateKey(label) {
|
|
77
|
-
return label
|
|
78
|
-
.toLowerCase()
|
|
79
|
-
.replace(/[^a-z0-9]+/g, "_")
|
|
80
|
-
.replace(/^_|_$/g, "");
|
|
78
|
+
return (0, transliteration_1.slugify)(label, { separator: "_", lowercase: true }) || "attr";
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
exports.default = CustomAttributeService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../src/modules/product-attributes/service.ts"],"names":[],"mappings":";;;;;AAAA,qDAAyD;AACzD,mGAAwE;AACxE,iGAAsE;AAEtE,MAAM,MAAM,GAAG;IACb,uBAAuB,EAAvB,mCAAuB;IACvB,sBAAsB,EAAtB,kCAAsB;CACvB,CAAA;AAID,2EAA2E;AAC3E,MAAM,sBAAuB,SAAQ,IAAA,qBAAa,EAAC,MAAM,CAAC;IACxD,KAAK,CAAC,qBAAqB,CAAC,UAAkB;QAC5C,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,4BAA4B,CAAC;YAC7C,WAAW,EAAE,UAAU;YACvB,U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C/C,CAAC;QACD,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,8BAA8B,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,IAM5B;QACC,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,sBAAsB,CAC1B,EAAU,EACV,IAKC;QAED,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,6BAA6B,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAC1C,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,2BAA2B,CAAC;YAC5C,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,IAAI;SACjB,EAAE;YACD,SAAS,EAAE,CAAC,2BAA2B,CAAC;SACzC,CAAC,CAAA;IACJ,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,OAAO,KAAK
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../../src/modules/product-attributes/service.ts"],"names":[],"mappings":";;;;;AAAA,qDAAyD;AACzD,qDAAyC;AACzC,mGAAwE;AACxE,iGAAsE;AAEtE,MAAM,MAAM,GAAG;IACb,uBAAuB,EAAvB,mCAAuB;IACvB,sBAAsB,EAAtB,kCAAsB;CACvB,CAAA;AAID,2EAA2E;AAC3E,MAAM,sBAAuB,SAAQ,IAAA,qBAAa,EAAC,MAAM,CAAC;IACxD,KAAK,CAAC,qBAAqB,CAAC,UAAkB;QAC5C,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,4BAA4B,CAAC;YAC7C,WAAW,EAAE,UAAU;YACvB,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,0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AC,CAAC,EAAE,EAAE,EAAE,GAAG,UAAU,EAAE,CAAC,CAAC,CAAA;IAC3E,CAAC;IAED,KAAK,CAAC,sBAAsB,CAAC,IAM5B;QACC,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,6BAA6B,CAAC,IAAI,CAAC,CAAA;IACvD,CAAC;IAED,KAAK,CAAC,sBAAsB,CAC1B,EAAU,EACV,IAKC;QAED,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,6BAA6B,CAAC,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC,CAAA;IACpE,CAAC;IAED,KAAK,CAAC,oBAAoB,CAAC,SAAiB;QAC1C,iDAAiD;QACjD,OAAO,MAAM,IAAI,CAAC,2BAA2B,CAAC;YAC5C,UAAU,EAAE,SAAS;YACrB,UAAU,EAAE,IAAI;SACjB,EAAE;YACD,SAAS,EAAE,CAAC,2BAA2B,CAAC;SACzC,CAAC,CAAA;IACJ,CAAC;IAEO,WAAW,CAAC,KAAa;QAC/B,OAAO,IAAA,yBAAO,EAAC,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,IAAI,MAAM,CAAA;IACtE,CAAC;CACF;AAED,kBAAe,sBAAsB,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empty-complete-org/medusa-product-attributes",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "Custom attributes module for Medusa v2 with support for text, number, file types and units of measurement",
|
|
5
5
|
"author": "empty-complete",
|
|
6
6
|
"license": "MIT",
|
|
@@ -82,5 +82,8 @@
|
|
|
82
82
|
},
|
|
83
83
|
"publishConfig": {
|
|
84
84
|
"registry": "https://registry.npmjs.org"
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"transliteration": "^2.6.1"
|
|
85
88
|
}
|
|
86
89
|
}
|