Introduction
Manage e-commerce products with dynamic catalogs, filtering, and search.
π― What does this module do?β
The Products module lets you create, retrieve, filter, and manage products in your online store or catalog - from simple items to complex products with variants, images, prices, and custom attributes.
Think of it as your digital warehouse - you manage your product inventory in OneEntry, and your app fetches products dynamically with powerful search, filters, and sorting.
π Simple Explanationβ
Imagine you're building an online store selling:
- π Sneakers - with sizes, colors, prices
- π± Electronics - with specs, images, reviews
- π Clothing - with sizes, materials, variants
- π Books - with authors, prices, descriptions
Instead of hardcoding each product, you:
- β Add products in OneEntry admin panel (with all details)
- β Fetch products dynamically using this module
- β Filter by category, price range, availability
- β Search products by name or description
- β Sort by price, date, popularity
- β Update prices/stock without redeploying
Real-world example:
Without Products Module (hardcoded):
- Add new product β Change code β Deploy β
- Change price β Code change β Deploy β
- 1000 products = massive code file β
With Products Module (dynamic):
- Add new product β Update in admin β Live instantly β
- Change price β Update in admin β Live instantly β
- 10,000 products = simple API calls β
β¨ Key Conceptsβ
What is a Product?β
A product is an item you sell, containing:
- Basic info - Name, description, SKU, price
- Images - Product photos, gallery
- Variants - Sizes, colors, options (e.g., "Red T-shirt Size M")
- Inventory - Stock quantity, availability
- Custom attributes - Any fields you define (brand, material, weight, etc.)
- SEO - Meta title, description, keywords
- Status - Active, draft, out of stock
- Localization - Multi-language support
Product Structureβ
Products can have different structures:
| Type | Description | Example |
|---|---|---|
| Simple Product | Single item, no variants | Book, Poster |
| Product with Variants | Multiple options (size, color) | T-shirt (S/M/L, Red/Blue) |
| Digital Product | Downloadable items | E-book, Software |
| Bundle | Group of products | Starter Pack, Gift Set |
Product Organizationβ
Products are organized by:
- Categories - Organize into sections (e.g., Men's Clothing, Electronics)
- Statuses - Active, Draft, Out of Stock
- Price ranges - Budget, Mid-range, Premium
- Custom filters - Brand, Size, Color, Material, etc.
Example hierarchy:
π Electronics
ββ π± Smartphones
β ββ iPhone 15 Pro
β ββ Samsung Galaxy S24
ββ π» Laptops
ββ MacBook Pro
ββ Dell XPS
π Clothing
ββ π T-Shirts
ββ π Jeans
π What You Need to Knowβ
1. Three Ways to Get Productsβ
| Method | When to Use | Example |
|---|---|---|
| getProducts() | List products with filters/search | Shop catalog page |
| getProductByUrl() | User visits specific product page | /products/sneakers |
| getProductByMarker() | Reference product in code | featured_product |
| getProductById() | Internal references | Product ID: 123 |
2. Pagination Explained Simplyβ
When you have 1000 products, you don't load all at once:
Offset formula: offset = (pageNumber - 1) * limit
3. Sorting Optionsβ
Sort products by different fields:
| sortKey | What It Does | Example Use |
|---|---|---|
| price | Sort by price | Show cheapest first |
| date | Sort by creation date | Show newest products |
| title | Sort alphabetically | A-Z product list |
| position | Custom order (default) | Hand-picked order from admin |
| id | Sort by ID | Technical sorting |
Sort order:
- ASC (Ascending) - Low to high (AβZ, 0β9, cheapβexpensive)
- DESC (Descending) - High to low (ZβA, 9β0, expensiveβcheap)
4. Filtering Productsβ
Use filters to narrow down results:
Condition markers:
| Marker | Meaning | Example |
|---|---|---|
| eq | Equal (exact match) | Price = $50 |
| neq | Not equal | Status β "sold out" |
| in | Contains (one of) | Color in ["red", "blue"] |
| nin | Not contains | Category not in ["archived"] |
| mth | Greater than | Price > $100 |
| lth | Less than | Price < $50 |
| exs | Exists (has value) | Has discount |
| nexs | Does not exist (empty) | No discount |
5. Product Statusβ
Products have different statuses:
const product = await Products.getProductById(123);
if (product.statusId === 1 && product.isVisible) {
console.log("β
Product is active and visible");
} else if (product.statusId === 0) {
console.log("π Product is draft");
} else {
console.log("π« Product is hidden");
}
Status values:
statusId: 1- Active (available for purchase)statusId: 0- Draft (not visible to customers)isVisible: false- Hidden (admin can see, customers can't)
π Quick Reference Table - Common Methodsβ
| Method | What It Does | When to Use |
|---|---|---|
| getProducts() | Get all products (filtered, sorted, paginated) | Product catalog page |
| getProductById() | Get product by ID | Internal references |
| getProductByUrl() | Get product by URL | Product detail page |
| getProductByMarker() | Get product by marker | Featured/special products |
| getProductsStatusesByMarker() | Get available statuses | Filter by status |
| getRelatedProducts() | Get related/similar products | "You may also like" section |
| getProductStatus() | Check product availability | Stock management |
β Common Questions (FAQ)β
Q: Can I filter by multiple criteria at once?β
A: Yes! Combine multiple filters:
// Find: Red T-shirts, Size M, Price under $30
const filtered = await Products.getProducts({
conditionValue: [
{ attributeMarker: "category", conditionMarker: "eq", value: "t-shirts" },
{ attributeMarker: "color", conditionMarker: "eq", value: "red" },
{ attributeMarker: "size", conditionMarker: "eq", value: "M" },
{ attributeMarker: "price", conditionMarker: "lth", value: 30 }
],
limit: 20
});
Q: How do I handle product variants (sizes, colors)?β
A: Product variants are stored in attributeValues:
const product = await Products.getProductByUrl('/products/t-shirt');
// Get available variants
const sizes = product.attributeValues.sizes?.value || []; // ["S", "M", "L", "XL"]
const colors = product.attributeValues.colors?.value || []; // ["Red", "Blue", "Green"]
Q: How do I implement "Load More" button?β
A: Use offset to load more products:
Q: Can I show products from multiple categories?β
A: Yes, use in condition marker:
// Show products from Electronics OR Clothing
const products = await Products.getProducts({
conditionValue: [{
attributeMarker: "category",
conditionMarker: "in", // Match any of these
value: ["electronics", "clothing", "accessories"]
}],
limit: 20
});
Q: How do I implement "New Arrivals" section?β
A: Sort by creation date or use parent category for manually sorting:
async function getNewArrivals(limit = 8) {
const result = await Products.getProducts({
sortKey: 'date', // Sort by creation date
sortOrder: 'DESC', // Newest first
limit: limit,
statusId: 1
});
return result.items;
}
// Usage
const newProducts = await getNewArrivals(8);
π‘ Important Notesβ
Performance Optimizationβ
Cache frequently accessed products:
const productCache = new Map();
const CACHE_DURATION = 5 * 60 * 1000; // 5 minutes
async function getCachedProduct(url) {
const cached = productCache.get(url);
if (cached && Date.now() - cached.timestamp < CACHE_DURATION) {
return cached.product;
}
const product = await Products.getProductByUrl(url);
productCache.set(url, {
product: product,
timestamp: Date.now()
});
return product;
}
Always Filter Active Productsβ
In production, always show only active products
Handle Missing Imagesβ
Provide fallback for products without images
π Best Practicesβ
Do's:
- β Always use pagination (limit + offset)
- β
Filter by
statusId: 1in production - β Cache product lists to reduce API calls
- β Handle "out of stock" gracefully
- β Provide fallback images
- β Use markers for featured products (not IDs)
- β Implement search with debouncing
- β Add loading states in UI
Don'ts:
- β Fetch all products at once (use pagination!)
- β Show draft products to customers
- β Hardcode product IDs in code
- β Ignore error handling
- β Skip caching for popular products
- β Forget to format prices properly
- β Load high-res images without Optimization
Definition of the Products moduleβ
More information about the module's user interface https://doc.oneentry.cloud/docs/category/catalog
const { Products } = defineOneEntry( "your-project-url", { "token": "your-app-token" });
This module accepts a set of user parameters called userQuery. If the parameters are not passed to the method, the default value will be applied. Some methods accept the body as a parameter for filtering. If you don't want to set up sorting, pass an empty array or don't pass anything.
Parameters:
const userQuery = { offset: 0, limit: 30, sortOrder: 'DESC', sortKey: 'id',}
Schema
offset: number
Pagination parameter. Default 0
example: 0
limit: number
pagination parameter. Default 30
example: 30
sortKey: string
Field for sorting (default not set - sorting by position, possible values: id, title, date, price, position)
Available values: id, position, title, date, price
sortOrder: string
sorting order DESC | ASC (default DESC)
example: "DESC"
"conditionMarker" by which values are filtered (not set by default), possible values:
'in' - Contains,
'nin' - Does not contain,
'eq' - Equal,
'neq' - Not equal,
'mth' - Greater than,
'lth' - Less than,
'exs' - Exists,
'nexs' - Does not exist
π Related Documentationβ
- Pages Module - Manage product pages
- AttributesSets Module - Custom product fields
- Blocks Module - Reusable product content blocks
- Orders Module - Handle product orders