Skip to content

Commit

Permalink
feat(method): new 'minQuantity' method for product stock check
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Jul 1, 2019
1 parent e29a9b6 commit 15fd498
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import formatMoney from './methods/format-money'
import findByProperty from './methods/find-by-property'
import findBySlug from './methods/find-by-slug'
import filterByParentSlug from './methods/filter-by-parent-slug'
import minQuantity from './methods/min-quantity'

const self = name + '@' + version

Expand Down Expand Up @@ -45,7 +46,8 @@ export {
formatMoney,
findByProperty,
findBySlug,
filterByParentSlug
filterByParentSlug,
minQuantity
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/methods/min-quantity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const minQuantity = product => (product && product.min_quantity) || 1

/**
* @method
* @memberof ecomUtils
* @name minQuantity
* @description Returns the minimum quantity to add to cart.
* @param {object} product - Body object (product or variation)
* @returns {number}
*
* @example
* // With min quantity specified
* // Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
* const product = { sku: 'TEST', name: 'Test', price: 10, min_quantity: 10 }
* ecomUtils.minQuantity(product)
* // => 10
* product.min_quantity = 0
* ecomUtils.minQuantity(product)
* // => 0
*
* @example
* // 1 by default when min quantity is undefined
* ecomUtils.minQuantity({ sku: 'TEST', name: 'Test' })
* // => 1
* ecomUtils.minQuantity({})
* // => 1
*/

export default minQuantity

0 comments on commit 15fd498

Please sign in to comment.