Commit cc094030 by Tuomas Riihimäki

Enforce product limits in user shop

1 parent f01b1260
......@@ -43,28 +43,27 @@ public class ProductShopItemHelper extends GenericCDIView {
@EJB
private DiscountBeanLocal discountBean;
public void updateProductShopItemCount(ProductShopItem item) {
public void updateProductShopItemCount(ProductShopItem item) {
// Discounts or overridden price, you cannot get both
if(item.isOverrideUnitPrice()) {
item.setInternalPrice(item.getOverriddenUnitPrice().multiply(item.getCount()));
} else {
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(item.getCount()));
// Discounts or overridden price, you cannot get both
if (item.isOverrideUnitPrice()) {
item.setInternalPrice(item.getOverriddenUnitPrice().multiply(item.getCount()));
} else {
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(item.getCount()));
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(), item.getCount(), Calendar.getInstance(), item.getUser()));
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(), item.getCount(), Calendar.getInstance(), item.getUser()));
item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
for (Discount d : item.getDiscounts())
{
BigDecimal newprice = item.getPrice().multiply(d.getPercentage());
item.getInternalDiscountValues().put(d.getId(), item.getPrice().subtract(newprice));
item.setInternalPrice(newprice);
}
}
item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
for (Discount d : item.getDiscounts())
{
BigDecimal newprice = item.getPrice().multiply(d.getPercentage());
item.getInternalDiscountValues().put(d.getId(), item.getPrice().subtract(newprice));
item.setInternalPrice(newprice);
}
}
}
}
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
......@@ -73,24 +72,27 @@ public class ProductShopItemHelper extends GenericCDIView {
count = BigDecimal.ZERO;
}
item.setCount(count);
updateProductShopItemCount(item);
updateProductShopItemCount(item);
}
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);
if (item.getCount().compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item, BigDecimal.ZERO);
}
item.setLimit(BigDecimal.ZERO);
return true;
}
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!