medusa-product-listing-logic
v1.2.3
Published
Ported Product Listing logic from B&B_ui project.
Readme
Medusa Product Listing Logic
A lightweight utility library for handling product listing, sorting, and searching in Medusa storefronts.
Features
- Client-side product sorting (price, date).
- Pagination support.
- Product search by query.
- Inventory-aware product fetching.
- Fetch product order counts.
Installation
npm install medusa-product-listing-logicUsage
Sorting Products
import { sortProducts, SortOptions } from 'medusa-product-listing-logic';
const products = [...]; // Array of Medusa StoreProduct
const sorted = sortProducts(products, 'price_asc');Listing Products
import { listProducts } from 'medusa-product-listing-logic';
const { response, nextPage } = await listProducts({
sdk: medusaSdk,
region: currentRegion,
pageParam: 1,
queryParams: { limit: 12 }
});API Functions
| Function | Description |
| :--- | :--- |
| sortProducts | Sorts products by price or creation date. |
| listProducts | Fetches a paginated list of products. |
| listProductsWithSort | Fetches and sorts products client-side. |
| searchProducts | Searches products by a string query. |
| getProductWithInventory | Fetches a product with full inventory details. |
| getProductOrderCount | Fetches the total number of orders for a product. |
License
MIT
