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