Kaynağa Gözat

[ADD] product pack mapping

robert 6 yıl önce
ebeveyn
işleme
d9f1a44cfc
1 değiştirilmiş dosya ile 23 ekleme ve 4 silme
  1. 23 4
      src/store/modules/cart.js

+ 23 - 4
src/store/modules/cart.js

@@ -5,13 +5,31 @@ const state = {
 }
 
 const getters = {
-    cartItems (state) {
+    cartItems(state, getters) {
+        if (state.cartItems.length > 0) {
+            for (let item of state.cartItems) {
+                if (!!item.packs) {
+                    continue
+                }
+
+                item.packs = []
+
+                for (let pack of getters.packs) {
+                    if (item.id !== pack.productId) {
+                        continue
+                    }
+
+                    item.packs.push(pack)
+                }
+            }
+        }
+
         return state.cartItems
     },
-    cartTotal (state, getters) {
+    cartTotal(state) {
         return state.cartTotal
     },
-    itemToDiscount (state) {
+    itemToDiscount(state) {
         return state.itemToDiscount
     }
 }
@@ -35,7 +53,8 @@ const mutations = {
             }
             return
         }
-        console.log(getters)
+
+        // console.log(getters)
         state.cartItems = [payload, ...state.cartItems]
     },
     pullFromCart (state, payload) {