Commit 48abfe98 by Tuomas Riihimäki

Add possibility to enter product count as a number in user shop.

1 parent fe44ba6d
......@@ -40,13 +40,13 @@
<h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" />
</h:commandButton>
<h:outputText id="cartcount" escape="false" value="&nbsp;&nbsp;#{cart.count}&nbsp;&nbsp;">
<p:inputText size="2" id="cartcount" escape="false" value="#{cart.count}">
<f:ajax render="@form" listener="#{productShopView.countChangeListener}" />
<f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
</h:outputText>
</p:inputText>
<h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" />
</h:commandButton>
</p:column>
<p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header">
......@@ -57,7 +57,7 @@
</h:outputText>
</p:column>
<p:column>
<h:dataTable border="0" var="disc" value="#{cart.discounts}">
<h:dataTable styleClass="noborderTable" border="0" var="disc" value="#{cart.discounts}">
<p:column>
<h:outputText value="#{disc.shortdesc}" />
</p:column>
......
......@@ -9,6 +9,7 @@ import java.util.Map;
import javax.ejb.EJB;
import javax.enterprise.context.ConversationScoped;
import javax.faces.event.AjaxBehaviorEvent;
import javax.faces.model.ListDataModel;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView {
@EJB
private transient EventBeanLocal eventbean;
public void cashChanged()
{
payInstant = false;
......@@ -164,6 +163,14 @@ public class ProductShopView extends GenericCDIView {
}
}
public void countChangeListener(AjaxBehaviorEvent e)
{
ProductShopItem item = shoppingcart.getRowData();
logger.info("Count change from event {}, src {}, from item {}", e, e.getSource(), item.getCount());
psiHelper.setProductShopItemCount(item, item.getCount());
updateCartLimits(item);
}
public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData();
......@@ -224,7 +231,7 @@ public class ProductShopView extends GenericCDIView {
hasLimits = true;
}
psiHelper.updateProductShopItemLimit(n,l);
psiHelper.updateProductShopItemLimit(n, l);
}
}
......@@ -429,7 +436,7 @@ public class ProductShopView extends GenericCDIView {
ReaderEvent event = readerView.getReaderEvent();
if(event == null) {
if (event == null) {
return null;
}
......
......@@ -17,29 +17,25 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
@ConversationScoped
public class ProductShopItemHelper extends GenericCDIView {
/**
*
*/
private static final long serialVersionUID = 1L;
@EJB
private DiscountBeanLocal discountBean;
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
if (count == null || count.compareTo(BigDecimal.ZERO) < 0)
{
count = BigDecimal.ZERO;
}
item.setInternalCount(count);
item.setCount(count);
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(count));
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(),count, Calendar.getInstance(), item.getUser()) );
item.setInternalDiscounts(discountBean.getActiveDiscountsByProduct(item.getProduct(), count, Calendar.getInstance(), item.getUser()));
item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
......@@ -51,7 +47,6 @@ public class ProductShopItemHelper extends GenericCDIView {
}
}
public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) {
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0)
......@@ -59,7 +54,7 @@ public class ProductShopItemHelper extends GenericCDIView {
this.setProductShopItemCount(item, item.getCount().add(limitValue));
if (item.getCount().compareTo(BigDecimal.ZERO) < 0) {
this.setProductShopItemCount(item,BigDecimal.ZERO);
this.setProductShopItemCount(item, BigDecimal.ZERO);
}
item.setLimit(BigDecimal.ZERO);
return true;
......@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
return false;
}
}
......@@ -47,7 +47,7 @@ public class ProductShopItem {
this.user = user;
this.product = prod;
id = this.product.getId();
setInternalCount(BigDecimal.ZERO);
setCount(BigDecimal.ZERO);
setInternalPrice(BigDecimal.ZERO);
}
......@@ -85,9 +85,14 @@ public class ProductShopItem {
* DO NOT USE THIS.
*
* Use ProductShopIteHelper.setProductShopItemCount instead.
*
* p.s. This still needs to exist because we want to set count from jsf, but
* this value needs to be updated with
* ProductShopIteHelper.setProductShopItemCount
*
* @param count
*/
public void setInternalCount(BigDecimal count) {
public void setCount(BigDecimal count) {
this.count = count;
}
......@@ -109,7 +114,6 @@ public class ProductShopItem {
return discountValues.get(discId);
}
public BigDecimal getPrice()
{
return price;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!