]> git.mxchange.org Git - pizzaservice-war.git/commitdiff
Continued:
authorRoland Haeder <roland@mxchange.org>
Mon, 14 Sep 2015 09:29:26 +0000 (11:29 +0200)
committerRoland Haeder <roland@mxchange.org>
Mon, 14 Sep 2015 09:29:26 +0000 (11:29 +0200)
- added total price to basket and index
- now item prices are right-origiented
- added method calculateTotalPrice() to basket controller
- added method getItemAmount() to basket controller
- now amount and submit button/link to basket are left-floated, prices are right-floated
Signed-off-by:Roland Häder <roland@mxchange.org>

src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebBean.java
src/java/org/mxchange/pizzaapplication/beans/basket/BasketWebController.java
web/basket.xhtml
web/index.xhtml
web/resources/css/cssLayout.css

index 9adcfea5d38435f7557e7fda50c141b179036d19..2fbd7726f96dc5347ea8042a55b81ea113941591 100644 (file)
@@ -150,6 +150,24 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                return totalPrice;
        }
 
+       @Override
+       public Float calculateTotalPrice () {
+               // Init total price
+               Float totalPrice = 0.0f;
+
+               // Iterate over all items
+               for (final AddableBasketItem item : this.allItems()) {
+                       // Is the item a product?
+                       if (item.isProductType()) {
+                               // Calculate single price and add it
+                               totalPrice += this.calculateItemPrice(item);
+                       }
+               }
+
+               // Return final sum
+               return totalPrice;
+       }
+
        @Override
        public Long getAmount () {
                return this.amount;
@@ -170,6 +188,25 @@ public class BasketWebBean extends BaseFrameworkBean implements BasketWebControl
                this.currentItem = currentItem;
        }
 
