Customizing the Bundle Guided Selling Pages
This document provides an example for how to customize the Bundle Guided Selling pages.
Pages, Tags, and Templates
Variables
The following lists all the variables with its corresponding description and value.
| Variable Name | Description | Value |
|---|---|---|
|
<${addOnName}> |
The name of the AddOn |
b2ctelcostorefront |
|
<${addOnPageRoot}> |
The location where custom page fragments must go |
b2ctelcostorefront/acceleratoraddon/web/webroot/WEB-INF |
|
<${targetRoot}> |
The location where source files should be copied |
yacceleratorstorefront/web/webroot/WEB-INF |
Files to Copy
The following lists the files needed to be copied into a target path. The table also shows where the file can be found.
| File Name | Source Path | Target Path |
|---|---|---|
|
Controller |
<${addOnName}>/acceleratoraddon/web/src/de/hybris/platform/b2ctelcostorefront/controllers/pages/TelcoGuidedSellingController.java |
yacceleratorstorefront/web/addonsrc/b2ctelcostorefront/de/hybris/platform/b2ctelcostorefront/controllers/pages/TelcoGuidedSellingController.java |
|
Styling |
<${addOnName}>/acceleratoraddon/web/webroot/_ui/desktop/common/css/telco_guidedSelling.css |
|
|
JavaScript |
<${addOnName}>/acceleratoraddon/web/webroot/_ui/desktop/common/js/acc.guidedSelling.js |
|
|
Localization |
<${addOnPageRoot}>/messages/base.properties |
|
|
Tags |
<${addOnPageRoot}>/tags/desktop/guidedselling/dashboard.tag |
<${targetRoot}>/tags/addons/b2ctelcostorefront/desktop/guidedselling/dashboard.tag |
|
Tags |
<${addOnPageRoot}>/tags/desktop/guidedselling/dashboardEmpty.tag |
<${targetRoot}>/tags/addons/b2ctelcostorefront/desktop/guidedselling/dashboardEmpty.tag |
|
Tags |
<${addOnPageRoot}>/tags/desktop/guidedselling/editComponentAccordeonStyle.tag |
<${targetRoot}>/tags/addons/b2ctelcostorefront/desktop/guidedselling/editComponentAccordeonStyle.tag |
|
Tags |
<${addOnPageRoot}>/tags/desktop/guidedselling/viewAllServicePlans.tag |
<${targetRoot}>/tags/addons/b2ctelcostorefront/desktop/guidedselling/viewAllServicePlans.tag |
|
Tags |
<${addOnPageRoot}>/tags/desktop/product/productListerGridItemForGuidedSelling.tag |
<${targetRoot}>/tags/addons/b2ctelcostorefront/desktop/product/productListerGridItemForGuidedSelling.tag |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/guidedselling/editComponentAccordeonStylePage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/guidedselling/editComponentAccordeonStylePage.jsp |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/guidedselling/editComponentSolrStylePage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/guidedselling/editComponentSolrStylePage.jsp |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/guidedselling/viewAllServicePlansPage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/guidedselling/viewAllServicePlansPage.jsp |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/product/deviceLayoutPage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/product/deviceLayoutPage.jsp |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/product/serviceAddOnLayoutPage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/product/serviceAddOnLayoutPage.jsp |
|
JSP |
<${addOnPageRoot}>/views/desktop/pages/product/servicePlanLayoutPage.jsp |
<${targetRoot}>/views/addons/b2ctelcostorefront/desktop/pages/product/servicePlanLayoutPage.jsp |
Customization of JSP Files
The changes are mostly related to adding new taglibs and using these tags. The following shows an example JSP file:
File Name: ${addOnPageRoot}/views/desktop/pages/product/deviceLayoutPage.jsp
| Initial Value | Customization Possibilities |
|---|---|
[...]
<%@ taglib prefix="telcoProduct" tagdir="/WEB-INF/tags/addons/b2ctelcostorefront/desktop/product" %>
[...]
<%@ taglib prefix="guidedselling" tagdir="/WEB-INF/tags/addons/b2ctelcostorefront/desktop/guidedselling" %>
[...]
<guidedselling:dashboardEmpty type="DeviceModel"/>
<telcoProduct:deviceProductDetailsPanel product="${product}"
galleryImages="${galleryImages}" />
[...]
|
Added new taglibs and new sections for the Guided Selling dashboard and b2ctelco-specific device details panel in the deviceLayoutPage. |
Customization of Tag Files
In this example, there is no specific customization necessary. For details, refer to the respective tag files mentioned above.
Customization of ImpEx Files
Defining the New Page Template using ImpEx
File Name: b2ctelcostore/resources/b2ctelcostore/import/coredata/contentCatalogs/b2ctelcoContentCatalog/cms-content.impex
| Initial Value | Customization Possibilities |
|---|---|
$contentCatalog=b2ctelcoContentCatalog [...] $addonExtensionName=b2ctelcostorefront # Create PageTemplates # These define the layout for pages # "FrontendTemplateName" is used to define the JSP that should be used to render the page for pages with multiple possible layouts. # "RestrictedPageTypes" is used to restrict templates to page types INSERT_UPDATE PageTemplate;$contentCV[unique=true];uid[unique=true];name;frontendTemplateName;restrictedPageTypes(code);active[default=true] [...] ;;BundleSelectionAddOnPageTemplate;Extras Page Template;addon:/$addonExtensionName/pages/guidedselling/editComponentAccordeonStylePage;ContentPage;false; ;;BundleSelectionDevicePageTemplate;Device Page Template;addon:/$addonExtensionName/pages/guidedselling/editComponentSolrStylePage;ContentPage;false; ;;BundleSelectionPlanPageTemplate;Plans Page Template;;ContentPage;false; # Add Velocity templates that are in the CMS Cockpit. These give a better layout for editing pages # The FileLoaderValueTranslator loads a File into a String property. The templates could also be inserted in-line in this file. UPDATE PageTemplate;$contentCV[unique=true];uid[unique=true];velocityTemplate[translator=de.hybris.platform.commerceservices.impex.impl.FileLoaderValueTranslator] [...] ;;BundleSelectionAddOnPageTemplate ;$jarResourceCmsTelco/structure-view/structure_bundleSelectionPageTemplate.vm ;;BundleSelectionPlanPageTemplate ;$jarResourceCmsTelco/structure-view/structure_bundleSelectionPageTemplate.vm [...] INSERT_UPDATE ContentSlotName;name[unique=true];template(uid,$contentCV)[unique=true][default='BundleSelectionPlanPageTemplate'];validComponentTypes(code) ;SiteLogo;;CMSImageComponent,BannerComponent ;HeaderLinks;;CMSLinkComponent,CMSParagraphComponent ;MiniCart;;MiniCartComponent ;NavigationBar;;NavigationComponent ;Footer;;CMSLinkComponent,CMSParagraphComponent,FooterNavigationComponent INSERT_UPDATE ContentSlotName;name[unique=true];template(uid,$contentCV)[unique=true][default='BundleSelectionAddOnPageTemplate'];validComponentTypes(code) ;SiteLogo;;CMSImageComponent,BannerComponent ;HeaderLinks;;CMSLinkComponent,CMSParagraphComponent ;MiniCart;;MiniCartComponent ;NavigationBar;;NavigationComponent ;Footer;;CMSLinkComponent,CMSParagraphComponent,FooterNavigationComponent INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='BundleSelectionPlanPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;SiteLogo-BundleSelectionPlan;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-BundleSelectionPlan;HomepageNavLink;;HomepageNavLinkSlot;true ;;MiniCart-BundleSelectionPlan;MiniCart;;MiniCartSlot;true ;;NavigationBar-BundleSelectionPlan;NavigationBar;;NavigationBarSlot;true ;;Tabs-BundleSelectionPlan;Tabs;;TabsSlot;true ;;Footer-BundleSelectionPlan;Footer;;FooterSlot;true ;;HeaderLinks-BundleSelectionPlan;HeaderLinks;;HeaderLinksSlot;true [...] INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='BundleSelectionAddOnPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;SiteLogo-BundleSelectionAddOn;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-BundleSelectionAddOn;HomepageNavLink;;HomepageNavLinkSlot;true ;;NavigationBar-BundleSelectionAddOn;NavigationBar;;NavigationBarSlot;true ;;MiniCart-BundleSelectionAddOn;MiniCart;;MiniCartSlot;true ;;Footer-BundleSelectionAddOn;Footer;;FooterSlot;true ;;HeaderLinks-BundleSelectionAddOn;HeaderLinks;;HeaderLinksSlot;true ;;SearchBox-BundleSelectionAddOn;SearchBox;;SearchBoxSlot;true ;;TopHeaderSlot-BundleSelectionAddOn;TopHeaderSlot;;TopHeaderSlot;true ;;BottomHeaderSlot-BundleSelectionAddOn;BottomHeaderSlot;;BottomHeaderSlot;true ;;PlaceholderContentSlot-BundleSelectionAddOn;PlaceholderContentSlot;;PlaceholderContentSlot;true INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='BundleSelectionPlanPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;SiteLogo-BundleSelectionPlan;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-BundleSelectionPlan;HomepageNavLink;;HomepageNavLinkSlot;true ;;NavigationBar-BundleSelectionPlan;NavigationBar;;NavigationBarSlot;true ;;MiniCart-BundleSelectionPlan;MiniCart;;MiniCartSlot;true ;;Footer-BundleSelectionPlan;Footer;;FooterSlot;true ;;HeaderLinks-BundleSelectionPlan;HeaderLinks;;HeaderLinksSlot;true ;;SearchBox-BundleSelectionPlan;SearchBox;;SearchBoxSlot;true ;;TopHeaderSlot-BundleSelectionPlan;TopHeaderSlot;;TopHeaderSlot;true ;;BottomHeaderSlot-BundleSelectionPlan;BottomHeaderSlot;;BottomHeaderSlot;true ;;PlaceholderContentSlot-BundleSelectionPlan;PlaceholderContentSlot;;PlaceholderContentSlot;true # Content slots for template INSERT_UPDATE ContentSlotName;name[unique=true];template(uid,$contentCV)[unique=true][default='SBGProductsLandingPageTemplate'];validComponentTypes(code);compTypeGroup(code) ;SiteLogo;;CMSImageComponent,BannerComponent; ;HeaderLinks;;CMSLinkComponent,CMSParagraphComponent; ;SearchBox;;;searchbox ;MiniCart;;MiniCartComponent; ;NavigationBar;;NavigationComponent; ;Section1;;$wideContent; ;Section2;;$wideContent; ;Section3;;$narrowContent; ;Section4;;$narrowContent; ;Footer;;CMSLinkComponent,CMSParagraphComponent,FooterNavigationComponent; ;TopHeaderSlot;;;wide INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='SBGProductsLandingPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;TopHeaderSlot-SBGProductsLandingPage;TopHeaderSlot;;TopHeaderSlot;true ;;SiteLogo-SBGProductsLandingPage;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-SBGProductsLandingPage;HomepageNavLink;;HomepageNavLinkSlot;true ;;SearchBox-SBGProductsLandingPage;SearchBox;;SearchBoxSlot;true ;;MiniCart-SBGProductsLandingPage;MiniCart;;MiniCartSlot;true ;;NavigationBar-SBGProductsLandingPage;NavigationBar;;NavigationBarSlot;true ;;Footer-SBGProductsLandingPage;Footer;;FooterSlot;true ;;HeaderLinks-SBGProductsLandingPage;HeaderLinks;;HeaderLinksSlot;true INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='PlanDetailsPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;SiteLogo-PlanDetails;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-PlanDetails;HomepageNavLink;;HomepageNavLinkSlot;true ;;MiniCart-PlanDetails;MiniCart;;MiniCartSlot;true ;;NavigationBar-PlanDetails;NavigationBar;;NavigationBarSlot;true ;;Tabs-PlanDetails;Tabs;;TabsSlot;true ;;Footer-PlanDetails;Footer;;FooterSlot;true ;;HeaderLinks-PlanDetails;HeaderLinks;;HeaderLinksSlot;true INSERT_UPDATE ContentSlotForTemplate;$contentCV[unique=true];uid[unique=true];position[unique=true];pageTemplate(uid,$contentCV)[unique=true][default='AddOnDetailsPageTemplate'];contentSlot(uid,$contentCV)[unique=true];allowOverwrite ;;TopHeaderSlot-AddOnDetails;TopHeaderSlot;;TopHeaderSlot;true ;;SiteLogo-AddOnDetails;SiteLogo;;SiteLogoSlot;true ;;HomepageLink-AddOnDetails;HomepageNavLink;;HomepageNavLinkSlot;true ;;MiniCart-AddOnDetails;MiniCart;;MiniCartSlot;true ;;NavigationBar-AddOnDetails;NavigationBar;;NavigationBarSlot;true ;;Tabs-AddOnDetails;Tabs;;TabsSlot;true ;;Footer-AddOnDetails;Footer;;FooterSlot;true ;;HeaderLinks-AddOnDetails;HeaderLinks;;HeaderLinksSlot;true [...] |
Defined new CMS pages and its components via ImpEx. |
Localization of Pages using ImpEx
File Name: b2ctelcostore/resources/b2ctelcostore/import/coredata/contentCatalogs/b2ctelcoContentCatalog/cms-content_en.impex
| Initial Value | Customization Possibilities |
|---|---|
$contentCatalog=b2ctelcoContentCatalog $contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Staged])[default=$contentCatalog:Staged] # Language $lang=en # Functional Content Pages INSERT_UPDATE ContentPage;$contentCV[unique=true];uid[unique=true] ;name ;masterTemplate(uid,$contentCV) ;label ;defaultPage[default='true'];approvalStatus(code)[default='approved'];homepage[default='false'];previewImage(code, $contentCV)[default='ContentPageModel__function_preview'] ; ;guidedselling-select-device ;Select Device Page ;BundleSelectionAddOnPageTemplate ;guidedselling-select-device # Content Pages UPDATE ContentPage;$contentCV[unique=true];uid[unique=true];title[lang=$lang] [...] ;;bundleselection-plan;"Service Plan Selection" ;;bundleselection-extra;"Service Add Ons Selection" ;;guidedselling-select-device;"Product Selection" [...] |
Added localizable properties for Guided Selling Pages. |
Setting Preview Images for Guided Selling Pages using ImpEx
File Name: b2ctelcostore/resources/b2ctelcostore/import/sampledata/contentCatalogs/b2ctelcoContentCatalog/cms-content.impex
| Initial Value | Customization Possibilities |
|---|---|
$contentCatalog=b2ctelcoContentCatalog $contentCV=catalogVersion(CatalogVersion.catalog(Catalog.id[default=$contentCatalog]),CatalogVersion.version[default=Staged])[default=$contentCatalog:Staged] [...] $media=media(code, $contentCV); $contentPage=contentPage(uid, $contentCV); $addonExtensionName=b2ctelcostorefront [...] # Preview Image for use in the CMS Cockpit for special ContentPages INSERT_UPDATE Media;$contentCV[unique=true];code[unique=true];mime;realfilename;@media[translator=de.hybris.platform.impex.jalo.media.MediaDataTranslator][forceWrite=true];folder(qualifier)[default='images'] [...] ;;guidedSellingSelectDevicePagePreview;text/png;GuidedSellingSelectDevicePage.png;$jarResourceCms/preview-images/b2ctelco/GuidedSellingSelectDevicePage.png ;;guidedSellingSelectPlanPagePreview;text/png;GuidedSellingSelectPlanPage.png;$jarResourceCms/preview-images/b2ctelco/GuidedSellingSelectPlanPage.png # Functional Content Pages UPDATE ContentPage;$contentCV[unique=true];uid[unique=true];previewImage(code, $contentCV) [...] ;;guidedselling-select-device;guidedSellingSelectDevicePagePreview ;;bundleselection-plan;guidedSellingSelectPlanPagePreview [...] |
Defined and set preview images for Guided Selling Pages. |
Controller Configuration
The special controller is created to implement the Guided Selling functionality.
| Class Name | Source Path | Target Path |
|---|---|---|
|
TelcoGuidedSellingController |
<${addOnName}>/acceleratoraddon/web/src/de/hybris/platform/b2ctelcostorefront/controllers/pages/TelcoGuidedSellingController.java |
yacceleratorstorefront/web/addonsrc/b2ctelcostorefront/de/hybris/platform/b2ctelcostorefront/controllers/pages/TelcoGuidedSellingController.java |
TelcoGuidedSellingController
/*
* [y] hybris Platform
*
* Copyright (c) 2000-2015 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 de.hybris.platform.b2ctelcostorefront.controllers.pages;
import de.hybris.platform.acceleratorservices.controllers.page.PageType;
import de.hybris.platform.acceleratorstorefrontcommons.controllers.util.GlobalMessages;
import de.hybris.platform.acceleratorstorefrontcommons.forms.UpdateQuantityForm;
import de.hybris.platform.b2ctelcofacades.bundle.GuidedSellingFacade;
import de.hybris.platform.b2ctelcofacades.data.BundleTabData;
import de.hybris.platform.b2ctelcofacades.product.TelcoProductFacade;
import de.hybris.platform.b2ctelcoservices.model.DeviceModel;
import de.hybris.platform.b2ctelcoservices.model.ServiceAddOnModel;
import de.hybris.platform.b2ctelcoservices.model.ServicePlanModel;
import de.hybris.platform.b2ctelcostorefront.controllers.TelcoControllerConstants;
import de.hybris.platform.cms2.exceptions.CMSItemNotFoundException;
import de.hybris.platform.commercefacades.order.data.CartModificationData;
import de.hybris.platform.commercefacades.product.ProductOption;
import de.hybris.platform.commercefacades.product.data.ProductData;
import de.hybris.platform.commercefacades.search.data.SearchStateData;
import de.hybris.platform.commerceservices.order.CommerceCartModificationException;
import de.hybris.platform.commerceservices.search.facetdata.ProductSearchPageData;
import de.hybris.platform.commerceservices.search.pagedata.PageableData;
import de.hybris.platform.configurablebundlefacades.order.BundleCartFacade;
import de.hybris.platform.configurablebundleservices.bundle.BundleTemplateService;
import de.hybris.platform.configurablebundleservices.enums.BundleTemplateStatusEnum;
import de.hybris.platform.configurablebundleservices.model.BundleTemplateModel;
import java.util.Arrays;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
/**
* Controller for guided selling flows like the extras page.
*/
@Controller
@RequestMapping(value = "/bundle")
public class TelcoGuidedSellingController extends AbstractSearchPageController
{
private static final String GUIDEDSELLING_SELECT_ADDONS = "bundleselection-extra";
private static final String GUIDEDSELLING_SELECT_DEVICE = "guidedselling-select-device";
private static final String GUIDEDSELLING_BUNDLE_PLAN = "bundleselection-plan";
protected static final Logger LOG = Logger.getLogger(TelcoGuidedSellingController.class);
/**
* Component navigation.
*/
public static enum ComponentNavigation
{
CURRENT(""), NEXT("next"), PREVIOUS("prev");
final String code;
private ComponentNavigation(final String code)
{
this.code = code;
}
}
@Resource(name = "bundleTemplateService")
private BundleTemplateService bundleTemplateService;
@Resource(name = "guidedSellingFacade")
private GuidedSellingFacade guidedSellingFacade;
@Resource(name = "cartFacade")
private BundleCartFacade cartFacade;
@Resource(name = "telcoProductFacade")
private TelcoProductFacade productFacade;
@RequestMapping(value = "/view-plans/{bundleTemplateId}", method = RequestMethod.GET)
public String viewPlans(@PathVariable("bundleTemplateId") final String bundleTemplateId, final Model model)
throws CMSItemNotFoundException
{
BundleTemplateModel bundleTemplateModel = bundleTemplateService.getBundleTemplateForCode(bundleTemplateId);
if (bundleTemplateModel == null || !BundleTemplateStatusEnum.APPROVED.equals(bundleTemplateModel.getStatus().getStatus()))
{
if (bundleTemplateModel != null)
{
bundleTemplateModel = bundleTemplateService.getAllApprovedRootBundleTemplates(bundleTemplateModel.getCatalogVersion())
.iterator().next();
}
GlobalMessages.addErrorMessage(model, "guidedselling.viewplans.packagenotavailable");
}
final BundleTemplateModel firstComponentModel = bundleTemplateService
.getAllComponentsOfType(bundleTemplateModel, ServicePlanModel.class).iterator().next();
final ServicePlanModel firstPlan = (ServicePlanModel) firstComponentModel.getProducts().iterator().next();
final ProductData productData = productFacade.getProductForOptions(firstPlan, Arrays.asList(ProductOption.BASIC,
ProductOption.PRICE, ProductOption.SUMMARY, ProductOption.DESCRIPTION, ProductOption.GALLERY,
ProductOption.CATEGORIES, ProductOption.REVIEW, ProductOption.PROMOTIONS, ProductOption.CLASSIFICATION,
ProductOption.VARIANT_FULL, ProductOption.STOCK, ProductOption.SERVICE_PLAN_BUNDLE_TABS));
// change selected package to the one that is passed as a parameter
final List<BundleTabData> bundleTabs = productData.getBundleTabs();
for (final BundleTabData bundleTab : bundleTabs)
{
bundleTab.setPreselected(bundleTemplateId.equals(bundleTab.getParentBundleTemplate().getId()));
}
model.addAttribute("bundleTabs", bundleTabs);
storeCmsPageInModel(model, getContentPageForLabelOrId(GUIDEDSELLING_BUNDLE_PLAN));
setUpMetaDataForContentPage(model, getContentPageForLabelOrId(GUIDEDSELLING_BUNDLE_PLAN));
return TelcoControllerConstants.Views.Pages.GuidedSelling.ViewAllServicePlansPage;
}
/**
* Edit component page.
*
* @param bundleNo
* @param componentId
* @param searchQuery
* @param page
* @param showMode
* @param sortCode
* @param request
* @param model
* @return
* @throws CMSItemNotFoundException
*/
@RequestMapping(value = "/edit-component/{bundleNo}/component/{componentId}", method = RequestMethod.GET)
public String editComponent(@PathVariable("bundleNo") final String bundleNo,
@PathVariable("componentId") final String componentId,
@RequestParam(value = "q", required = false) final String searchQuery,
@RequestParam(value = "page", defaultValue = "0") final int page,
@RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
@RequestParam(value = "sort", required = false) final String sortCode,
final HttpServletRequest request, final Model model)
throws CMSItemNotFoundException
{
return internalEditComponent(bundleNo, componentId, searchQuery, page, showMode, sortCode, request, model);
}
/**
* Edit component page.
*
* @param bundleNo
* @param componentId
* @param searchQuery
* @param page
* @param showMode
* @param sortCode
* @param request
* @param model
* @param redirectAttributes
* @return
* @throws CMSItemNotFoundException
*/
@RequestMapping(value = "/edit-component/{bundleNo}/nextcomponent/{componentId}", method = RequestMethod.GET)
public String editNextComponent(@PathVariable("bundleNo") final String bundleNo,
@PathVariable("componentId") final String componentId,
@RequestParam(value = "q", required = false) final String searchQuery,
@RequestParam(value = "page", defaultValue = "0") final int page,
@RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
@RequestParam(value = "sort", required = false) final String sortCode,
final HttpServletRequest request,
final Model model, final RedirectAttributes redirectAttributes)
throws CMSItemNotFoundException
{
return editPositionalComponent(bundleNo, componentId, searchQuery,
page, showMode, sortCode, request, model, 1, redirectAttributes);
}
/**
* Preview component page.
*
* @param bundleNo
* @param componentId
* @param searchQuery
* @param page
* @param showMode
* @param sortCode
* @param request
* @param model
* @param redirectAttributes
* @return
* @throws CMSItemNotFoundException
*/
@RequestMapping(value = "/edit-component/{bundleNo}/prevcomponent/{componentId}", method = RequestMethod.GET)
public String editPreviousComponent(@PathVariable("bundleNo") final String bundleNo,
@PathVariable("componentId") final String componentId,
@RequestParam(value = "q", required = false) final String searchQuery,
@RequestParam(value = "page", defaultValue = "0") final int page,
@RequestParam(value = "show", defaultValue = "Page") final ShowMode showMode,
@RequestParam(value = "sort", required = false) final String sortCode,
final HttpServletRequest request,
final Model model, final RedirectAttributes redirectAttributes)
throws CMSItemNotFoundException
{
return editPositionalComponent(bundleNo, componentId, searchQuery,
page, showMode, sortCode, request, model, -1, redirectAttributes);
}
/**
* Generic method to edit a component at a relative position. It resolves the relative component and checks if it is
* valid to navigate there.
*/
protected String editPositionalComponent(final String bundleNo, final String componentId, final String searchQuery,
final int page, final ShowMode showMode, final String sortCode,
final HttpServletRequest request, final Model model,
final int relativeposition, final RedirectAttributes redirectAttributes)
throws CMSItemNotFoundException
{
String componentIdToNavigateTo = null;
if (guidedSellingFacade.checkIsComponentSelectionCriteriaMet(bundleNo, componentId))
{
componentIdToNavigateTo = guidedSellingFacade.getRelativeComponentId(bundleNo, componentId, relativeposition);
}
else
{
GlobalMessages.addFlashMessage(redirectAttributes, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.next.selection.criteria.not.met");
componentIdToNavigateTo = componentId;
final HttpServletRequest previousRequest = (HttpServletRequest) model.asMap().get("request");
final String previousUrl = previousRequest.getHeader("referer");
final int pos = previousUrl.indexOf(previousRequest.getContextPath()) + previousRequest.getContextPath().length();
final String redirectUrl = previousUrl.substring(pos, previousUrl.length());
return REDIRECT_PREFIX + redirectUrl;
}
if (componentIdToNavigateTo == null)
{
return REDIRECT_PREFIX + "/cart";
}
return internalEditComponent(bundleNo, componentIdToNavigateTo, searchQuery, page, showMode, sortCode, request, model);
}
/**
* Populates the dashboard and the appropriate step of the guided selling flow.
*/
protected String internalEditComponent(final String bundleNo, final String componentId, final String searchQuery,
final int page, final ShowMode showMode, final String sortCode,
final HttpServletRequest request, final Model model)
throws CMSItemNotFoundException
{
model.addAttribute("dashboard", guidedSellingFacade.getDashboard(Integer.parseInt(bundleNo), componentId));
final String productType = guidedSellingFacade.getComponentProductType(componentId);
if (productType == null)
{
// we have an invalid (empty?) component here: do not try to edit it but go to cart
return REDIRECT_PREFIX + "/cart";
}
model.addAttribute("productType", productType);
switch (productType)
{
case DeviceModel._TYPECODE:
case ServicePlanModel._TYPECODE:
final String urlPrefix = "/bundle/edit-component/" + bundleNo + "/component/" + componentId + "?q=";
final PageableData pageableData = createPageableData(page, getSearchPageSize(), sortCode, showMode);
final ProductSearchPageData<SearchStateData, ProductData> searchPageData = guidedSellingFacade.bundleSearch(
pageableData, searchQuery, urlPrefix, componentId, Integer.valueOf(bundleNo));
model.addAttribute("urlPrefix", urlPrefix);
model.addAttribute("pageType", PageType.PRODUCTSEARCH);
model.addAttribute("componentId", componentId);
populateModel(model, searchPageData, showMode);
storeCmsPageInModel(model, getContentPageForLabelOrId(GUIDEDSELLING_SELECT_DEVICE));
setUpMetaDataForContentPage(model, getContentPageForLabelOrId(GUIDEDSELLING_SELECT_DEVICE));
return TelcoControllerConstants.Views.Pages.GuidedSelling.EditComponentSolrStylePage;
case ServiceAddOnModel._TYPECODE:
model.addAttribute("bundleTemplateData", guidedSellingFacade.getComponentToEdit(bundleNo, componentId));
storeCmsPageInModel(model, getContentPageForLabelOrId(GUIDEDSELLING_SELECT_ADDONS));
setUpMetaDataForContentPage(model, getContentPageForLabelOrId(GUIDEDSELLING_SELECT_ADDONS));
return TelcoControllerConstants.Views.Pages.GuidedSelling.EditComponentAccordeonStylePage;
default:
return null;
}
}
/**
* Add product to cart.
*
* @param code
* @param model
* @param form
* @param bundleNo
* @param bundleTemplateId
* @param removeCurrentProducts
* @param navigation
* @param bindingResult
* @param redirectModel
* @return
*/
@RequestMapping(value = "/addEntry", method = RequestMethod.POST)
public String addToCart(
@RequestParam("productCodePost") final String code,
final Model model,
@Valid final UpdateQuantityForm form,
@RequestParam(value = "bundleNo", required = false) final Integer bundleNo,
@RequestParam(value = "bundleTemplateId", required = false) final String bundleTemplateId,
@RequestParam(value = "removeCurrentProducts", required = false, defaultValue = "false")
final boolean removeCurrentProducts,
@RequestParam("navigation") final ComponentNavigation navigation, final BindingResult bindingResult,
final RedirectAttributes redirectModel)
{
if (bindingResult.hasErrors())
{
for (final ObjectError error : bindingResult.getAllErrors())
{
if (error.getCode().equals("typeMismatch"))
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.error.quantity.invalid");
}
else
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
error.getDefaultMessage());
}
}
}
int finalBundleNo = addProduct(code, model, form.getQuantity().intValue(), bundleNo, bundleTemplateId,
removeCurrentProducts, redirectModel);
if (finalBundleNo < 0)
{
finalBundleNo = bundleNo == null ? 0 : bundleNo.intValue();
}
return REDIRECT_PREFIX + "/bundle/edit-component/" + finalBundleNo + "/" + navigation.code + "component/"
+ bundleTemplateId;
}
protected int addProduct(final String code, final Model model, final long qty, final Integer bundleNo,
final String bundleTemplateId, final boolean removeCurrentProducts,
final RedirectAttributes redirectModel)
{
try
{
final List<CartModificationData> cartModifications = cartFacade.addToCart(code, qty, bundleNo.intValue(),
bundleTemplateId, removeCurrentProducts);
model.addAttribute("modifiedCartData", cartModifications);
for (final CartModificationData cartModification : cartModifications)
{
if (cartModification.getQuantityAdded() == 0L)
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.information.quantity.noItemsAdded." + cartModification.getStatusCode());
}
else if (cartModification.getQuantityAdded() < qty)
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.information.quantity.reducedNumberOfItemsAdded." + cartModification.getStatusCode());
}
else if (cartModification.getQuantityAdded() > 0)
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER,
"guidedselling.basket.page.message.added");
return cartModification.getEntry().getBundleNo();
}
}
}
catch (final CommerceCartModificationException ex)
{
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.error.occurred");
LOG.warn("Couldn't add product of code " + code + " to cart.", ex);
}
return -2;
}
/**
* Remove product from cart.
*
* @param entryNumber
* @param model
* @param form
* @param bundleNo
* @param componentId
* @param bindingResult
* @param redirectModel
* @return
* @throws CMSItemNotFoundException
*/
@RequestMapping(value = "/removeEntry", method = RequestMethod.POST)
public String updateCartQuantities(@RequestParam("entryNumber") final long entryNumber, final Model model,
@Valid final UpdateQuantityForm form, @RequestParam("bundleNo") final String bundleNo,
@RequestParam("componentId") final String componentId, final BindingResult bindingResult,
final RedirectAttributes redirectModel) throws CMSItemNotFoundException
{
if (bindingResult.hasErrors())
{
for (final ObjectError error : bindingResult.getAllErrors())
{
if (error.getCode().equals("typeMismatch"))
{
GlobalMessages.addErrorMessage(model, "basket.error.quantity.invalid");
}
else
{
GlobalMessages.addErrorMessage(model, error.getDefaultMessage());
}
}
}
else if (cartFacade.getSessionCart().getEntries() != null)
{
try
{
final CartModificationData cartModification = cartFacade.updateCartEntry(entryNumber, form.getQuantity().longValue());
if (cartModification.getQuantity() == form.getQuantity().longValue())
{
// Success
if (cartModification.getQuantity() == 0)
{
// Success in removing entry
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER,
"guidedselling.basket.page.message.removed");
}
else
{
// Success in update quantity
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER,
"basket.page.message.update");
}
}
else
{
// Less than successful
if (form.getQuantity().longValue() == 0)
{
// Failed to remove entry
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.information.quantity.reducedNumberOfItemsAdded." + cartModification.getStatusCode());
}
else
{
// Failed to update quantity
GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.ERROR_MESSAGES_HOLDER,
"basket.information.quantity.reducedNumberOfItemsAdded." + cartModification.getStatusCode());
}
}
return REDIRECT_PREFIX + "/bundle/edit-component/" + bundleNo + "/component/" + componentId;
}
catch (final CommerceCartModificationException ex)
{
LOG.warn("Couldn't update product with the entry number: " + entryNumber + ".", ex);
return REDIRECT_PREFIX + "/bundle/edit-component/" + bundleNo + "/component/" + componentId;
}
}
return REDIRECT_PREFIX + "/cart";
}
}
Spring Configuration
| File Name | Source Path |
|---|---|
|
b2ctelcostorefront-web-spring.xml |
<${addOnName}>/resources/b2ctelcostorefront/web/spring/b2ctelcostorefront-web-spring.xml |
Bean Changes:
b2ctelcostorefront-web-spring.xml
[...] <bean name="telcoGuidedSellingController" class="de.hybris.platform.b2ctelcostorefront.controllers.pages.TelcoGuidedSellingController"/> [...]