Secondary Category Module
In this section of the documentation, you will find resources to learn more about the Secondary Category Module and how to use it in your application. Mercur has secondary product categorization features available out-of-the-box through the Secondary Category Module. A module is a standalone package that provides features for a single domain. Each of Mercur’s marketplace features are placed in custom modules, such as this Secondary Category Module. Learn more about why modules are isolated in this documentation.Secondary Category Features
- Flexible Product Categorization: Allow products to belong to multiple categories beyond their primary category.
- Category-Based Navigation: Enable products to appear in multiple category browsing contexts.
- Dynamic Category Assignment: Add or remove secondary categories when creating or updating products.
- Cross-Category Discovery: Help customers discover products through multiple categorization paths.
How to Use the Secondary Category Module
In your Medusa application, you build flows around Commerce Modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism. Secondary categories are managed through workflow hooks on Medusa’s coreupdateProductsWorkflow. Mercur extends this workflow to handle secondary category assignments:
src/workflows/hooks/product-updated.ts
Workflow Usage
Concepts
In this document, you’ll learn about the main concepts related to secondary categories in Mercur.Secondary Category
A secondary category is a reference to a Medusa product category that allows products to be organized under multiple categories simultaneously. It is represented by the SecondaryCategory data model. A secondary category holds:- A unique ID
- A reference to a product category via
category_id
Primary vs Secondary Categories
Primary Category
In Medusa’s Product Module, each product can belong to multiple categories through the built-in many-to-many relationship. These are considered the product’s primary categories.Secondary Category
Mercur’s Secondary Category Module provides an additional layer of categorization:- Products can be tagged with secondary categories
- Useful for cross-cutting concerns (e.g., “Sale Items”, “Seasonal”, “Featured”)
- Separate from the primary category hierarchy
- Can be managed independently without affecting product category structure
Why Secondary Categories?
Use Case Example: A dress might have:- Primary Category: Women’s Clothing → Dresses
- Secondary Categories:
- Summer Collection
- Sale Items
- New Arrivals
- Wedding Guest Outfits
Dynamic Assignment
Secondary categories can be dynamically assigned when creating or updating products through theadditional_data parameter:
- Creates or retrieves secondary category records for the specified category IDs
- Creates module links between products and secondary categories
- Removes links for categories in the
removearray
Workflow Hook Integration
Secondary categories are managed through a workflow hook on Medusa’supdateProductsWorkflow: