beerbay-math
Version:
39 lines (32 loc) • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getCartPrice = exports.getCartQuantity = void 0;
var _products = require("./products");
/**
* @method getCartQuantity
* @description Return the cart
* @param {any[]} cart
*/
var getCartQuantity = function getCartQuantity() {
var cart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var quantity = cart.reduce(function (acc, current) {
return acc + current.quantity;
}, 0);
return quantity;
};
/**
* @method getCartPrice
* @description Sum up all of the product prices
* @param {any[]} cart
*/
exports.getCartQuantity = getCartQuantity;
var getCartPrice = function getCartPrice() {
var cart = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var price = cart.reduce(function (acc, current) {
return acc + (0, _products.getProductPrice)(current) * (0, _products.getProductQuantity)(current);
}, 0);
return parseFloat(price.toFixed(2));
};
exports.getCartPrice = getCartPrice;