Commit cc094030 by Tuomas Riihimäki

Enforce product limits in user shop

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