Skip to main content

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:

TypeDescriptionExample
Simple ProductSingle item, no variantsBook, Poster
Product with VariantsMultiple options (size, color)T-shirt (S/M/L, Red/Blue)
Digital ProductDownloadable itemsE-book, Software
BundleGroup of productsStarter 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​

MethodWhen to UseExample
getProducts()List products with filters/searchShop catalog page
getProductByUrl()User visits specific product page/products/sneakers
getProductByMarker()Reference product in codefeatured_product
getProductById()Internal referencesProduct 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:

sortKeyWhat It DoesExample Use
priceSort by priceShow cheapest first
dateSort by creation dateShow newest products
titleSort alphabeticallyA-Z product list
positionCustom order (default)Hand-picked order from admin
idSort by IDTechnical 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:

MarkerMeaningExample
eqEqual (exact match)Price = $50
neqNot equalStatus β‰  "sold out"
inContains (one of)Color in ["red", "blue"]
ninNot containsCategory not in ["archived"]
mthGreater thanPrice > $100
lthLess thanPrice < $50
exsExists (has value)Has discount
nexsDoes 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​

MethodWhat It DoesWhen to Use
getProducts()Get all products (filtered, sorted, paginated)Product catalog page
getProductById()Get product by IDInternal references
getProductByUrl()Get product by URLProduct detail page
getProductByMarker()Get product by markerFeatured/special products
getProductsStatusesByMarker()Get available statusesFilter by status
getRelatedProducts()Get related/similar products"You may also like" section
getProductStatus()Check product availabilityStock 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: 1 in 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