Java tutorial
/* * [y] hybris Platform * * Copyright (c) 2000-2016 SAP SE * All rights reserved. * * This software is the confidential and proprietary information of SAP * 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 SAP Hybris. */ package de.hybris.platform.dfcheckoutfacade.cart.impl; import de.hybris.platform.commercefacades.order.data.CartData; import de.hybris.platform.commercefacades.order.data.OrderEntryData; import de.hybris.platform.commercefacades.order.impl.DefaultCartFacade; import de.hybris.platform.core.model.order.AbstractOrderEntryModel; import de.hybris.platform.core.model.order.CartModel; import de.hybris.platform.dfcheckoutfacade.cart.DfCartFacade; import de.hybris.platform.order.exceptions.CalculationException; import de.hybris.platform.order.impl.DefaultCalculationService; import de.hybris.platform.servicelayer.model.ModelService; import java.util.ArrayList; import java.util.List; import org.springframework.beans.factory.annotation.Required; /** * */ public class DfDefaultCartFacade extends DefaultCartFacade implements DfCartFacade { private ModelService modelService; private DefaultCalculationService calculationService; @Override public void updateEntiresSelectedStatus(final String code, final String status) { //first, update status final CartModel cart = getCartService().getSessionCart(); final List<AbstractOrderEntryModel> entries = cart.getEntries(); for (final AbstractOrderEntryModel entry : entries) { if (entry.getProduct().getCode().equals(code)) { entry.setChecked(Boolean.parseBoolean(status)); cart.setEntries(entries); getModelService().save(entry); getModelService().refresh(cart); } } //second, update checkout price try { getCalculationService().recalculate(cart); } catch (final CalculationException e) { e.printStackTrace(); } } /** * set cart entry with checked status */ @Override public CartData getSessionCart() { final CartData cartData; if (hasSessionCart()) { final CartModel cart = getCartService().getSessionCart(); cartData = getCartConverter().convert(cart); final List<OrderEntryData> entries = new ArrayList<OrderEntryData>(); for (final AbstractOrderEntryModel modelEntry : cart.getEntries()) { final String code = modelEntry.getProduct().getCode(); for (final OrderEntryData dataEntry : cartData.getEntries()) { if (code.equals(dataEntry.getProduct().getCode())) { dataEntry.setChecked(modelEntry.isChecked()); entries.add(dataEntry); } } } cartData.setEntries(entries); } else { cartData = createEmptyCart(); } return cartData; } /** * @return the modelService */ public ModelService getModelService() { return modelService; } /** * @param modelService * the modelService to set */ @Required public void setModelService(final ModelService modelService) { this.modelService = modelService; } /** * @return the calculationService */ public DefaultCalculationService getCalculationService() { return calculationService; } /** * @param calculationService * the calculationService to set */ @Required public void setCalculationService(final DefaultCalculationService calculationService) { this.calculationService = calculationService; } }