@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
38 lines • 1.19 kB
TypeScript
export default price;
/**
* @method
* @memberof ecomUtils
* @name price
* @description Returns current price from item object.
* @param {Object.<string, *>} product - Item (product or variation) body object
* @returns {number}
*
* @example
* // Prices with no promotion date range
* // Full object ref.: https://developers.e-com.plus/docs/api/#/store/products/
* ecomUtils.price({ sku: 'TEST', name: 'Test', price: 140.56 })
* // => 140.56
* ecomUtils.price({ price: 100, base_price: 110 })
* // => 100
* ecomUtils.price({ price: 190, base_price: 170 })
* // => 190
* ecomUtils.price({})
* // => 0
*
* @example
* // With promotion date range
* const product = { sku: 'abc', price: 20.9, base_price: 30.9, price_effective_date: {} }
* product.price_effective_date.start = '2021-01-01T00:00:00.000Z'
* ecomUtils.price(product)
* // => 30.9
* product.price_effective_date.start = '2019-06-01T16:03:45.035Z'
* ecomUtils.price(product)
* // => 20.9
* product.price_effective_date.end = '2019-06-10T16:03:45.035Z'
* ecomUtils.price(product)
* // => 30.9
*/
declare function price(product: {
[x: string]: any;
}): number;
//# sourceMappingURL=price.d.ts.map