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 @@ ...@@ -40,13 +40,13 @@
<h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}"> <h:commandButton action="#{productShopView.addMinusOne}" value="#{i18n['productshop.minusOne']}">
<f:ajax render="@form" /> <f:ajax render="@form" />
</h:commandButton> </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" /> <f:convertNumber maxIntegerDigits="2" minFractionDigits="0" />
</h:outputText> </p:inputText>
<h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}"> <h:commandButton action="#{productShopView.addOne}" value="#{i18n['productshop.plusOne']}">
<f:ajax render="@form" /> <f:ajax render="@form" />
</h:commandButton> </h:commandButton>
</p:column> </p:column>
<p:column rendered="#{productShopView.hasLimits}"> <p:column rendered="#{productShopView.hasLimits}">
<f:facet name="header"> <f:facet name="header">
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
</h:outputText> </h:outputText>
</p:column> </p:column>
<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> <p:column>
<h:outputText value="#{disc.shortdesc}" /> <h:outputText value="#{disc.shortdesc}" />
</p:column> </p:column>
......
...@@ -9,6 +9,7 @@ import java.util.Map; ...@@ -9,6 +9,7 @@ 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.AjaxBehaviorEvent;
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;
...@@ -54,8 +55,6 @@ public class ProductShopView extends GenericCDIView { ...@@ -54,8 +55,6 @@ 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;
...@@ -164,6 +163,14 @@ public class ProductShopView extends GenericCDIView { ...@@ -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) { public String add(Integer count) {
ProductShopItem item = shoppingcart.getRowData(); ProductShopItem item = shoppingcart.getRowData();
...@@ -224,7 +231,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -224,7 +231,7 @@ public class ProductShopView extends GenericCDIView {
hasLimits = true; hasLimits = true;
} }
psiHelper.updateProductShopItemLimit(n,l); psiHelper.updateProductShopItemLimit(n, l);
} }
} }
...@@ -429,7 +436,7 @@ public class ProductShopView extends GenericCDIView { ...@@ -429,7 +436,7 @@ public class ProductShopView extends GenericCDIView {
ReaderEvent event = readerView.getReaderEvent(); ReaderEvent event = readerView.getReaderEvent();
if(event == null) { if (event == null) {
return null; return null;
} }
......
...@@ -17,29 +17,25 @@ import fi.codecrew.moya.web.helpers.ProductShopItem; ...@@ -17,29 +17,25 @@ import fi.codecrew.moya.web.helpers.ProductShopItem;
@ConversationScoped @ConversationScoped
public class ProductShopItemHelper extends GenericCDIView { public class ProductShopItemHelper extends GenericCDIView {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@EJB @EJB
private DiscountBeanLocal discountBean; private DiscountBeanLocal discountBean;
public void setProductShopItemCount(ProductShopItem item, BigDecimal count) { public void setProductShopItemCount(ProductShopItem item, BigDecimal count) {
if (count == null || count.compareTo(BigDecimal.ZERO) < 0) if (count == null || count.compareTo(BigDecimal.ZERO) < 0)
{ {
count = BigDecimal.ZERO; count = BigDecimal.ZERO;
} }
item.setInternalCount(count); item.setCount(count);
item.setInternalPrice(item.getProduct().getPrice().abs().multiply(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>()); item.setInternalDiscountValues(new HashMap<Integer, BigDecimal>());
...@@ -51,7 +47,6 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -51,7 +47,6 @@ public class ProductShopItemHelper extends GenericCDIView {
} }
} }
public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) { public boolean updateProductShopItemLimit(ProductShopItem item, BigDecimal limitValue) {
if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0) if (limitValue != null && limitValue.compareTo(BigDecimal.ZERO) < 0)
...@@ -59,7 +54,7 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -59,7 +54,7 @@ public class ProductShopItemHelper extends GenericCDIView {
this.setProductShopItemCount(item, item.getCount().add(limitValue)); this.setProductShopItemCount(item, item.getCount().add(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);
} }
item.setLimit(BigDecimal.ZERO); item.setLimit(BigDecimal.ZERO);
return true; return true;
...@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView { ...@@ -68,5 +63,4 @@ public class ProductShopItemHelper extends GenericCDIView {
return false; return false;
} }
} }
...@@ -47,7 +47,7 @@ public class ProductShopItem { ...@@ -47,7 +47,7 @@ public class ProductShopItem {
this.user = user; this.user = user;
this.product = prod; this.product = prod;
id = this.product.getId(); id = this.product.getId();
setInternalCount(BigDecimal.ZERO); setCount(BigDecimal.ZERO);
setInternalPrice(BigDecimal.ZERO); setInternalPrice(BigDecimal.ZERO);
} }
...@@ -85,9 +85,14 @@ public class ProductShopItem { ...@@ -85,9 +85,14 @@ public class ProductShopItem {
* DO NOT USE THIS. * DO NOT USE THIS.
* *
* Use ProductShopIteHelper.setProductShopItemCount instead. * 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 * @param count
*/ */
public void setInternalCount(BigDecimal count) { public void setCount(BigDecimal count) {
this.count = count; this.count = count;
} }
...@@ -109,7 +114,6 @@ public class ProductShopItem { ...@@ -109,7 +114,6 @@ public class ProductShopItem {
return discountValues.get(discId); return discountValues.get(discId);
} }
public BigDecimal getPrice() public BigDecimal getPrice()
{ {
return price; return price;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!