Search code examples
sap-commerce-cloud

Hybris create custom selector in platform init page + create/not create user during system init


System setup (create custom selector in platform init page, with "create DemoUser" and "not create DemoUser" options). Depending on the value selected, create or not create DemoUser user during system init.


Solution

  • Find CoreSystemSetup class in your core extension to hook ServiceLayer code into the Hybris initialization and update life-cycle events. If you don't have, create the one.

    Now, inside SystemSetup class, you need to define a method using @SystemSetupParameterMethod

    Like

    @SystemSetupParameterMethod
    public List<SystemSetupParameter> getSystemSetupParameters()
    {
        final List<SystemSetupParameter> params = new ArrayList<SystemSetupParameter>();
    
        final SystemSetupParameter customDataParameter = new SystemSetupParameter("createDemoUser");
        customDataParameter.setLabel("Create demo Users?");
        customDataParameter.addValue("true");
        customDataParameter.addValue("false", true);
        params.add(customDataParameter);
    
        return params;
    }
    

    Now you can fetch user selected value inside createProjectData(@SystemSetup(type = Type.PROJECT, process = Process.ALL))

    Like

    @SystemSetup(type = Type.PROJECT, process = Process.ALL)
    public void createProjectData(final SystemSetupContext context) throws Exception
    {
        LOG.info("-----> createCustomData : " + context.getParameter(CoreConstants.EXTENSIONNAME + 
            "_createDemoUser"));
    }
    

    For more details, refer Hooks-for-Initialization-and-Update-Process