@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
40 lines (39 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _minQuantity = _interopRequireDefault(require("./min-quantity"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @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
*/
var inStock = function inStock(product) {
return !product.hasOwnProperty('quantity') || product.quantity >= (0, _minQuantity.default)(product);
};
var _default = exports.default = inStock;