@csbeker/medusa-product-attributes
v2.3.2
Published
A plugin for adding attributes support to MedusaJS products
Maintainers
Readme
Medusa Product Attributes Plugin
[!NOTE] Este plugin es un fork y continúa el desarrollo del repositorio original de Nicolas Gorga. Se agregan mejoras, soporte y nuevas funcionalidades sobre la base de su trabajo.
Create global (category specific) product attributes on your Medusa commerce application.
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
- Create Admin panel widgets link attribute values to products
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 to the plugins array in your project config:
module.exports = defineConfig({
projectConfig: {
// ...
},
plugins: [
{
resolve: `@nicogorga/medusa-product-attributes`,
options: {}
}
]
})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
