@nicogorga/medusa-product-attributes v2.0.2
@nicogorga/medusa-product-attributes
Create global (category specific) product attributes on your Medusa commerce application
!WARNING This plugin is a WIP and I am working on it in my spare time between projects and work. Feel free to make contributions by making pull requests and proposing ideas / new flows to implement via Discussions If this helps you, you can buy me a :coffee: or reach out to me if you need help with your MedusaJS projects :wink:
Compatibility
This plugin is compatible with versions >= 2.6.1 of @medusajs/medusa.
Progress
All the progress is recorded in CHANGELOG.md and so far, it is solely focused on backend (you can use the functionallities via API calls)
Roadmap
- Introduce entities to facilitate constructing UI components in Admin Panel and filtering them in Storefront
- Create Admin panel route / widgets to interact with attribute / attribute values and link them to products
- Create adaptation of starter to show example of Storefront filtering products with attributes
Prerequisites
How to Install
1. Run the following command in the directory of the Medusa backend using your package manager (for example for npm):
npm install @nicogorga/medusa-product-attributes2. In medusa-config.ts add the following at the end of the plugins array in your project config object:
projectConfig: {
plugins = [
// ...
{
resolve: `@nicogorga/medusa-product-attributes`,
},
]
}3. In your already existent or new createProductsWorkflow.productsCreated hook handler, import productsCreatedHookHandler and call it like following. This is important as it's what links new products to the requested attribute values (if any):
import { createProductsWorkflow } from "@medusajs/medusa/core-flows";
import { productsCreatedHookHandler } from "@nicogorga/medusa-product-attributes/utils/products-created-handler"
createProductsWorkflow.hooks.productsCreated(
async ({ products, additional_data }, { container }) => {
const links = await productsCreatedHookHandler({ products, additional_data, container })
// Your own logic (if any). You can return 'links' to your compensation function, to dismiss the links if an error occurs
}
)4. In your already existent or new updateProductsWorkflow.productsUpdated hook handler, import productUpdatedHookHandler and call it like following. This is important as it's what updated the porduct attributes, with the requested attribute values (if any):
import { updateProductsWorkflow } from "@medusajs/medusa/core-flows";
import { productsUpdatedHookHandler } from "@nicogorga/medusa-product-attributes/utils/products-updated-handler"
updateProductsWorkflow.hooks.productsUpdated(
async ({ products, additional_data }, { container }) => {
const links = await productsUpdatedHookHandler({ products, additional_data, container })
// Your own logic (if any). You can return 'links' to your compensation function, to dismiss the links if an error occurs
}
)Additional Resources
- medusa-custom-attributes v1 Props to Viktor Holik, the creator, for his work as it is a great reference and has proved to be open to help
- Github Discussions