productSkuFetchPlans.add(new SpecificFetchMode(ProductSku_.prices.getName()));
productSkuFetchPlans.add(new SpecificFetchMode(ProductSku_.prices.getName() + "." + ProductSkuPrice_.currency.getName()));
productSkuFetchPlans.add(new SpecificFetchMode(ProductSku_.assets.getName()));
FetchPlan productSkuFetchPlan = new FetchPlan(productSkuFetchPlans);
final CartViewBean cartViewBean = new CartViewBean();
cartViewBean.setWithPromoCode(true);
cartViewBean.setWithItemQuantityActions(true);
cartViewBean.setCartDetailsUrl(urlService.generateUrl(FoUrls.CART_DETAILS, requestData));
cartViewBean.setCartAuthUrl(urlService.generateUrl(FoUrls.CART_AUTH, requestData));
cartViewBean.setCartDeliveryAndOrderDetailsUrl(urlService.generateUrl(FoUrls.CART_DELIVERY, requestData));
cartViewBean.setCartOrderPaymentUrl(urlService.generateUrl(FoUrls.CART_ORDER_PAYMENT, requestData));
cartViewBean.setCartOrderConfirmationUrl(urlService.generateUrl(FoUrls.CART_ORDER_CONFIRMATION, requestData));
cartViewBean.setAddNewAddressUrl(urlService.generateUrl(FoUrls.PERSONAL_ADD_ADDRESS, requestData));
if(cart != null){
// ITEMS PART
List<CartItemViewBean> cartItemViewBeans = new ArrayList<CartItemViewBean>();
Set<CartItem> cartItems = cart.getCartItems();
for (Iterator<CartItem> iterator = cartItems.iterator(); iterator.hasNext();) {
final CartItem cartItem = (CartItem) iterator.next();
cartItemViewBeans.add(buildViewBeanCartItem(requestData, cartItem, productSkuFetchPlan));
}
cartViewBean.setCartItems(cartItemViewBeans);
// SUB PART : Shippings
final List<CartDeliveryMethodViewBean> cartDeliveryMethodViewBeans = new ArrayList<CartDeliveryMethodViewBean>();
final Set<DeliveryMethod> deliveryMethods = cart.getDeliveryMethods();
if (deliveryMethods != null) {
for (Iterator<DeliveryMethod> iterator = deliveryMethods.iterator(); iterator.hasNext();) {
final DeliveryMethod deliveryMethod = (DeliveryMethod) iterator.next();
if(deliveryMethod != null){
final CartDeliveryMethodViewBean cartDeliveryMethodViewBean = new CartDeliveryMethodViewBean();
cartDeliveryMethodViewBean.setLabel(deliveryMethod.getName());
cartDeliveryMethodViewBean.setAmountWithCurrencySign(deliveryMethod.getPriceWithStandardCurrencySign(cart.getCurrency().getId()));
Object[] params = { deliveryMethod.getName() };
cartDeliveryMethodViewBean.setLabel(getSpecificMessage(ScopeWebMessage.COMMON, "shoppingcart.amount.deliveryMethods", params, locale));
cartDeliveryMethodViewBeans.add(cartDeliveryMethodViewBean);
}
}
cartViewBean.setCartDeliveryMethods(cartDeliveryMethodViewBeans);
}
// SUB PART : Taxes
// final List<CartTaxViewBean> cartTaxViewBeans = new ArrayList<CartTaxViewBean>();
// final Set<Tax> taxes = cart.getTaxes();
// if (taxes != null) {
// for (Iterator<Tax> iterator = taxes.iterator(); iterator.hasNext();) {
// final Tax tax = (Tax) iterator.next();
// final CartTaxViewBean cartTaxViewBean = new CartTaxViewBean();
// BigDecimal taxesCalc = cartItemsTotal;
// taxesCalc = taxesCalc.multiply(tax.getPercent());
// taxesCalc = taxesCalc.divide(new BigDecimal("100"));
// cartFeesTotal = cartFeesTotal.add(taxesCalc);
// Object[] params = { tax.getName() };
// cartTaxViewBean.setCartTaxTotal(formatter.format(taxesCalc));
// cartTaxViewBean.setCartTaxTotalLabel(getSpecificMessage(ScopeWebMessage.COMMON, "shoppingcart.amount.taxes", params, locale));
// cartTaxViewBeans.add(cartTaxViewBean);
// }
// cartViewBean.setCartTaxes(cartTaxViewBeans);
// }
cartViewBean.setCartItemsTotalWithCurrencySign(cart.getCartItemTotalWithStandardCurrencySign());
cartViewBean.setCartShippingTotalWithCurrencySign(cart.getDeliveryMethodTotalWithStandardCurrencySign());
cartViewBean.setCartFeesTotalWithCurrencySign(cart.getTaxTotalWithStandardCurrencySign());
cartViewBean.setCartTotalWithCurrencySign(cart.getCartTotalWithStandardCurrencySign());
}
return cartViewBean;
}