WCS Command Context initialization and cloning.

Command context will contain information regarding command object, You can retrieve user, store, language related information from command. The command context is set to the controller command when the command is invoked by the component facade. The command context should be used as a read-only object. You should not call its setter methods.



Example to get Command context:
private CommandContext getCommandContext() {
        CommandContext commandContext = null;
        ActivityToken activityToken = ((BusinessContextInternalService) BusinessContextServiceFactory
                .getBusinessContextService()).getActivityToken();
        commandContext = ContextHelper.createCommandContext(activityToken );
        return commandContext;
    }

Cloning Command Context: if you want to change any object value in command context then always recommended to first clone the command context, reset the required value and then reset the command context in required place



Ex:

     CommandContext clonedCmdContext = (CommandContext)getCommandContext().clone();
     clonedCmdContext.setCountry("US"); //override context country
     clonedCmdContext.setLanguageId("-1");//Override language to english.
     clonedCmdContext.setLanguage("en");
     clonedCmdContext.setStoreId("10151");



// Pass clone command context to any other command.

RaiseWCSEventCmd cmd = (RaiseWCSEventCmd)
        CommandFactory.createCommand(RaiseWCSEventCmd.CLASS_NAME,     clonedCmdContext .getStoreId());
 cmd.setCommandContext(clonedCmdContext ); 



Reference: 
https://help.hcltechsw.com/commerce/8.0.0/api/com/ibm/commerce/command/CommandContext.html

Comments

Popular posts from this blog

HCL Commerce v9 Installation steps

Protect/UnProtect Excel workbook using password