@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.
Files changed (2) hide show
  1. package/README.md +144 -54
  2. 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
- - **4 attribute types**: text, number (with units), file, boolean
34
- - **Category inheritance**: attributes defined on a parent category are automatically inherited by all subcategories
35
- - **Global attributes**: applied to every product in the store
36
- - **Templates**: reusable attribute blueprints apply to any category in one click
37
- - **Automatic slug generation**: labels are transliterated (works with Russian, Chinese, any script)
38
- - **Smart file naming**: uploaded images are renamed to `{product_handle}_{attr_key}.ext`
39
- - **Admin UI included**: category widget, product widget, two Settings pages
40
- - **Ships with migrations**: just run `npx medusa db:migrate`
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
- ## Screenshots
54
+ ---
43
55
 
44
- ### Category widget with inheritance
45
- ![Category widget](./assets/category-widget.png)
56
+ ### Requirements
46
57
 
47
- ### Product attribute values
48
- ![Product widget](./assets/product-widget.png)
58
+ | Dependency | Version |
59
+ |------------|---------|
60
+ | Medusa | ^2.13 |
61
+ | Node.js | >=20 |
62
+ | TypeScript | ^5.0 |
49
63
 
50
- ### Global attributes settings
51
- ![Global attributes](./assets/global-attributes.png)
64
+ ---
52
65
 
53
- ### Attribute templates settings
54
- ![Templates](./assets/templates.png)
66
+ ## Quick Start
55
67
 
56
- ## Installation
68
+ ### Installation
57
69
 
58
70
  ```bash
71
+ # Via pnpm
59
72
  pnpm add @empty-complete-org/medusa-product-attributes
60
- # or
73
+
74
+ # Via npm
61
75
  npm install @empty-complete-org/medusa-product-attributes
62
- # or
76
+
77
+ # Via yarn
63
78
  yarn add @empty-complete-org/medusa-product-attributes
64
79
  ```
65
80
 
66
- Add to `medusa-config.ts`:
81
+ ### 1. Add the plugin to configuration
82
+
83
+ ```typescript
84
+ // medusa-config.ts
85
+ import { defineConfig } from '@medusajs/framework/utils'
67
86
 
68
- ```ts
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
+ ![Category widget](./assets/category-widget.png)
113
+
114
+ ### Product attribute values
115
+ ![Product widget](./assets/product-widget.png)
116
+
117
+ ### Settings — Global Attributes & Templates
118
+ ![Settings page](./assets/settings-page.png)
119
+
120
+ ---
121
+
85
122
  ## Usage
86
123
 
87
124
  ### Admin
88
125
 
89
- 1. **Category attributes** — open any category in admin, the "Атрибуты" widget appears below the details. Add custom attributes (inherited by all subcategories), or pick one from a template.
90
- 2. **Global attributes** — Settings → *Global Attributes*. Applied to every product automatically.
91
- 3. **Templates** — Settings → *Attribute Templates*. Create reusable blueprints.
92
- 4. **Product values** — open any product, the "Характеристики" widget shows all inherited + global attributes with inputs for their values.
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
- ```ts
97
- // List all attributes for a product (globals + category chain)
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
- ## Peer dependencies
184
+ ---
185
+
186
+ ## Project Structure
131
187
 
132
- - `@medusajs/framework` ^2.13
133
- - `@medusajs/medusa` ^2.13
134
- - `@medusajs/admin-sdk` ^2.13
135
- - `@medusajs/ui` ^4
136
- - `@tanstack/react-query` ^5
137
- - `react` ^18 || ^19
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 # builds to .medusa/server/
145
- pnpm run dev # medusa plugin:develop
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
- ## License
232
+ ---
149
233
 
150
- MIT © empty-complete
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.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
+ }