cancel
Showing results for 
Search instead for 
Did you mean: 

Not able to get a popup in CCO screen with a plugin

0 Kudos
315

Dear experts,

We are programming a simple method in our plugin to show a pop-up in cco screen, as explained in the following blog:

https://blogs.sap.com/2018/10/22/sap-customer-checkout-plugin-development-part-ii/

But we are not able to make it work, it does nothing. We made sure the plugin is being executed when we post a receipt in cco (inserting System.out.println and those kind of things), and we also tried to simplify it all we can, so that currently the code looks as follows:

But the last line seems not to be doing anything.

package com.sap.tutorial.plugin;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
import javax.json.JsonObject;
import com.sap.scco.ap.plugin.BasePlugin;
import com.sap.scco.ap.plugin.BreakExecutionException;
import com.sap.scco.ap.plugin.annotation.PluginAt;
import com.sap.scco.ap.plugin.annotation.PluginAt.POSITION;
import com.sap.scco.ap.pos.entity.ReceiptEntity;
import com.sap.scco.ap.pos.service.ReceiptPosService;
import com.sap.scco.env.UIEventDispatcher;
import com.sap.scco.util.logging.Logger;

public class PluginBackEnd extends BasePlugin {

	private static final Logger logger = Logger.getLogger(PluginBackEnd.class);
	private JsonObject invoiceObject;
	
	@Override
	public String getId() {
		return "TUTORIAL_PLUGIN";
	}

	@Override
	public String getName( ) {
		return "My Plugin";
	}

	@Override
	public String getVersion() {
		return "1.0.0";
	}

	@Override
	public void startup() {
		
		super.startup();
	}

//	@Override
//	public Map<String, String> getPluginPropertyConfig() {
//		Map<String, String> props = new HashMap<>();
//		props.put("MY_PROPERTY", "String");
//		return props;
//	}

	@Override
	public boolean persistPropertiesToDB() {
		return true;
	}

	
	@PluginAt(pluginClass = ReceiptPosService.class, method = "validateReceipt", where = POSITION.AFTER)
	public void afterValidateReceipt(Object proxy, Object[] args, Object returnValue, StackTraceElement callStack)
			throws BreakExecutionException, FileNotFoundException {

		System.out.println("Entra al método");
		
		final ReceiptEntity receipt = (ReceiptEntity)args[0];			
		
		showMessageToUi("Mensaje de prueba", "error");

	}
	
	public static void showMessageToUi(String msg, String type) {
						
		//JOptionPane.showMessageDialog(null, msg);
		
		System.out.println("id: "+PluginBackEnd.class.getSimpleName());
		
		Map<String, String> dialogOptions = new HashMap<String, String>();
		dialogOptions.put("message", msg);
		dialogOptions.put("id", PluginBackEnd.class.getSimpleName());
		dialogOptions.put("type", type);
		dialogOptions.put("maxLifeTime", "30");			
		
		UIEventDispatcher.INSTANCE.dispatchAction("SHOW_MESSAGE_DIALOG", dialogOptions, null);
		
	}
	


}

Accepted Solutions (1)

Accepted Solutions (1)

R_Zieschang
Contributor

Hi asolar,

which UI are you using? The plugin from part II was designed for the old retail UI. Because the "new" UI ist based on another tech stack, sending messages to the customer works a bit different now.

So here's an example for the new UI.

private void sendMessageToUi(String titleKey, String titleMessage) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("title", titleKey);
jsonObject.put("message", titleMessage);
BroadcasterHolder.INSTANCE.getBroadcaster().broadcastPluginEventForPath("SHOW_MESSAGE_BOX", jsonObject);
}

hth

Robert

0 Kudos

Thanks a lot Robert, it's hard to find documentation about this.

Answers (0)