@empty-complete-org/medusa-product-attributes 1.1.1 → 1.1.3
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/README.md +144 -54
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -4,9 +4,6 @@
|
|
|
4
4
|
<p><i>A flexible attribute system for Medusa v2 — text, number, file, boolean, with units and category inheritance</i></p>
|
|
5
5
|
|
|
6
6
|
<p>
|
|
7
|
-
<a href="https://github.com/empty-complete/medusa-product-attributes/blob/main/LICENSE">
|
|
8
|
-
<img src="https://img.shields.io/npm/l/@empty-complete-org/medusa-product-attributes" alt="License">
|
|
9
|
-
</a>
|
|
10
7
|
<a href="https://www.npmjs.com/package/@empty-complete-org/medusa-product-attributes">
|
|
11
8
|
<img src="https://img.shields.io/npm/v/@empty-complete-org/medusa-product-attributes" alt="npm version">
|
|
12
9
|
</a>
|
|
@@ -16,6 +13,12 @@
|
|
|
16
13
|
<a href="https://github.com/empty-complete/medusa-product-attributes/actions/workflows/ci.yml">
|
|
17
14
|
<img src="https://github.com/empty-complete/medusa-product-attributes/actions/workflows/ci.yml/badge.svg" alt="CI Status">
|
|
18
15
|
</a>
|
|
16
|
+
<a href="https://github.com/empty-complete/medusa-product-attributes/commits/main">
|
|
17
|
+
<img src="https://img.shields.io/github/commit-activity/m/empty-complete/medusa-product-attributes" alt="GitHub commit activity">
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://github.com/empty-complete/medusa-product-attributes/blob/main/LICENSE">
|
|
20
|
+
<img src="https://img.shields.io/npm/l/@empty-complete-org/medusa-product-attributes" alt="License">
|
|
21
|
+
</a>
|
|
19
22
|
</p>
|
|
20
23
|
|
|
21
24
|
<p>
|
|
@@ -24,49 +27,64 @@
|
|
|
24
27
|
<a href="https://nodejs.org/"><img src="https://img.shields.io/badge/Node.js-%3E=20-339933" alt="Node.js"></a>
|
|
25
28
|
</p>
|
|
26
29
|
|
|
30
|
+
<p>
|
|
31
|
+
<a href="https://t.me/kinesis_lab">
|
|
32
|
+
<img src="https://img.shields.io/badge/Telegram-follow-229ED9?logo=telegram" alt="Telegram">
|
|
33
|
+
</a>
|
|
34
|
+
</p>
|
|
27
35
|
</div>
|
|
28
36
|
|
|
29
37
|
---
|
|
30
38
|
|
|
31
39
|
## Features
|
|
32
40
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
| Feature | Description |
|
|
42
|
+
|---------|-------------|
|
|
43
|
+
| **Text Attributes** | Arbitrary text values for products |
|
|
44
|
+
| **Numeric Attributes** | Numbers with units (kg, m, pcs, etc.) |
|
|
45
|
+
| **File Attributes** | File uploads: certificates, 3D models, manuals |
|
|
46
|
+
| **Boolean Attributes** | Yes/No values |
|
|
47
|
+
| **Category Inheritance** | Attributes cascade from parent to child categories |
|
|
48
|
+
| **Global Attributes** | Applied to every product automatically |
|
|
49
|
+
| **Templates** | Reusable blueprints — apply to any category in one click |
|
|
50
|
+
| **Auto Slug** | Labels are transliterated (Russian, Chinese, any script) |
|
|
51
|
+
| **Smart File Naming** | Uploaded images renamed to `{product_handle}_{attr_key}.ext` |
|
|
52
|
+
| **i18n** | English and Russian out of the box, extensible |
|
|
41
53
|
|
|
42
|
-
|
|
54
|
+
---
|
|
43
55
|
|
|
44
|
-
###
|
|
45
|
-

|
|
56
|
+
### Requirements
|
|
46
57
|
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
| Dependency | Version |
|
|
59
|
+
|------------|---------|
|
|
60
|
+
| Medusa | ^2.13 |
|
|
61
|
+
| Node.js | >=20 |
|
|
62
|
+
| TypeScript | ^5.0 |
|
|
49
63
|
|
|
50
|
-
|
|
51
|
-

|
|
64
|
+
---
|
|
52
65
|
|
|
53
|
-
|
|
54
|
-

