Products

Fetch ordered product

const order = { // Order from the 'Orders' publication example.
    _id: 'order-id-from-example',
    productId: 'product-id',
};

DDPClient.subscribe('ordered.product', [order._id], () => {
    const collection = DDPClient.collections['shop.products'];
    const product = collection[order.productId];

    product._id         // Product ID
    product.name        // Product name
    product.description // Product description as defined in the product manager page.
    product.minQuantity // Minimum order quantity.
    product.shopId      // ID of the shop this product belongs to.
    product.stockCount  // Remaining stock.
    product.value       // Value in cents for this product. ($1 = 100).
});

Search for products

const shopId = 'ID-of-your-shop';

const query = {             // optional
    search: 'Steam Keys',   // Search by product name
}

const options = {
    limit: 50, // Maximum number of products to fetch at one time. (optional)
    skip: 0,   // Number of products to skip. (optional)
    sort: {
        createdAt: -1, // Sort direction. (optional)
                       // -1 = descending
                       // 1 = ascending
    }
}

DDPClient.subscribe('admin.shop.products', [shopId, query, options], () => {
    const products = DDPClient.collections['shop.products']; // Array of product objects.
})

Fetch products by their ID.

const shopId = 'ID-of-your-shop';

const productIds = [ // Array of products you'd like to retrieve.
    'ciLygg2LmnNYHKrp7',
]

DDPClient.subscribe('admin.shop.products', [shopId, productIds], () => {
    const products = DDPClient.collections['shop.products']; // Array of products fetched from the server.
})