Skip to content
Snippets Groups Projects
Commit 56ca5cbc authored by Fabio Heyming's avatar Fabio Heyming
Browse files

Added persistant shopping cart

parent a2960b1c
Branches
No related tags found
1 merge request!1Mal aufn Master megren
...@@ -283,7 +283,7 @@ public class MampfMobil { ...@@ -283,7 +283,7 @@ public class MampfMobil {
// bestellungsteil besteht aus Customer-ID, ShopItem-ID //Customer-ID, ShopItem-ID
String csvFavoriten = ""; String csvFavoriten = "";
for(Customer c:MampfMobil.customers){ for(Customer c:MampfMobil.customers){
for(ShopItem sI: c.favoriten){ for(ShopItem sI: c.favoriten){
...@@ -291,7 +291,18 @@ public class MampfMobil { ...@@ -291,7 +291,18 @@ public class MampfMobil {
} }
} }
String fileName7 = "favoriten.csv"; String fileName7 = "favoriten.csv";
CSVFileHelper.saveCSVFile(context, fileName7, csvBestellungen); CSVFileHelper.saveCSVFile(context, fileName7, csvFavoriten);
//Customer-ID, Item-ID, quantity
String csvShoppingCart = "";
for(Customer c:MampfMobil.customers){
for(BestellungsTeil bT: c.shoppingCart){
csvShoppingCart = csvShoppingCart + c.id + ","+ bT.item.id + "," + bT.quantity +"\n";
}
}
String fileName8 = "shoppingCart.csv";
CSVFileHelper.saveCSVFile(context, fileName8, csvShoppingCart);
} }
...@@ -479,15 +490,17 @@ public class MampfMobil { ...@@ -479,15 +490,17 @@ public class MampfMobil {
String[] lines = csvData7.split("\n"); String[] lines = csvData7.split("\n");
for (String line : lines) { for (String line : lines) {
String[] data = line.split(","); String[] data = line.split(",");
Log.d("myTag", "ADDED 1 fav");
if (data.length >= 2) { if (data.length >= 2) {
int cusId = Integer.parseInt(data[0]); int cusId = Integer.parseInt(data[0]);
int shopItemId = Integer.parseInt(data[0]); int shopItemId = Integer.parseInt(data[1]);
Log.d("myTag", "ADDED 2 fav");
for (Customer c : MampfMobil.customers) { for (Customer c : MampfMobil.customers) {
if (c.id == cusId) { if (c.id == cusId) {
Log.d("myTag", "ADDED 3 fav");
for (Supplier s : MampfMobil.suppliers) { for (Supplier s : MampfMobil.suppliers) {
for (ShopItem sI : s.shopItems) { for (ShopItem sI : s.shopItems) {
Log.d("myTag", sI.id + "" + shopItemId);
if (sI.id == shopItemId) { if (sI.id == shopItemId) {
c.addToFavourits(sI); c.addToFavourits(sI);
} }
...@@ -498,5 +511,34 @@ public class MampfMobil { ...@@ -498,5 +511,34 @@ public class MampfMobil {
} }
} }
} }
String fileName8 = "shoppingCart.csv";
String csvData8 = CSVFileHelper.loadCSVFile(context, fileName8);
if (csvData8 != null) {
String[] lines = csvData8.split("\n");
for (String line : lines) {
String[] data = line.split(",");
if (data.length >= 3) {
int cusId = Integer.parseInt(data[0]);
int itemId = Integer.parseInt(data[1]);
int amount = Integer.parseInt(data[2]);
for (Customer c : MampfMobil.customers) {
if (c.id == cusId) {
for (Supplier s : MampfMobil.suppliers) {
for (ShopItem sI : s.shopItems) {
if (sI.item.id == itemId) {
c.addToShoppingCart(new BestellungsTeil(sI.item,amount));
}
}
}
}
}
}
}
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment