shopping cart done
Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
parent
7d443a1aeb
commit
41d62898c1
@ -52,6 +52,26 @@ public class ShoppingCartDB {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int updateItem(@NotNull ShoppingCartItem item) {
|
||||||
|
Connection connection = database.getConnection();
|
||||||
|
assert connection != null;
|
||||||
|
int alterCount = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PreparedStatement statement = connection.prepareStatement("UPDATE cart_books SET count = ? WHERE user = ? AND book = ?");
|
||||||
|
statement.setInt(1, item.getCount());
|
||||||
|
statement.setLong(2, item.getUser().getId());
|
||||||
|
statement.setLong(3, item.getArticle().getId());
|
||||||
|
|
||||||
|
alterCount += statement.executeUpdate();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return alterCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* insert new item to users shopping cart.
|
* insert new item to users shopping cart.
|
||||||
*
|
*
|
||||||
|
@ -3,11 +3,13 @@ package de.hsel.itech.jsf;
|
|||||||
import de.hsel.itech.db.Database;
|
import de.hsel.itech.db.Database;
|
||||||
import de.hsel.itech.db.pojo.*;
|
import de.hsel.itech.db.pojo.*;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.faces.annotation.ManagedProperty;
|
import javax.faces.annotation.ManagedProperty;
|
||||||
import javax.faces.bean.ManagedBean;
|
import javax.faces.bean.ManagedBean;
|
||||||
import javax.faces.bean.SessionScoped;
|
import javax.faces.bean.SessionScoped;
|
||||||
import javax.faces.context.FacesContext;
|
import javax.faces.context.FacesContext;
|
||||||
|
import javax.faces.event.PhaseId;
|
||||||
import javax.faces.event.ValueChangeEvent;
|
import javax.faces.event.ValueChangeEvent;
|
||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -72,10 +74,15 @@ public class CartBean {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void change(ValueChangeEvent event) {
|
public void change(@NotNull ValueChangeEvent event) {
|
||||||
System.out.println("änderung");
|
if (event.getPhaseId() != PhaseId.INVOKE_APPLICATION) {
|
||||||
|
event.setPhaseId(PhaseId.INVOKE_APPLICATION);
|
||||||
|
event.queue();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for(ShoppingCartItem item : getItems()) {
|
for(ShoppingCartItem item : getItems()) {
|
||||||
System.out.println(item.getCount());
|
Database.getInstance().shoppingCart().updateItem(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user