this.basketBean = (BasketSessionBeanRemote) context.lookup("ejb/stateless-basket"); //NOI18N
}
+ @Override
+ public Float calculateItemPrice () {
+ // Is the current item/amount set?
+ if (this.getCurrentItem() == null) {
+ // Current item is null
+ throw new NullPointerException("currentItem is null");
+ } else if (this.getCurrentItem().getProduct() == null) {
+ // Product is null
+ throw new NullPointerException("currentItem.product is null");
+ } else if (this.getCurrentItem().getAmount() == null) {
+ // Amount is null
+ throw new NullPointerException("currentItem.amount is null");
+ }
+
+ // Caculate item's price
+ Float totalPrice = (this.getCurrentItem().getProduct().getPrice() * this.getCurrentItem().getAmount());
+
+ // Return it
+ return totalPrice;
+ }
+
@Override
public Long getAmount () {
return this.amount;
* @author Roland Haeder<roland@mxchange.org>
*/
public interface BasketWebController extends Serializable {
+
/**
* Checks whether the basket is empty
*
public boolean isEmpty ();
/**
- * Checks whether the basket has items in it. This method is wrapper to isEmpty()
+ * Checks whether the basket has items in it. This method is wrapper to
+ * isEmpty()
*
* @return Whether the basket is empty
*/
public boolean isProductAdded (final Product product);
/**
- * Adds given product instance to basket by adding amount from form data to it.
+ * Adds given product instance to basket by adding amount from form data to
+ * it.
*
* @param product Product instance to add
* @return Redirect target or null
* @param currentItem Current item
*/
public void setCurrentItem (final AddableBasketItem currentItem);
+
+ /**
+ * Calculates total price (no tax added) of current item. If no current item
+ * is set and no amount, a NPE is thrown.
+ *
+ * @return Current item's total price
+ */
+ public Float calculateItemPrice ();
}