Skip to content

Commit

Permalink
CheckOutController update
Browse files Browse the repository at this point in the history
  • Loading branch information
kaszabimre committed May 8, 2016
1 parent 39390b4 commit d273319
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import hu.unideb.inf.Unizon.facade.ProductFacade;
import hu.unideb.inf.Unizon.model.Order;
import hu.unideb.inf.Unizon.model.ProdToOrder;
import hu.unideb.inf.Unizon.model.ProdToOrderPK;
import hu.unideb.inf.Unizon.model.Product;

@ManagedBean
Expand Down Expand Up @@ -91,20 +92,27 @@ public void finalizeShopping() {
for (Map.Entry<Product, Integer> entry : cartItemController.getProducts().entrySet()) {
Product product = entry.getKey();

// ProdToOrderPK ???
ProdToOrder newProdToOrder = new ProdToOrder();
newProdToOrder.setAmount(entry.getValue());
newProdToOrder.setOrder(newOrder);
newProdToOrder.setProduct(product);

prodToOrderFacade.create(newProdToOrder); // New rows added to DB
// ProdToOrderPK ???

int newAmount = product.getAmount() - entry.getValue();
// TODO Check newAmount first (individually)
product.setAmount(newAmount);
productFacade.edit(product);
searchController.modifyProduct(product);
if (newAmount >= 0) {
ProdToOrderPK newProdToOrderPk = new ProdToOrderPK();
newProdToOrderPk.setOrderId(newOrder.getOrderId());
newProdToOrderPk.setProductId(product.getProductId());
ProdToOrder newProdToOrder = new ProdToOrder();
newProdToOrder.setId(newProdToOrderPk);
newProdToOrder.setAmount(entry.getValue());
newProdToOrder.setOrder(newOrder);
newProdToOrder.setProduct(product);

prodToOrderFacade.create(newProdToOrder);

product.setAmount(newAmount);
productFacade.edit(product);
searchController.modifyProduct(product);

} else {
addErrorMessage(product.getTitle() + "is out of stock");
}
}

log.info("Products' amount successfully updated.");
Expand Down
2 changes: 1 addition & 1 deletion program/Unizon/src/main/webapp/cart.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
<p:panelGrid>
<p:commandButton class="button cart" value="Order"
oncomplete="PF('checkOutFromCartDialogVar').hide()"
actionListener="#" update=":messages">
actionListener="#{checkOutController.finalizeShopping()}" update=":messages">
</p:commandButton>
<!-- {checkOutController.finalizeShopping()} -->
</p:panelGrid>
Expand Down

0 comments on commit d273319

Please sign in to comment.