# 🛍️ Medusa Product Filter Plugin

## 🔧 Compatibility

- Node.js: >= 20
- Medusa: v2.4.0
- @medusajs/admin-sdk: 2.4.0
- @medusajs/framework: 2.4.0
- @medusajs/ui: 4.0.4

## 📥 Installation

### Using npm
```bash
npm install @tsc_tech/medusa-plugin-product-filter
```

### Using yarn
```bash
yarn add @tsc_tech/medusa-plugin-product-filter
```

After installation, make sure to configure your `medusa-config.js`:

```javascript
module.exports = {
  plugins: [
    // ... other plugins
    {
      resolve: `@tsc_tech/medusa-plugin-product-filter`,
      options: {}
    },
  ],
}
```

## 🎯 Product Filter API

### 1. 📦 Get Filtered Products
Retrieve products based on specified filters.

**Endpoint:** `GET /store/filter/products`

**Headers:**
```http
Content-Type: application/json
x-publishable-api-key: <your-publishable-key>
```

**Query Parameters:**
- `option_value[]`: Filter by product option values
- `limit` (number): Number of products per page
- `min_price` (number): Minimum price filter
- `max_price` (number): Maximum price filter

**Example Request:**
```bash
curl --location --globoff 'http://localhost:9000/store/filter/products?option_value[]=[%22option1%22%2C%22option2%22]&limit=10&min_price=0&max_price=50' \
--header 'Content-Type: application/json' \
--header 'x-publishable-api-key: <your-publishable-key>'
```

### 2. 💰 Get Price Range
Retrieve the price range for products in a specific category.

**Endpoint:** `GET /store/filter/products/price-range`

**Headers:**
```http
x-publishable-api-key: <your-publishable-key>
```

**Query Parameters:**
- `categoryId`: ID of the category to get price range for

**Example Request:**
```bash
curl --location 'http://localhost:9000/store/filter/products/price-range/?categoryId=<category-id>' \
--header 'x-publishable-api-key: <your-publishable-key>'
```

**Example Response:**
```json
{
    "max": "100",
    "min": "10"
}
```

### 3. 🔍 Get Category Filter Options
Retrieve all available option values for a specific category.

**Endpoint:** `GET /store/category/filter/:categoryHandle`

**Headers:**
```http
x-publishable-api-key: <your-publishable-key>
```

**Parameters:**
- `categoryHandle`: The handle of the category (URL parameter)

**Example Request:**
```bash
curl --location 'http://localhost:9000/store/category/filter/<category-handle>' \
--header 'x-publishable-api-key: <your-publishable-key>'
```

**Example Response:**
```json
[
    {
        "title": "color",
        "values": [
            "red",
            "green",
            "blue",
            "black"
        ]
    }
]
```
The response provides an array of option types and their available values in the specified category.

**Note:** 
- Replace `<your-publishable-key>` with your Medusa instance publishable key
- Replace `<category-handle>` with your actual category handle
- Replace `<category-id>` with your actual category ID

### 4. 🎨 Get Filtered Product Variants
Retrieve product variants based on specified filters.

**Endpoint:** `GET /store/filter/product-variants`

**Headers:**
```http
x-publishable-api-key: <your-publishable-key>
```

**Query Parameters:**
- `region_id`: ID of the region
- `option_value[]`: Filter by variant option values
- `min_price` (number): Minimum price filter
- `max_price` (number): Maximum price filter

**Example Request:**
```bash
curl --location --globoff 'http://localhost:9000/store/filter/product-variants?region_id=<region-id>&option_value[]=[%22option1%22%2C%22option2%22]&min_price=10&max_price=50' \
--header 'x-publishable-api-key: <your-publishable-key>'
```

**Note:** ℹ️
- Replace `<your-publishable-key>` with your Medusa instance publishable key
- Replace `<region-id>` with your actual region ID
- Replace `<category-handle>` with your actual category handle
- Replace `<category-id>` with your actual category ID

## 🆘 Support

If you encounter any issues or need additional help:
- 💬 Join the [Medusa Discord community](https://discord.gg/medusajs)
- 📚 Check the [Medusa Documentation](https://docs.medusajs.com)