Commit cc094030 by Tuomas Riihimäki

Enforce product limits in user shop

1 parent f01b1260
...@@ -46,7 +46,7 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -46,7 +46,7 @@ public class ProductShopItemHelper extends GenericCDIView {
public void updateProductShopItemCount(ProductShopItem item) { public void updateProductShopItemCount(ProductShopItem item) {
// Discounts or overridden price, you cannot get both // Discounts or overridden price, you cannot get both
if(item.isOverrideUnitPrice()) { if (item.isOverrideUnitPrice()) {
item.setInternalPrice(item.getOverriddenUnitPrice().multiply(item.getCount())); item.setInternalPrice(item.getOverriddenUnitPrice().multiply(item.getCount()));
} else { } else {
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(item.getCount())); item.setInternalPrice(item.getProduct().getPrice().abs().multiply(item.getCount()));
...@@ -63,7 +63,6 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -63,7 +63,6 @@ public class ProductShopItemHelper extends GenericCDIView {
} }
} }
} }
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) { public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
...@@ -78,10 +77,13 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -78,10 +77,13 @@ public class ProductShopItemHelper extends GenericCDIView {
} }
public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) { public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) {
BigDecimal productsLeft = null;
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0) if (limitValue != null) {
{ productsLeft = limitValue.subtract(item.getCount());
this.setProductShopItemCount(item, item.getCount().add(limitValue)); if (productsLeft.compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item, limitValue);
if (item.getCount().compareTo(BigDecimal.ZERO) < 0) { if (item.getCount().compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item, BigDecimal.ZERO); this.setProductShopItemCount(item, BigDecimal.ZERO);
...@@ -89,8 +91,8 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -89,8 +91,8 @@ public class ProductShopItemHelper extends GenericCDIView {
item.setLimit(BigDecimal.ZERO); item.setLimit(BigDecimal.ZERO);
return true; return true;
} }
item.setLimit(limitValue); }
item.setLimit(productsLeft);
return false; return false;
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!