common.js 497 B

123456789101112131415161718192021222324
  1. export class MenuItem {
  2. constructor (title, price) {
  3. this.title = title
  4. this.price = price
  5. }
  6. }
  7. export class CartItem {
  8. constructor (menuItem) {
  9. this.title = menuItem.title
  10. this.price = menuItem.price
  11. this.quantity = 1
  12. }
  13. }
  14. export function calcItog (cartList) {
  15. if (Array.isArray(cartList) && cartList.length) {
  16. return cartList.reduce((total, item) => {
  17. // console.log('item', item)
  18. return total + item.price * item.quantity
  19. }, 0)
  20. }
  21. return 0
  22. }