UNPKG

@ecomplus/utils

Version:

JS utility functions to E-Com Plus (not only) related apps

34 lines (31 loc) 1 kB
import minQuantity from './min-quantity.mjs' /** * @method * @memberof ecomUtils * @name inStock * @description Check if item has stock equal or greater than minimum quantity. * @param {Object.<string, *>} product - Body object (product or variation) * @returns {boolean} * * @example * // Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/ * const product = { sku: 'TEST', name: 'Test', price: 10 } * ecomUtils.inStock(product) * // => true * product.quantity = 5 * ecomUtils.inStock(product) * // => true * product.min_quantity = 10 * ecomUtils.inStock(product) * // => false * ecomUtils.inStock({ quantity: 1, min_quantity: 2 }) * // => false * ecomUtils.inStock({ quantity: 0 }) * // => false * ecomUtils.inStock({ quantity: 1, min_quantity: 1 }) * // => true * ecomUtils.inStock({ quantity: 1 }) * // => true */ const inStock = product => !product.hasOwnProperty('quantity') || product.quantity >= minQuantity(product) export default inStock