@empty-complete-org/medusa-product-attributes 0.11.0 → 0.11.1
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.
- package/.medusa/server/src/admin/index.js +68 -47
- package/.medusa/server/src/admin/index.mjs +68 -47
- package/.medusa/server/src/api/admin/category/[categoryId]/custom-attributes/route.js +24 -1
- package/.medusa/server/src/api/admin/category/[categoryId]/custom-attributes/route.js.map +1 -1
- package/.medusa/server/src/modules/product-attributes/service.d.ts +1 -0
- package/.medusa/server/src/modules/product-attributes/service.js +18 -0
- package/.medusa/server/src/modules/product-attributes/service.js.map +1 -1
- package/package.json +1 -1
|
@@ -34,6 +34,8 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
34
34
|
queryFn: () => sdk.client.fetch(`/admin/category/${categoryId}/custom-attributes`)
|
|
35
35
|
});
|
|
36
36
|
const attributes = (result == null ? void 0 : result.category_custom_attributes) ?? [];
|
|
37
|
+
const ownAttributes = attributes.filter((a) => !a.inherited);
|
|
38
|
+
const inheritedAttributes = attributes.filter((a) => a.inherited);
|
|
37
39
|
const createMutation = reactQuery.useMutation({
|
|
38
40
|
mutationFn: (body) => sdk.client.fetch(`/admin/category/${categoryId}/custom-attributes`, {
|
|
39
41
|
method: "POST",
|
|
@@ -66,6 +68,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
66
68
|
type: addForm.type
|
|
67
69
|
});
|
|
68
70
|
};
|
|
71
|
+
const typeLabel = (t) => t === "text" ? "Текст" : t === "number" ? "Число" : t;
|
|
69
72
|
return /* @__PURE__ */ jsxRuntime.jsxs(ui.Container, { className: "divide-y p-0", children: [
|
|
70
73
|
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
71
74
|
/* @__PURE__ */ jsxRuntime.jsx(ui.Heading, { level: "h2", children: "Атрибуты" }),
|
|
@@ -81,60 +84,78 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
81
84
|
] }),
|
|
82
85
|
isLoading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: "Загрузка…" }) }),
|
|
83
86
|
isError && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-error text-sm", children: "Не удалось загрузить атрибуты." }) }),
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
(
|
|
87
|
-
"div",
|
|
88
|
-
{
|
|
89
|
-
className: "flex items-center gap-3 px-6 py-3 text-sm",
|
|
90
|
-
children: [
|
|
91
|
-
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex-1 text-ui-fg-base", children: [
|
|
92
|
-
"Удалить «",
|
|
93
|
-
attr.label,
|
|
94
|
-
"»?"
|
|
95
|
-
] }),
|
|
96
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
97
|
-
ui.Button,
|
|
98
|
-
{
|
|
99
|
-
size: "small",
|
|
100
|
-
variant: "danger",
|
|
101
|
-
onClick: () => deleteMutation.mutate(attr.id),
|
|
102
|
-
isLoading: deleteMutation.isPending,
|
|
103
|
-
children: "Удалить"
|
|
104
|
-
}
|
|
105
|
-
),
|
|
106
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
107
|
-
ui.Button,
|
|
108
|
-
{
|
|
109
|
-
size: "small",
|
|
110
|
-
variant: "secondary",
|
|
111
|
-
onClick: () => setConfirmDeleteId(null),
|
|
112
|
-
children: "Отмена"
|
|
113
|
-
}
|
|
114
|
-
)
|
|
115
|
-
]
|
|
116
|
-
},
|
|
117
|
-
attr.id
|
|
118
|
-
) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
87
|
+
inheritedAttributes.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
88
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-2 bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", weight: "plus", className: "text-ui-fg-muted uppercase", children: "Унаследованные" }) }),
|
|
89
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children: inheritedAttributes.map((attr) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
119
90
|
"div",
|
|
120
91
|
{
|
|
121
92
|
className: "flex items-center gap-3 px-6 py-3",
|
|
122
93
|
children: [
|
|
123
|
-
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-ui-fg-
|
|
124
|
-
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: attr.type
|
|
125
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
126
|
-
"button",
|
|
127
|
-
{
|
|
128
|
-
onClick: () => setConfirmDeleteId(attr.id),
|
|
129
|
-
className: "text-xs text-ui-fg-error hover:underline",
|
|
130
|
-
children: "Удалить"
|
|
131
|
-
}
|
|
132
|
-
)
|
|
94
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-ui-fg-subtle", children: attr.label }),
|
|
95
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: typeLabel(attr.type) }),
|
|
96
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "blue", children: "из родителя" })
|
|
133
97
|
]
|
|
134
98
|
},
|
|
135
99
|
attr.id
|
|
136
|
-
)
|
|
137
|
-
|
|
100
|
+
)) })
|
|
101
|
+
] }),
|
|
102
|
+
ownAttributes.length > 0 && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
103
|
+
inheritedAttributes.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-2 bg-ui-bg-subtle", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { size: "xsmall", weight: "plus", className: "text-ui-fg-muted uppercase", children: "Свои" }) }),
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "divide-y", children: ownAttributes.map(
|
|
105
|
+
(attr) => confirmDeleteId === attr.id ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
className: "flex items-center gap-3 px-6 py-3 text-sm",
|
|
109
|
+
children: [
|
|
110
|
+
/* @__PURE__ */ jsxRuntime.jsxs("span", { className: "flex-1 text-ui-fg-base", children: [
|
|
111
|
+
"Удалить «",
|
|
112
|
+
attr.label,
|
|
113
|
+
"»?"
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
116
|
+
ui.Button,
|
|
117
|
+
{
|
|
118
|
+
size: "small",
|
|
119
|
+
variant: "danger",
|
|
120
|
+
onClick: () => deleteMutation.mutate(attr.id),
|
|
121
|
+
isLoading: deleteMutation.isPending,
|
|
122
|
+
children: "Удалить"
|
|
123
|
+
}
|
|
124
|
+
),
|
|
125
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
126
|
+
ui.Button,
|
|
127
|
+
{
|
|
128
|
+
size: "small",
|
|
129
|
+
variant: "secondary",
|
|
130
|
+
onClick: () => setConfirmDeleteId(null),
|
|
131
|
+
children: "Отмена"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
]
|
|
135
|
+
},
|
|
136
|
+
attr.id
|
|
137
|
+
) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
138
|
+
"div",
|
|
139
|
+
{
|
|
140
|
+
className: "flex items-center gap-3 px-6 py-3",
|
|
141
|
+
children: [
|
|
142
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-1 text-sm text-ui-fg-base", children: attr.label }),
|
|
143
|
+
/* @__PURE__ */ jsxRuntime.jsx(ui.Badge, { size: "2xsmall", color: "grey", children: typeLabel(attr.type) }),
|
|
144
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
145
|
+
"button",
|
|
146
|
+
{
|
|
147
|
+
onClick: () => setConfirmDeleteId(attr.id),
|
|
148
|
+
className: "text-xs text-ui-fg-error hover:underline",
|
|
149
|
+
children: "Удалить"
|
|
150
|
+
}
|
|
151
|
+
)
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
attr.id
|
|
155
|
+
)
|
|
156
|
+
) })
|
|
157
|
+
] }),
|
|
158
|
+
!isLoading && !isError && attributes.length === 0 && !showAddForm && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsxRuntime.jsx(ui.Text, { className: "text-ui-fg-muted text-sm", children: "Нет атрибутов. Добавьте первый." }) }),
|
|
138
159
|
showAddForm && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 px-6 py-3", children: [
|
|
139
160
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
140
161
|
ui.Input,
|
|
@@ -31,6 +31,8 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
31
31
|
queryFn: () => sdk.client.fetch(`/admin/category/${categoryId}/custom-attributes`)
|
|
32
32
|
});
|
|
33
33
|
const attributes = (result == null ? void 0 : result.category_custom_attributes) ?? [];
|
|
34
|
+
const ownAttributes = attributes.filter((a) => !a.inherited);
|
|
35
|
+
const inheritedAttributes = attributes.filter((a) => a.inherited);
|
|
34
36
|
const createMutation = useMutation({
|
|
35
37
|
mutationFn: (body) => sdk.client.fetch(`/admin/category/${categoryId}/custom-attributes`, {
|
|
36
38
|
method: "POST",
|
|
@@ -63,6 +65,7 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
63
65
|
type: addForm.type
|
|
64
66
|
});
|
|
65
67
|
};
|
|
68
|
+
const typeLabel = (t) => t === "text" ? "Текст" : t === "number" ? "Число" : t;
|
|
66
69
|
return /* @__PURE__ */ jsxs(Container, { className: "divide-y p-0", children: [
|
|
67
70
|
/* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between px-6 py-4", children: [
|
|
68
71
|
/* @__PURE__ */ jsx(Heading, { level: "h2", children: "Атрибуты" }),
|
|
@@ -78,60 +81,78 @@ const CategoryAttributeTemplatesWidget = ({
|
|
|
78
81
|
] }),
|
|
79
82
|
isLoading && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Загрузка…" }) }),
|
|
80
83
|
isError && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-error text-sm", children: "Не удалось загрузить атрибуты." }) }),
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
(
|
|
84
|
-
"div",
|
|
85
|
-
{
|
|
86
|
-
className: "flex items-center gap-3 px-6 py-3 text-sm",
|
|
87
|
-
children: [
|
|
88
|
-
/* @__PURE__ */ jsxs("span", { className: "flex-1 text-ui-fg-base", children: [
|
|
89
|
-
"Удалить «",
|
|
90
|
-
attr.label,
|
|
91
|
-
"»?"
|
|
92
|
-
] }),
|
|
93
|
-
/* @__PURE__ */ jsx(
|
|
94
|
-
Button,
|
|
95
|
-
{
|
|
96
|
-
size: "small",
|
|
97
|
-
variant: "danger",
|
|
98
|
-
onClick: () => deleteMutation.mutate(attr.id),
|
|
99
|
-
isLoading: deleteMutation.isPending,
|
|
100
|
-
children: "Удалить"
|
|
101
|
-
}
|
|
102
|
-
),
|
|
103
|
-
/* @__PURE__ */ jsx(
|
|
104
|
-
Button,
|
|
105
|
-
{
|
|
106
|
-
size: "small",
|
|
107
|
-
variant: "secondary",
|
|
108
|
-
onClick: () => setConfirmDeleteId(null),
|
|
109
|
-
children: "Отмена"
|
|
110
|
-
}
|
|
111
|
-
)
|
|
112
|
-
]
|
|
113
|
-
},
|
|
114
|
-
attr.id
|
|
115
|
-
) : /* @__PURE__ */ jsxs(
|
|
84
|
+
inheritedAttributes.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
85
|
+
/* @__PURE__ */ jsx("div", { className: "px-6 py-2 bg-ui-bg-subtle", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", weight: "plus", className: "text-ui-fg-muted uppercase", children: "Унаследованные" }) }),
|
|
86
|
+
/* @__PURE__ */ jsx("div", { className: "divide-y", children: inheritedAttributes.map((attr) => /* @__PURE__ */ jsxs(
|
|
116
87
|
"div",
|
|
117
88
|
{
|
|
118
89
|
className: "flex items-center gap-3 px-6 py-3",
|
|
119
90
|
children: [
|
|
120
|
-
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-ui-fg-
|
|
121
|
-
/* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "grey", children: attr.type
|
|
122
|
-
/* @__PURE__ */ jsx(
|
|
123
|
-
"button",
|
|
124
|
-
{
|
|
125
|
-
onClick: () => setConfirmDeleteId(attr.id),
|
|
126
|
-
className: "text-xs text-ui-fg-error hover:underline",
|
|
127
|
-
children: "Удалить"
|
|
128
|
-
}
|
|
129
|
-
)
|
|
91
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-ui-fg-subtle", children: attr.label }),
|
|
92
|
+
/* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "grey", children: typeLabel(attr.type) }),
|
|
93
|
+
/* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "blue", children: "из родителя" })
|
|
130
94
|
]
|
|
131
95
|
},
|
|
132
96
|
attr.id
|
|
133
|
-
)
|
|
134
|
-
|
|
97
|
+
)) })
|
|
98
|
+
] }),
|
|
99
|
+
ownAttributes.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
100
|
+
inheritedAttributes.length > 0 && /* @__PURE__ */ jsx("div", { className: "px-6 py-2 bg-ui-bg-subtle", children: /* @__PURE__ */ jsx(Text, { size: "xsmall", weight: "plus", className: "text-ui-fg-muted uppercase", children: "Свои" }) }),
|
|
101
|
+
/* @__PURE__ */ jsx("div", { className: "divide-y", children: ownAttributes.map(
|
|
102
|
+
(attr) => confirmDeleteId === attr.id ? /* @__PURE__ */ jsxs(
|
|
103
|
+
"div",
|
|
104
|
+
{
|
|
105
|
+
className: "flex items-center gap-3 px-6 py-3 text-sm",
|
|
106
|
+
children: [
|
|
107
|
+
/* @__PURE__ */ jsxs("span", { className: "flex-1 text-ui-fg-base", children: [
|
|
108
|
+
"Удалить «",
|
|
109
|
+
attr.label,
|
|
110
|
+
"»?"
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsx(
|
|
113
|
+
Button,
|
|
114
|
+
{
|
|
115
|
+
size: "small",
|
|
116
|
+
variant: "danger",
|
|
117
|
+
onClick: () => deleteMutation.mutate(attr.id),
|
|
118
|
+
isLoading: deleteMutation.isPending,
|
|
119
|
+
children: "Удалить"
|
|
120
|
+
}
|
|
121
|
+
),
|
|
122
|
+
/* @__PURE__ */ jsx(
|
|
123
|
+
Button,
|
|
124
|
+
{
|
|
125
|
+
size: "small",
|
|
126
|
+
variant: "secondary",
|
|
127
|
+
onClick: () => setConfirmDeleteId(null),
|
|
128
|
+
children: "Отмена"
|
|
129
|
+
}
|
|
130
|
+
)
|
|
131
|
+
]
|
|
132
|
+
},
|
|
133
|
+
attr.id
|
|
134
|
+
) : /* @__PURE__ */ jsxs(
|
|
135
|
+
"div",
|
|
136
|
+
{
|
|
137
|
+
className: "flex items-center gap-3 px-6 py-3",
|
|
138
|
+
children: [
|
|
139
|
+
/* @__PURE__ */ jsx("span", { className: "flex-1 text-sm text-ui-fg-base", children: attr.label }),
|
|
140
|
+
/* @__PURE__ */ jsx(Badge, { size: "2xsmall", color: "grey", children: typeLabel(attr.type) }),
|
|
141
|
+
/* @__PURE__ */ jsx(
|
|
142
|
+
"button",
|
|
143
|
+
{
|
|
144
|
+
onClick: () => setConfirmDeleteId(attr.id),
|
|
145
|
+
className: "text-xs text-ui-fg-error hover:underline",
|
|
146
|
+
children: "Удалить"
|
|
147
|
+
}
|
|
148
|
+
)
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
attr.id
|
|
152
|
+
)
|
|
153
|
+
) })
|
|
154
|
+
] }),
|
|
155
|
+
!isLoading && !isError && attributes.length === 0 && !showAddForm && /* @__PURE__ */ jsx("div", { className: "px-6 py-4", children: /* @__PURE__ */ jsx(Text, { className: "text-ui-fg-muted text-sm", children: "Нет атрибутов. Добавьте первый." }) }),
|
|
135
156
|
showAddForm && /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2 px-6 py-3", children: [
|
|
136
157
|
/* @__PURE__ */ jsx(
|
|
137
158
|
Input,
|
|
@@ -3,11 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.GET = GET;
|
|
4
4
|
exports.POST = POST;
|
|
5
5
|
exports.PATCH = PATCH;
|
|
6
|
+
const utils_1 = require("@medusajs/framework/utils");
|
|
6
7
|
const product_attributes_1 = require("../../../../../modules/product-attributes");
|
|
8
|
+
/**
|
|
9
|
+
* Walk up the category tree, starting from `leafId`, collecting ids of the
|
|
10
|
+
* category itself and all of its ancestors. Ordered leaf → root.
|
|
11
|
+
*
|
|
12
|
+
* A hard cap of 20 levels guards against cycles in malformed data.
|
|
13
|
+
*/
|
|
14
|
+
async function resolveAncestorChain(productService, leafId) {
|
|
15
|
+
const chain = [];
|
|
16
|
+
let currentId = leafId;
|
|
17
|
+
let depth = 0;
|
|
18
|
+
while (currentId && depth < 20) {
|
|
19
|
+
chain.push(currentId);
|
|
20
|
+
const category = await productService.retrieveProductCategory(currentId, {
|
|
21
|
+
select: ["id", "parent_category_id"],
|
|
22
|
+
});
|
|
23
|
+
currentId = category?.parent_category_id ?? null;
|
|
24
|
+
depth++;
|
|
25
|
+
}
|
|
26
|
+
return chain;
|
|
27
|
+
}
|
|
7
28
|
async function GET(req, res) {
|
|
8
29
|
const { categoryId } = req.params;
|
|
9
30
|
const service = req.scope.resolve(product_attributes_1.CUSTOM_ATTRIBUTE_MODULE);
|
|
10
|
-
const
|
|
31
|
+
const productService = req.scope.resolve(utils_1.Modules.PRODUCT);
|
|
32
|
+
const categoryIds = await resolveAncestorChain(productService, categoryId);
|
|
33
|
+
const category_custom_attributes = await service.getAttributesByCategoryIds(categoryIds);
|
|
11
34
|
res.json({ category_custom_attributes });
|
|
12
35
|
}
|
|
13
36
|
async function POST(req, res) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../../src/api/admin/category/[categoryId]/custom-attributes/route.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"route.js","sourceRoot":"","sources":["../../../../../../../../src/api/admin/category/[categoryId]/custom-attributes/route.ts"],"names":[],"mappings":";;AA6BA,kBASC;AAED,oBAoBC;AAED,sBAcC;AA3ED,qDAAmD;AACnD,kFAAmF;AAGnF;;;;;GAKG;AACH,KAAK,UAAU,oBAAoB,CACjC,cAAmB,EACnB,MAAc;IAEd,MAAM,KAAK,GAAa,EAAE,CAAA;IAC1B,IAAI,SAAS,GAAkB,MAAM,CAAA;IACrC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,OAAO,SAAS,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QAC/B,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACrB,MAAM,QAAQ,GAAQ,MAAM,cAAc,CAAC,uBAAuB,CAAC,SAAS,EAAE;YAC5E,MAAM,EAAE,CAAC,IAAI,EAAE,oBAAoB,CAAC;SACrC,CAAC,CAAA;QACF,SAAS,GAAI,QAAQ,EAAE,kBAAoC,IAAI,IAAI,CAAA;QACnE,KAAK,EAAE,CAAA;IACT,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC;AAEM,KAAK,UAAU,GAAG,CAAC,GAAkB,EAAE,GAAmB;IAC/D,MAAM,EAAE,UAAU,EAAE,GAAG,GAAG,CAAC,MAAM,CAAA;IACjC,MAAM,OAAO,GAA2B,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,4CAAuB,CAAC,CAAA;I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CAAC,EAAE,yBAAyB,EAAE,CAAC,CAAA;AACzC,CAAC"}
|
|
@@ -63,6 +63,7 @@ declare class CustomAttributeService extends CustomAttributeService_base {
|
|
|
63
63
|
updated_at: Date;
|
|
64
64
|
deleted_at: Date | null;
|
|
65
65
|
}[]>;
|
|
66
|
+
getAttributesByCategoryIds(categoryIds: string[]): Promise<any[]>;
|
|
66
67
|
createCategoryAttribute(data: {
|
|
67
68
|
label: string;
|
|
68
69
|
type: string;
|
|
@@ -19,6 +19,24 @@ class CustomAttributeService extends (0, utils_1.MedusaService)(models) {
|
|
|
19
19
|
deleted_at: null,
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
|
+
async getAttributesByCategoryIds(categoryIds) {
|
|
23
|
+
if (!categoryIds || categoryIds.length === 0) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
// @ts-ignore - method generated by MedusaService
|
|
27
|
+
const attributes = await this.listCategoryCustomAttributes({
|
|
28
|
+
category_id: categoryIds,
|
|
29
|
+
deleted_at: null,
|
|
30
|
+
});
|
|
31
|
+
// First id in the list is the leaf category — its attributes are "own",
|
|
32
|
+
// everything else is inherited from an ancestor.
|
|
33
|
+
const leafId = categoryIds[0];
|
|
34
|
+
return attributes.map((attr) => ({
|
|
35
|
+
...attr,
|
|
36
|
+
inherited: attr.category_id !== leafId,
|
|
37
|
+
source_category_id: attr.category_id,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
22
40
|
async createCategoryAttribute(data) {
|
|
23
41
|
const key = this.generateKey(data.label);
|
|
24
42
|
// @ts-ignore - method generated by MedusaService
|
|
@@ -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,CA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B,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;aACT,WAAW,EAAE;aACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;aAC3B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC1B,CAAC;CACF;AAED,kBAAe,sBAAsB,CAAA"}
|
|
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,UAAU,EAAE,IAAI;SACjB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,0BAA0B,CAAC,WAAqB;QACpD,IAAI,CAAC,WAAW,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7C,OAAO,EAAE,CAAA;QACX,CAAC;QACD,iDAAiD;QACjD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,4BAA4B,CAAC;YACzD,WAAW,EAAE,WAAW;YACx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B,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;aACT,WAAW,EAAE;aACb,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC;aAC3B,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAA;IAC1B,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.11.
|
|
3
|
+
"version": "0.11.1",
|
|
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",
|