|
|
66
|
+
## Quick Start
|
|
55
67
|
|
|
56
|
-
|
|
68
|
+
### Installation
|
|
57
69
|
|
|
58
70
|
```bash
|
|
71
|
+
# Via pnpm
|
|
59
72
|
pnpm add @empty-complete-org/medusa-product-attributes
|
|
60
|
-
|
|
73
|
+
|
|
74
|
+
# Via npm
|
|
61
75
|
npm install @empty-complete-org/medusa-product-attributes
|
|
62
|
-
|
|
76
|
+
|
|
77
|
+
# Via yarn
|
|
63
78
|
yarn add @empty-complete-org/medusa-product-attributes
|
|
64
79
|
```
|
|
65
80
|
|
|
66
|
-
Add to
|
|
81
|
+
### 1. Add the plugin to configuration
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
// medusa-config.ts
|
|
85
|
+
import { defineConfig } from '@medusajs/framework/utils'
|
|
67
86
|
|
|
68
|
-
|
|
69
|
-
module.exports = defineConfig({
|
|
87
|
+
export default defineConfig({
|
|
70
88
|
plugins: [
|
|
71
89
|
{
|
|
72
90
|
resolve: "@empty-complete-org/medusa-product-attributes",
|
|
@@ -76,48 +94,84 @@ module.exports = defineConfig({
|
|
|
76
94
|
})
|
|
77
95
|
```
|
|
78
96
|
|
|
79
|
-
Run migrations
|
|
97
|
+
### 2. Run migrations
|
|
80
98
|
|
|
81
99
|
```bash
|
|
82
100
|
npx medusa db:migrate
|
|
83
101
|
```
|
|
84
102
|
|
|
103
|
+
### 3. Done!
|
|
104
|
+
|
|
105
|
+
The plugin automatically creates tables and registers admin widgets.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Screenshots
|
|
110
|
+
|
|
111
|
+
### Category widget with inheritance
|
|
112
|
+

|
|
113
|
+
|
|
114
|
+
### Product attribute values
|
|
115
|
+

|
|
116
|
+
|
|
117
|
+
### Settings — Global Attributes & Templates
|
|
118
|
+

|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
85
122
|
## Usage
|
|
86
123
|
|
|
87
124
|
### Admin
|
|
88
125
|
|
|
89
|
-
1. **Category attributes** — open any category
|
|
90
|
-
2. **Global attributes** — Settings → *
|
|
91
|
-
3. **Templates** — Settings → *
|
|
92
|
-
4. **Product values** — open any product, the "
|
|
126
|
+
1. **Category attributes** — open any category, the "Attributes" widget appears below details. Add custom attributes (inherited by subcategories), or pick from a template.
|
|
127
|
+
2. **Global attributes** — Settings → *Product Attributes* → Globals tab. Applied to every product automatically.
|
|
128
|
+
3. **Templates** — Settings → *Product Attributes* → Templates tab. Reusable blueprints.
|
|
129
|
+
4. **Product values** — open any product, the "Characteristics" widget shows all inherited + global attributes with inputs.
|
|
93
130
|
|
|
94
131
|
### API
|
|
95
132
|
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
GET /admin/product/:productId/attribute-schema
|
|
99
|
-
|
|
100
|
-
// List/create/update attributes for a category
|
|
133
|
+
```
|
|
134
|
+
GET /admin/product/:productId/attribute-schema
|
|
101
135
|
GET /admin/category/:categoryId/custom-attributes
|
|
102
136
|
POST /admin/category/:categoryId/custom-attributes
|
|
103
137
|
PATCH /admin/category/:categoryId/custom-attributes
|
|
104
|
-
|
|
105
|
-
// Global attributes
|
|
106
138
|
GET /admin/global-attributes
|
|
107
139
|
POST /admin/global-attributes
|
|
108
140
|
PATCH /admin/global-attributes
|
|
109
|
-
|
|
110
|
-
// Templates
|
|
111
141
|
GET /admin/attribute-templates
|
|
112
142
|
POST /admin/attribute-templates
|
|
113
143
|
PATCH /admin/attribute-templates
|
|
114
144
|
POST /admin/attribute-templates/:id/apply { category_id }
|
|
115
|
-
|
|
116
|
-
// Product values
|
|
117
145
|
GET /admin/product/:productId/custom-attributes
|
|
118
146
|
POST /admin/product/:productId/custom-attributes
|
|
119
147
|
```
|
|
120
148
|
|
|
149
|
+
### Programmatic usage
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
import { CUSTOM_ATTRIBUTE_MODULE } from '@empty-complete-org/medusa-product-attributes'
|
|
153
|
+
|
|
154
|
+
const module = container.resolve(CUSTOM_ATTRIBUTE_MODULE)
|
|
155
|
+
|
|
156
|
+
// Create a category attribute
|
|
157
|
+
await module.createCategoryAttribute({
|
|
158
|
+
label: 'Screen Size',
|
|
159
|
+
type: 'number',
|
|
160
|
+
unit: 'inch',
|
|
161
|
+
category_id: 'pcat_phones',
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
// Add a product value
|
|
165
|
+
await module.createProductAttribute({
|
|
166
|
+
product_id: 'prod_iphone15pro',
|
|
167
|
+
category_custom_attribute_id: 'attr_screen_size',
|
|
168
|
+
value: '6.1',
|
|
169
|
+
value_numeric: 6.1,
|
|
170
|
+
})
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
121
175
|
## Attribute types
|
|
122
176
|
|
|
123
177
|
| Type | Admin input | Stored in |
|
|
@@ -127,24 +181,60 @@ POST /admin/product/:productId/custom-attributes
|
|
|
127
181
|
| `file` | upload button | `value` (URL), `value_file` |
|
|
128
182
|
| `boolean` | select Yes/No | `value` |
|
|
129
183
|
|
|
130
|
-
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Project Structure
|
|
131
187
|
|
|
132
|
-
|
|
133
|
-
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
188
|
+
```
|
|
189
|
+
medusa-product-attributes/
|
|
190
|
+
├── src/
|
|
191
|
+
│ ├── admin/
|
|
192
|
+
│ │ ├── lib/
|
|
193
|
+
│ │ │ ├── i18n.ts
|
|
194
|
+
│ │ │ ├── locales/
|
|
195
|
+
│ │ │ │ ├── en.json
|
|
196
|
+
│ │ │ │ └── ru.json
|
|
197
|
+
│ │ │ └── sdk.ts
|
|
198
|
+
│ │ ├── routes/settings/product-attributes/
|
|
199
|
+
│ │ │ └── page.tsx
|
|
200
|
+
│ │ └── widgets/
|
|
201
|
+
│ │ ├── category-attribute-templates.tsx
|
|
202
|
+
│ │ └── product-attribute-values.tsx
|
|
203
|
+
│ ├── api/admin/
|
|
204
|
+
│ │ ├── attribute-templates/
|
|
205
|
+
│ │ ├── category/[categoryId]/custom-attributes/
|
|
206
|
+
│ │ ├── global-attributes/
|
|
207
|
+
│ │ └── product/[productId]/
|
|
208
|
+
│ │ ├── attribute-schema/
|
|
209
|
+
│ │ └── custom-attributes/
|
|
210
|
+
│ └── modules/product-attributes/
|
|
211
|
+
│ ├── models/
|
|
212
|
+
│ ├── migrations/
|
|
213
|
+
│ ├── service.ts
|
|
214
|
+
│ └── index.ts
|
|
215
|
+
├── assets/
|
|
216
|
+
├── package.json
|
|
217
|
+
├── tsconfig.json
|
|
218
|
+
└── LICENSE
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
---
|
|
138
222
|
|
|
139
223
|
## Development
|
|
140
224
|
|
|
141
225
|
```bash
|
|
142
226
|
pnpm install
|
|
143
|
-
pnpm test
|
|
144
|
-
pnpm run build
|
|
145
|
-
pnpm run dev
|
|
227
|
+
pnpm test # Jest unit tests
|
|
228
|
+
pnpm run build # medusa plugin:build
|
|
229
|
+
pnpm run dev # medusa plugin:develop
|
|
146
230
|
```
|
|
147
231
|
|
|
148
|
-
|
|
232
|
+
---
|
|
149
233
|
|
|
150
|
-
|
|
234
|
+
<div align="center">
|
|
235
|
+
<h2>Contributing</h2>
|
|
236
|
+
<p>Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.</p>
|
|
237
|
+
<p>
|
|
238
|
+
<sub>Made with ❤️ for the Medusa community</sub>
|
|
239
|
+
</p>
|
|
240
|
+
</div>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empty-complete-org/medusa-product-attributes",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
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",
|
|
@@ -86,4 +86,4 @@
|
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"transliteration": "^2.6.1"
|
|
88
88
|
}
|
|
89
|
-
}
|
|
89
|
+
}
|