Commit 68deeb02 by Tuomas Riihimäki

Update product cart counts when committing cart.

It is possible to reserve any number of products despite product limits
if you type the number of products you want to buy and press 'buy'-button.

This is caused by event listener for product line firing after submit button is launched
This seems to be also fixed in newer primefaces version, but we don't want to trust
anything sent by javascript
1 parent bda09b74
......@@ -27,7 +27,6 @@ import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.ValueChangeEvent;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -46,7 +45,6 @@ import fi.codecrew.moya.model.LanEventProperty;
import fi.codecrew.moya.model.LanEventPropertyKey;
import fi.codecrew.moya.model.Product;
import fi.codecrew.moya.model.ReaderEvent;
import fi.codecrew.moya.web.annotations.SelectedUser;
import fi.codecrew.moya.web.cdiview.GenericCDIView;
import fi.codecrew.moya.web.cdiview.reader.ReaderView;
import fi.codecrew.moya.web.cdiview.user.UserView;
......@@ -73,8 +71,7 @@ public class ProductShopView extends GenericCDIView {
@EJB
private transient EventBeanLocal eventbean;
public void cashChanged()
{
public void cashChanged() {
payInstant = false;
}
......@@ -112,8 +109,7 @@ public class ProductShopView extends GenericCDIView {
private boolean allowStatistics = true;
private String otherInfo;
public String buyByCredit()
{
public String buyByCredit() {
cash = BigDecimal.ZERO;
payInstant = false;
return null;
......@@ -123,7 +119,7 @@ public class ProductShopView extends GenericCDIView {
if (requirePermissions(ShopPermission.LIST_USERPRODUCTS) && shoppingcart == null) {
shoppingcart = new ListDataModel<ProductShopItem>(ProductShopItem.productList(productBean.listUserShoppableProducts(), userView.getSelectedUser()));
for(ProductShopItem item : shoppingcart) {
for (ProductShopItem item : shoppingcart) {
psiHelper.updateProductShopItemCount(item);
}
......@@ -136,10 +132,8 @@ public class ProductShopView extends GenericCDIView {
private Boolean checkAllowStats;
public boolean isCheckAllowStats()
{
if (checkAllowStats == null)
{
public boolean isCheckAllowStats() {
if (checkAllowStats == null) {
LanEventProperty re = eventbean.getProperty(LanEventPropertyKey.CHECK_BILL_STATS_PERMISSION);
if (re != null) {
checkAllowStats = re.isBooleanValue();
......@@ -152,10 +146,8 @@ public class ProductShopView extends GenericCDIView {
private Boolean gatherBillInfo;
public boolean isGatherBillInfo()
{
if (gatherBillInfo == null)
{
public boolean isGatherBillInfo() {
if (gatherBillInfo == null) {
LanEventProperty re = eventbean.getProperty(LanEventPropertyKey.GATHER_OTHER_BILL_INFO);
if (re != null) {
gatherBillInfo = re.isBooleanValue();
......@@ -181,16 +173,13 @@ public class ProductShopView extends GenericCDIView {
}
}
public void countBoughtChangeListener()
{
public void countBoughtChangeListener() {
ProductShopItem item = boughtItems.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public void countChangeListener()
{
public void countChangeListener() {
ProductShopItem item = shoppingcart.getRowData();
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
......@@ -286,11 +275,9 @@ public class ProductShopView extends GenericCDIView {
updateCartLimits(null);
}
public BigDecimal getTransactionTotal()
{
public BigDecimal getTransactionTotal() {
BigDecimal ret = getCartPrice().subtract(getAccountCredits());
if (BigDecimal.ZERO.compareTo(ret) > 0)
{
if (BigDecimal.ZERO.compareTo(ret) > 0) {
ret = BigDecimal.ZERO;
}
return ret;
......@@ -320,6 +307,7 @@ public class ProductShopView extends GenericCDIView {
}
public String commitBillCart() {
updateAllCartLimits();
logger.debug("Committing billCart");
......@@ -338,8 +326,7 @@ public class ProductShopView extends GenericCDIView {
}
}
billbean.createBill(bill);
if (isCheckAllowStats())
{
if (isCheckAllowStats()) {
userbean.setUserApproval(bill.getUser(), "bill_allow_stats", allowStatistics, "Automagically created");
}
billEditView.setBill(bill);
......@@ -369,10 +356,10 @@ public class ProductShopView extends GenericCDIView {
for (ProductShopItem shopitem : shoppingcart) {
if (shopitem.getCount().compareTo(BigDecimal.ZERO) > 0) {
// retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), shopitem.getOverriddenUnitPrice(), userView.getSelectedUser()).getUser();
// retuser = productBean.createAccountEvent(shopitem.getProduct(), shopitem.getCount(), shopitem.getOverriddenUnitPrice(), userView.getSelectedUser()).getUser();
BigDecimal overriddenPrice = (shopitem.isOverrideUnitPrice()) ? shopitem.getOverriddenUnitPrice() : null;
retuser = productBean.createAccountEvent(shopitem.getProduct(), overriddenPrice, shopitem.getCount(), userView.getSelectedUser()).getUser();
retuser = productBean.createAccountEvent(shopitem.getProduct(), overriddenPrice, shopitem.getCount(), userView.getSelectedUser()).getUser();
}
}
......@@ -488,8 +475,7 @@ public class ProductShopView extends GenericCDIView {
// the product count
int n = 0;
for (ProductShopItem a : shoppingcart) {
if (a.getProduct().equals(product))
{
if (a.getProduct().equals(product)) {
// a.setCount(a.getCount().add(BigDecimal.ONE));
// updateCartLimits(null);
shoppingcart.setRowIndex(n);
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!