+       @Override
+       public Long getItemAmount (final Product product) {
+               // Initial value is zero
+               Long itemAmount = 0L;
+
+               // Iterate over all
+               for (final AddableBasketItem item : this.allItems()) {
+                       // Is this product instance and same?
+                       if ((item.isProductType()) && (item.getProduct().equals(product))) {
+                               // Found it
+                               itemAmount = item.getAmount();
+                               break;
+                       }
+               }
+
+               // Return it
+               return itemAmount;
+       }
+
        @Override
        public AddableBasketItem getLast () {
                // Deligate to basket instance
index 2f6c212e05f3b54dce92f1bbceec76b91472577a..8d28a9463f7fecc7d1e415ab716672ac7e42bfa3 100644 (file)
@@ -104,6 +104,13 @@ public interface BasketWebController extends Serializable {
         */
        public Float calculateItemPrice (final AddableBasketItem item);
 
+       /**
+        * Calculates total sum (no tax added) for all items
+        *
+        * @return Total price of all items
+        */
+       public Float calculateTotalPrice ();
+
        /**
         * Getter for last entry
         *
@@ -124,4 +131,14 @@ public interface BasketWebController extends Serializable {
         * @return A list of all added items
         */
        public List<AddableBasketItem> allItems ();
+
+       /**
+        * Some getter for item amount of given product. This method requires a full
+        * iteration over all items in the basket to look for proper product
+        * instance.
+        * 
+        * @param product Product instance
+        * @return Item amount of given product
+        */
+       public Long getItemAmount (final Product product);
 }
index ffe36a049dbc73f151999612fda0d012a5734ba6..845e9be6f3f39f8287089bd936f0cae2b3ee8658 100644 (file)
                                <h:column>
                                        <f:facet name="header">Einzelpreis:</f:facet>
 
-                                       <ui:fragment rendered="#{item.isProductType()}">
-                                               <h:outputText class="price" value="#{item.product.price}">
-                                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
-                                               </h:outputText>
-                                       </ui:fragment>
+                                       <div class="item_price">
+                                               <ui:fragment rendered="#{item.isProductType()}">
+                                                       <h:outputText class="price" value="#{item.product.price}">
+                                                               <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                                                       </h:outputText>
+                                               </ui:fragment>
+                                       </div>
                                </h:column>
 
                                <h:column>
                                <h:column>
                                        <f:facet name="header">Zwischensumme:</f:facet>
 
-                                       <h:outputText id="item_price" value="#{basketController.calculateItemPrice(item)}" rendered="#{item.isProductType()}">
-                                               <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
-                                       </h:outputText>
+                                       <div class="item_total_price">
+                                               <h:outputText class="price" id="item_price" value="#{basketController.calculateItemPrice(item)}" rendered="#{item.isProductType()}">
+                                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                                               </h:outputText>
+                                       </div>
                                </h:column>
                        </h:dataTable>
 
+                       <div class="totals_container">
+                               Gesamtsumme:
+                               <h:outputText class="price" id="total_sum" value="#{basketController.calculateTotalPrice()}">
+                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                               </h:outputText>
+                       </div>
+
                        <h:outputText class="empty_basket" value="Es befinden sich derzeit keine Artikel im Warenkorb." rendered="#{basketController.isEmpty()}" />
                </ui:define>
 
index 4c3d08db60c4cff2effe5f040d04248b8f5c1528..f682c0ea2db54c3f116d956176d4bbe104321e94 100644 (file)
                                                </div>
 
                                                <div class="item_content">
-                                                       <div class="item_actions">
-                                                               <ui:fragment rendered="#{!basketController.isProductAdded(product)}">
-                                                                       <h:form acceptcharset="utf-8" id="add_item">
-                                                                               <h:commandButton class="submit" id="add" value="Hinzufügen" action="#{basketController.addItem(product)}" title="#{msg.BUTTON_TITLE_ADD_ITEM_TO_BASKET}" />
-
-                                                                               <h:inputText class="input" id="amount" size="3" maxlength="20" value="#{basketController.amount}" title="#{msg.INPUT_TITLE_ENTER_ITEM_AMOUNT}">
-                                                                                       <!--
-                                                                                       If the customer wants to order more, he need to call in.
-                                                                                       //-->
-                                                                                       <f:validator for="amount" validatorId="ItemAmountValidator" />
-                                                                               </h:inputText>
-                                                                       </h:form>
-                                                               </ui:fragment>
-
-                                                               <ui:fragment rendered="#{basketController.isProductAdded(product)}">
-                                                                       <div class="item_amount">
-                                                                               #{basketController.amount}
-                                                                       </div>
-
-                                                                       <div class="item_basket_link">
-                                                                               <h:link outcome="basket" title="Zum Warenkorb" value="Im Warenkorb ändern" />
-                                                                       </div>
-
-                                                                       <div class="clear"></div>
-                                                               </ui:fragment>
-                                                       </div>
+                                                       <div class="table_left">
+                                                               <div class="item_actions">
+                                                                       <ui:fragment rendered="#{!basketController.isProductAdded(product)}">
+                                                                               <h:form acceptcharset="utf-8" id="add_item">
+                                                                                       <h:commandButton class="submit" id="add" value="Hinzufügen" action="#{basketController.addItem(product)}" title="#{msg.BUTTON_TITLE_ADD_ITEM_TO_BASKET}" />
+
+                                                                                       <h:inputText class="input" id="amount" size="3" maxlength="20" value="#{basketController.amount}" title="#{msg.INPUT_TITLE_ENTER_ITEM_AMOUNT}">
+                                                                                               <!--
+                                                                                               If the customer wants to order more, he need to call in.
+                                                                                               //-->
+                                                                                               <f:validator for="amount" validatorId="ItemAmountValidator" />
+                                                                                       </h:inputText>
+                                                                               </h:form>
+                                                                       </ui:fragment>
+
+                                                                       <ui:fragment rendered="#{basketController.isProductAdded(product)}">
+                                                                               <div class="item_amount">
+                                                                                       Anzahl:
+                                                                                       #{basketController.getItemAmount(product)}
+                                                                               </div>
+
+                                                                               <div class="item_basket_link">
+                                                                                       <h:link outcome="basket" title="Zum Warenkorb" value="Im Warenkorb ändern" />
+                                                                               </div>
 
-                                                       <div class="item_price">
-                                                               Einzelpreis:
-                                                               <h:outputText class="price" value="#{product.price}">
-                                                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
-                                                               </h:outputText>
+                                                                               <div class="clear"></div>
+                                                                       </ui:fragment>
+                                                               </div>
                                                        </div>
 
-                                                       <div class="item_total_price">
-                                                               Zwischensumme:
-                                                               <h:outputText class="price" value="Nicht bestellt." rendered="#{!basketController.isProductAdded(product)}" />
-                                                               <h:outputText class="price" value="#{basketController.calculateCurrentItemPrice()}" rendered="#{basketController.isProductAdded(product)}">
-                                                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
-                                                               </h:outputText>
+                                                       <div class="table_right">
+                                                               <div class="item_price">
+                                                                       Einzelpreis:
+                                                                       <h:outputText class="price" value="#{product.price}">
+                                                                               <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                                                                       </h:outputText>
+                                                               </div>
+
+                                                               <div class="item_total_price">
+                                                                       Zwischensumme:
+                                                                       <h:outputText class="price" value="Nicht bestellt." rendered="#{!basketController.isProductAdded(product)}" />
+                                                                       <h:outputText class="price" value="#{basketController.calculateCurrentItemPrice()}" rendered="#{basketController.isProductAdded(product)}">
+                                                                               <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                                                                       </h:outputText>
+                                                               </div>
                                                        </div>
+
+                                                       <div class="clear"></div>
                                                </div>
                                        </div>
                                </h:column>
                        </h:dataTable>
+
+                       <div id="totals_container">
+                               Gesamtsumme:
+                               <h:outputText class="price" id="total_sum" value="#{basketController.calculateTotalPrice()}">
+                                       <f:convertNumber type="currency" minFractionDigits="2" maxFractionDigits="2" locale="de_DE" />
+                               </h:outputText>
+                       </div>
                </ui:define>
 
                <ui:define name="footer">
index ed37fb5ab647a5b78fe84d9892c3224284279ab9..321cf6466c916c6e612600b6250354014ac107a3 100644 (file)
@@ -154,6 +154,6 @@ ul.footer_nav li.footer_copyright {
        width: 100px;
 }
 
-.price {
+.item_price, .item_total_price {
        text-align: right;
 }