Skip to content
Permalink
Browse files

Add promotion rows in CheckoutWindow

  • Loading branch information
amahdy committed Dec 24, 2015
1 parent 0d0e977 commit aaedac8b6830a14cfede1fb86a27f12cba0e9d49
@@ -175,8 +175,7 @@ public void onClose(ConfirmDialog dialog) {

private void checkout() {

CheckoutWindow window = new CheckoutWindow(getShoppingCart()
.getShoppingCartItemList());
CheckoutWindow window = new CheckoutWindow(getShoppingCart());
window.addCloseListener(new CloseListener() {

/**
@@ -1,15 +1,13 @@
package com.redhat.coolstore.web.ui.components;

import java.util.List;

import com.redhat.coolstore.model.ShoppingCart;
import com.redhat.coolstore.model.ShoppingCartItem;
import com.redhat.coolstore.web.ui.converter.StringPropertyValueGenerator;
import com.redhat.coolstore.web.ui.util.Formatter;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.GeneratedPropertyContainer;
import com.vaadin.ui.Grid;
import com.vaadin.ui.Grid.FooterCell;
import com.vaadin.ui.Grid.FooterRow;
import com.vaadin.ui.UI;
import com.vaadin.ui.Window;
@@ -22,24 +20,14 @@
private static final long serialVersionUID = -8504668339755922310L;

private static final String PROPERTY_PRODUCT_NAME = "productName";
private static final String PROPERTY_PRODUCT_PRICE = "productPrice";
private static final String PROPERTY_UNIT_PRICE = "unitPrice";
private static final String PROPERTY_QUANTITY = "quantity";
private static final String PROPERTY_PRODUCT_TOTAL = "productTotal";

private static Double totalPrice;
private FooterCell gridFooterTotal;

private void updateGridFooterTotal(Double price) {
totalPrice += price;
gridFooterTotal.setText(Formatter.formatPrice(totalPrice));
}

public CheckoutWindow(List<ShoppingCartItem> shoppingCartItems) {

totalPrice = 0D;
public CheckoutWindow(ShoppingCart shoppingCart) {

BeanItemContainer<ShoppingCartItem> container = new BeanItemContainer<ShoppingCartItem>(
ShoppingCartItem.class, shoppingCartItems);
ShoppingCartItem.class, shoppingCart.getShoppingCartItemList());
GeneratedPropertyContainer gContainer = new GeneratedPropertyContainer(
container);
gContainer.addGeneratedProperty(PROPERTY_PRODUCT_NAME,
@@ -57,7 +45,7 @@ public String getValue(Item item, Object itemId,
.getName();
}
});
gContainer.addGeneratedProperty(PROPERTY_PRODUCT_PRICE,
gContainer.addGeneratedProperty(PROPERTY_UNIT_PRICE,
new StringPropertyValueGenerator() {

/**
@@ -85,10 +73,8 @@ public String getValue(Item item, Object itemId,
public String getValue(Item item, Object itemId,
Object propertyId) {
ShoppingCartItem scItem = (ShoppingCartItem) itemId;
Double currentPrice = scItem.getProduct().getPrice()
* scItem.getQuantity();
updateGridFooterTotal(currentPrice);
return Formatter.formatPrice(currentPrice);
return Formatter.formatPrice(scItem.getProduct()
.getPrice() * scItem.getQuantity());
}
});

@@ -97,17 +83,33 @@ public String getValue(Item item, Object itemId,

grid.removeAllColumns();
grid.addColumn(PROPERTY_PRODUCT_NAME);
grid.addColumn(PROPERTY_PRODUCT_PRICE);
grid.addColumn(PROPERTY_UNIT_PRICE);
grid.addColumn(PROPERTY_QUANTITY);
grid.getColumn(PROPERTY_QUANTITY).setSortable(false);
grid.addColumn(PROPERTY_PRODUCT_TOTAL);

FooterRow gridFooter = grid.appendFooterRow();

gridFooter.join(PROPERTY_PRODUCT_NAME, PROPERTY_PRODUCT_PRICE,
gridFooter.join(PROPERTY_PRODUCT_NAME, PROPERTY_UNIT_PRICE,
PROPERTY_QUANTITY).setText(
"Shipping Total: "
+ Formatter.formatPrice(shoppingCart
.getShippingPromoSavings()));
gridFooter.getCell(PROPERTY_PRODUCT_TOTAL).setText(
Formatter.formatPrice(shoppingCart.getShippingTotal()));

gridFooter = grid.appendFooterRow();
gridFooter.join(PROPERTY_PRODUCT_NAME, PROPERTY_UNIT_PRICE,
PROPERTY_QUANTITY).setText(
"Promo Total: "
+ Formatter.formatPrice(shoppingCart
.getCartItemPromoSavings()));
gridFooter.getCell(PROPERTY_PRODUCT_TOTAL).setText(
Formatter.formatPrice(shoppingCart.getCartItemTotal()));

gridFooter = grid.appendFooterRow();
gridFooter.join(PROPERTY_PRODUCT_NAME, PROPERTY_UNIT_PRICE,
PROPERTY_QUANTITY).setText("Order Total:");

gridFooterTotal = gridFooter.getCell(PROPERTY_PRODUCT_TOTAL);
gridFooter.getCell(PROPERTY_PRODUCT_TOTAL).setText(
Formatter.formatPrice(shoppingCart.getCartTotal()));

setCaption("<h2>Thank you for your order!</h2>");
setCaptionAsHtml(true);

0 comments on commit aaedac8

Please sign in to comment.
You can’t perform that action at this time.