Adding Consent Entry Points
Users give consent at entry points, such as the customer registration page. Learn how to add entry points to other areas of the storefront, and to other storefronts such as powertools.
The following example shows how to add a consent entry point to the Edit Units page, which you can access by navigating to in the powertools storefront. We'll create a marketing campaign consent template for this entry point.
Creating your own consent entry point involves the following main steps:
- Setting up the consent template
- Updating the controllers
- Adapting the front-end form
Setting Up the Consent Template
- In the powertools extension, add a new consent impex file along with build-time generated impex localizations. For more information on build-time generated localizations, see Localization of ImpEx Using Build Time Generation.
- powertoolsstore/resources/powertoolsstore/import/sampledata/stores/powertools/consents.impex
# ----------------------------------------------------------------------- # [y] hybris Platform # # Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. # # This software is the confidential and proprietary information of SAP # ("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. # ----------------------------------------------------------------------- # ImpEx for Consents for Electronics Store #% impex.setLocale( Locale.GERMAN ); $siteUid=powertools INSERT_UPDATE ConsentTemplate;id[unique=true];name;description;version[unique=true];baseSite(uid)[unique=true,default=$siteUid] ;BUSINESSUNIT_MARKETING;"Receive e-mails for Business Unit Marketing campaigns";"I approve to use my personal data for receiving e-mail newsletters for Business Unit Marketing campaigns.";0;; - powertoolsstore/resources-lang/powertoolsstore/import/sampledata/stores/powertools/consents.vt
# ----------------------------------------------------------------------- # [y] hybris Platform # # Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. # # This software is the confidential and proprietary information of SAP # ("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. # ----------------------------------------------------------------------- # # ImpEx for Consents for Electronics Store # # Language \$lang=$lang.toLowerCase() \$siteUid=powertools #set( $consents = $query.load('consents') ) UPDATE ConsentTemplate;id[unique=true];name[lang=\$lang];description[lang=\$lang];version[unique=true];baseSite(uid)[unique=true,default=\$siteUid] #foreach( $consent in $consents ) ;$consent.key;"$consent.values.name";"$consent.values.description";0;; #end - powertoolsstore/resources-lang/powertoolsstore/import/sampledata/stores/powertools/consents_en.properties
# ----------------------------------------------------------------------- # [y] hybris Platform # # Copyright (c) 2017 SAP SE or an SAP affiliate company. All rights reserved. # # This software is the confidential and proprietary information of SAP # ("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. # ----------------------------------------------------------------------- Consent.BUSINESSUNIT_MARKETING.name=Receive e-mails for Business Unit Marketing campaigns Consent.BUSINESSUNIT_MARKETING.description=I approve to use my personal data for receiving e-mail newsletters for Business Unit Marketing campaigns.
- powertoolsstore/resources/powertoolsstore/import/sampledata/stores/powertools/consents.impex
- Add a new property denoting the ID of the consent template to use for the B2B unit page in the project.properties file in the powertools extension:
businessunit.consent.id.powertools=BUSINESSUNIT_MARKETING
Updating the Controllers
- In the commerceorgaddon extension, modify MyCompanyPageController.java to add a constant for the consent template ID property name. This Java file is located in commerceorgaddon/acceleratoraddon/web/src/de/hybris/platform/commerceorgaddon/controllers/pages.
protected static final String BUSINESSUNIT_CONSENT_ID = "businessunit.consent.id";
- Add a new method that sets up the consent template data in the page model:
protected void addBusinessUnitConsentDataToModel(final Model model) { final String consentId = getSiteConfigService().getProperty(BUSINESSUNIT_CONSENT_ID); if (StringUtils.isNotBlank(consentId)) { final ConsentTemplateData consentData = getConsentFacade().getLatestConsentTemplate(consentId); model.addAttribute("consentTemplateData", consentData); } } - In BusinessUnitManagementPageController.java, add a call to addBusinessUnitConsentDataToModel to the editUnit (GET) method just before the return statement. This Java file is located in commerceorgaddon/acceleratoraddon/web/src/de/hybris/platform/commerceorgaddon/controllers/pages.
@RequestMapping(value = "/edit", method = RequestMethod.GET) @RequireHardLogIn public String editUnit(@RequestParam("unit") final String unit, final Model model) throws CMSItemNotFoundException { ... addBusinessUnitConsentDataToModel(model); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUnitEditPage; } - In the editUnit (POST) method, add a code block to handle the giveConsent and withdrawConsent logic, just after the call to b2bUnitFacade.updateOrCreateBusinessUnit(...). Also add a call to addBusinessUnitConsentDataToModel(...) in the catch block. This sets up the page model in the event of returning to the edit page after an error:
@RequestMapping(value = "/edit", method = RequestMethod.POST) @RequireHardLogIn public String editUnit(@RequestParam("unit") final String unit, @Valid final B2BUnitForm unitForm, final BindingResult bindingResult, final Model model, final RedirectAttributes redirectModel) throws CMSItemNotFoundException { ... ... try { b2bUnitFacade.updateOrCreateBusinessUnit(unit, unitData); final ConsentForm consentForm = unitForm.getConsentForm(); if (consentForm != null) { if (consentForm.getConsentGiven()) { getConsentFacade().giveConsent(consentForm.getConsentTemplateId(), consentForm.getConsentTemplateVersion()); } else if (consentForm.getConsentCode() != null) { getConsentFacade().withdrawConsent(consentForm.getConsentCode()); } } } catch (final ModelSavingException e) { LOG.error(String.format("Failed to save unit. Possibly non-unique id (original id: [%s] new id: [%s]).", unit, unitData.getUid()), e); GlobalMessages.addErrorMessage(model, "form.global.error"); bindingResult.rejectValue("uid", "form.b2bunit.notunique"); addBusinessUnitConsentDataToModel(model); return ControllerConstants.Views.Pages.MyCompany.MyCompanyManageUnitEditPage; } GlobalMessages.addFlashMessage(redirectModel, GlobalMessages.CONF_MESSAGES_HOLDER, "form.b2bunit.success"); return String.format(REDIRECT_TO_UNIT_DETAILS, urlEncode(unitForm.getUid())); } - Add the necessary import statements to each file.
Adapting the Front-End Form
- Add a consentForm property to B2BUnitForm.java (located in commerceorgaddon/acceleratoraddon/web/src/de/hybris/platform/commerceorgaddon/forms):
public class B2BUnitForm { ... private ConsentForm consentForm; ... public ConsentForm getConsentForm() { return consentForm; } public void setConsentForm(final ConsentForm consentForm) { this.consentForm = consentForm; } } - In b2bUnitForm.tag, add a block just above the buttons to handle the display of the consent checkbox. This file is located in commerceorgaddon/acceleratoraddon/web/webroot/WEB-INF/tags/responsive/company.
... <c:if test="${ not empty consentTemplateData }"> <form:hidden path="consentForm.consentTemplateId" value="${consentTemplateData.id}" /> <form:hidden path="consentForm.consentTemplateVersion" value="${consentTemplateData.version}" /> <form:hidden path="consentForm.consentCode" value="${consentTemplateData.consentData.code}" /> <div class="checkbox"> <label class="control-label uncased"> <c:choose> <c:when test="${not empty consentTemplateData.consentData && empty consentTemplateData.consentData.consentWithdrawnDate}"> <form:checkbox path="consentForm.consentGiven" checked="checked" /> </c:when> <c:otherwise> <form:checkbox path="consentForm.consentGiven" checked="" /> </c:otherwise> </c:choose> <c:out value="${consentTemplateData.description}" /> </label> </div> </c:if> ... - Add a tablib statement for the JSTL core taglib.
Users can now navigate to the Edit Units page of the powertools storefront and select the checkbox to give consent to receiving marketing newsletters.

