Java tutorial
/* * [y] hybris Platform * * Copyright (c) 2000-2013 hybris AG * All rights reserved. * * This software is the confidential and proprietary information of hybris * ("Confidential Information"). You shall not disclose such Confidential * Information and shall use it only in accordance with the terms of the * license agreement you entered into with hybris. * * */ package com.epam.cme.storefront.controllers.misc; import de.hybris.platform.acceleratorcms.model.components.MiniCartComponentModel; import de.hybris.platform.cms2.exceptions.CMSItemNotFoundException; import de.hybris.platform.cms2.servicelayer.services.CMSComponentService; import de.hybris.platform.commercefacades.order.CartFacade; import de.hybris.platform.commercefacades.order.data.CartData; import de.hybris.platform.commercefacades.product.data.PriceData; import com.epam.cme.storefront.controllers.AbstractController; import com.epam.cme.storefront.controllers.ControllerConstants; import java.util.Collections; import java.util.List; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * Controller for Telco MiniCart functionality which is not specific to a page. */ @Controller public class TelcoMiniCartController extends AbstractController { protected static final Logger LOG = Logger.getLogger(TelcoMiniCartController.class); /** * We use this suffix pattern because of an issue with Spring 3.1 where a Uri value is * incorrectly extracted if it contains on or more '.' characters. Please see * https://jira.springsource.org/browse/SPR-6164 for a discussion on the issue and future * resolution. */ private static final String TOTAL_DISPLAY_PATH_VARIABLE_PATTERN = "{totalDisplay:.*}"; private static final String COMPONENT_UID_PATH_VARIABLE_PATTERN = "{componentUid:.*}"; @Resource(name = "cartFacade") private CartFacade cartFacade; @Resource(name = "cmsComponentService") private CMSComponentService cmsComponentService; @RequestMapping(value = "/cart/miniCart/" + TOTAL_DISPLAY_PATH_VARIABLE_PATTERN, method = RequestMethod.GET) public String getMiniCart(@PathVariable final String totalDisplay, final Model model) { final CartData cartData = cartFacade.getMiniCart(); model.addAttribute("totalPrice", cartData.getTotalPrice()); model.addAttribute("subTotal", cartData.getSubTotal()); if (cartData.getDeliveryCost() != null) { final PriceData withoutDelivery = cartData.getDeliveryCost(); withoutDelivery .setValue(cartData.getTotalPrice().getValue().subtract(cartData.getDeliveryCost().getValue())); model.addAttribute("totalNoDelivery", withoutDelivery); } else { model.addAttribute("totalNoDelivery", cartData.getTotalPrice()); } model.addAttribute("totalItems", cartData.getTotalUnitCount()); model.addAttribute("totalDisplay", totalDisplay); return ControllerConstants.Views.Fragments.Cart.MiniCartPanel; } @RequestMapping(value = "/cart/rollover/" + COMPONENT_UID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET) public String rolloverMiniCartPopup(@PathVariable final String componentUid, final Model model) throws CMSItemNotFoundException { final CartData cartData = cartFacade.getMiniCart(); model.addAttribute("cartData", cartData); final Integer allEntriesCount = cartData.getAllEntriesCount(); final MiniCartComponentModel component = (MiniCartComponentModel) cmsComponentService .getSimpleCMSComponent(componentUid); final List entries = cartData.getEntries(); if (entries != null) { Collections.reverse(entries); model.addAttribute("entries", entries); model.addAttribute("numberItemsInCart", allEntriesCount == null ? Integer.valueOf(entries.size()) : allEntriesCount); if (entries.size() < component.getShownProductCount()) { model.addAttribute("numberShowing", Integer.valueOf(entries.size())); } else { model.addAttribute("numberShowing", Integer.valueOf(component.getShownProductCount())); } } model.addAttribute("lightboxBannerComponent", component.getLightboxBannerComponent()); return ControllerConstants.Views.Fragments.Cart.CartPopup; } }