Skip to Content
Technical Articles

SAP Customer Checkout Plugin Development – Part I

Part I: Develop your first SAP Customer Checkout Plugin

In the first part of this five-part blog series we are going to develop our first SAP Customer Checkout plugin. We are going to learn how to setup our eclipse project, use the cco API and build our plugin. To deep dive into the development, there are some prerequisites:

  • Eclipse and Maven installed
  • some experience in Java
  • SAP Customer Checkout 2.0 FP06 PL02 (with B1 Integration) installed and configured

After you started your Eclipse, right click in the package explorer and we will create a new Maven Project. I’ll explain why we use maven later on.

Click Next in the „New Maven Project“-wizard until you reach the screen where we need to set the Group Id and the Artifact Id.

You can choose whatever namespace you want to use, just make sure it does not collide with any other java packages (e.g. use your surname in the namespace or your company). Click finish.

Eclipse will now create a structure for your plugin and also a pom.xml which will be used for external dependencies and also for the creation of the MANIFEST file. Open the pom.xml with a text editor (I strongly recommend using the Spring Web Flow XML Editor which is part of the Spring Tools Suite you install at the eclipse marketplace).

The pom.xml should look something like this.

We will make some changes to it. Within the <properties> Tag add the following new properties:

<sap.scco.pluginClass>com.be1eye.cco.blogpluginpart1.App</sap.scco.pluginClass>
<sap.scco.POSVersions>n/a, 2.0 FP06</sap.scco.POSVersions>

In the sap.scco.pluginClass enter your namespace (your groupId) followed by the pluginname (your artifactId) and followed by App which will be our main class Eclipse already created for us. In the second property sap.scco.POSVersion you can enter a list for all CCO Versions your plugin can is compatible to. In our case this is 2.0 FP06.

After that, we also need some instructions for maven, so that maven will build our plugin correctly. Just copy and paste this part right under the </dependencies> part.

 

<build>
  <resources>
    <resource>
      <directory>resources</directory>
    </resource>
  </resources>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-shade-plugin</artifactId>
      <executions>
        <execution>
          <phase>package</phase>
          <goals>
            <goal>shade</goal>
          </goals>
          <configuration>
            <artifactSet>
              <excludes>
                <exclude>com.sap:scco:*</exclude>
              </excludes>
            </artifactSet>
            <filters>
              <filter>
                <artifact>*:*</artifact>
                <excludes>
                  <exclude>META-INF/*.SF</exclude>
                  <exclude>META-INF/*.DSA</exclude>
                  <exclude>META-INF/*.RSA</exclude>              
                </excludes>
            </filter>
           </filters>
           <transformers>
             <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
               <manifestEntries>
                 <PluginName>${project.name}</PluginName>
                 <CashdeskPOSPlugin>${sap.scco.pluginClass}</CashdeskPOSPlugin>
                 <CashDeskVersions>${sap.scco.POSVersions}</CashDeskVersions>
                 <Version>${project.version}</Version>
                 <Specification-Title>${project.name}</Specification-Title>
                 <Specification-Version>${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion}</Specification-Version>
                 <Specification-Vendor> ${project.organization.name}</Specification-Vendor>
                 <Implementation-Title>${project.name}</Implementation-Title>
                 <Implementation-Version>${project.version}</Implementation-Version>
                 <Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
                 <Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
                 <Implementation-URL>${project.url}</Implementation-URL>
                </manifestEntries>
              </transformer>
            </transformers>
          </configuration>
        </execution>
      </executions>
     </plugin>
   </plugins>
</build>

Your pom.xml now should look something like this:

These are classes to test your code but writing tests for our plugin is not scope of this blog series so we get rid of them.

Now we are going to add the ENV.jar of our SAP Customer Checkout Installation. Right Click your plugin name -> Build Path -> Configure Build Path…

Go to the tab Libraries and click on Add External JARs. Navigate to your SAP Customer Checkout installation and add the ENV.jar to your build path.

Click on Apply and Close. Now open the App.java file in your project.

Remove the static main method and extend the BasePlugin Class from SAP Customer Checkout.

Make sure you add the import afterwards. Just hover your mouse over BasePlugin and add the import.

Now we have to implement some methods so that SAP Customer Checkout knows how our plugin is called and which version it is. Just add these unimplemented methods by hover with your mouse over App and click add unimplemented methods.

You will see, that Eclipse has added 3 Methods getId(), getName() and getVersion().

Change the return values according your pluginid, name and version.

Notice the return value of the getVersion(). It will always output the version you set in your pom.xml.

Now we just have to build our plugin, copy it into the SAP Customer Checkout installation and we’ll see our first plugin running.

Right Click on our plugin folder -> Run as -> Maven Build…

Give this build configuration a name, set the goal to package, skip tests, apply and run. You should see the maven output in the bottom of your eclipse windows. If everything went well, you should see a folder named target. In this folder you will see a jar file with your artifactId and your version.

When successfull you can start the build from now on from eclipse directly.

Sometimes the build is failing, so please right click on your project -> Maven -> Update Project… and

update your project. The next build will be successfull eventually.

Copy the plugin jar file into the following folder [SAP Customer Checkout Installation folder]/cco/POSPlugins/AP

To be able to debug our plugin later, we need to add some parameters to the run.bat. So open run.bat with your prefered editor and search for the following part and the marked lines:

The first line will open a socket everytime Customer Checkout starts. The second line prevents cco from closing your browser everytime you restart or close cco.

Start your SAP Customer Checkout, log in and click on the cogwheel to open the CCO Backend. In the tab Plug-Ins you will now see, that our plugin successfully connected to Customer Checkout. Congratulations you just developed your first SAP Customer Checkout Plugin!

In the next part of this series, we will learn how to store and read our own plugin properties, how to write to the SAP Customer Checkout log and many more. So stay tuned!

If you have any questions do not hesitate to contact me.

 

The source is also hosted on gitlab: https://gitlab.com/ccoplugins/blogpluginpart1

 

Part II

8 Comments
You must be Logged on to comment or reply to a post.
  • Hi Robert,

    Thank you for the blog.

    Unfortunately, it does not work for me. Can you please suggest possible solution.

    If a plugin for CCO was made without Maven, it works like charm.

    After downloading your repository, this error appears:

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project blogpluginpart1: Compilation failure

    [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    A few strings have been added to pom.xml for fixing:

    <plugin>

    <artifactId>maven-compiler-plugin</artifactId>

    <version>3.6.0</version>

    <configuration>

    <source>1.8</source>

    <target>1.8</target>

    <fork>true</fork>

    <executable>C:\Program Files\Java\jdk1.8.0_121\bin\javac.exe</executable>

    </configuration>

    </plugin>

    But as result new error:

     

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.0:compile (default-compile) on project blogpluginpart1: Compilation failure: Compilation failure:

    [ERROR] C:\Projects\RTL\SAP_CCO\Maven_exp\src\main\java\com\be1eye\cco\blogpluginpart1\App.java:[3,29] error: package com.sap.scco.ap.plugin does not exist

     

    ENV.jar has been added as external jar. Maven and Java JDK were installed.

    • Hi Sergei,

       

      I did not test the build with the maven compiler plugin. Maven normally uses the JAVA_HOME Environment Variable to discover it’s JDK. Can you please check, if your JAVA_HOME Environment Variable points to your JDK?

      Have a look at:
      https://www.mkyong.com/java/how-to-set-java_home-on-windows-10/

      Then try to remove the plugin you have added to your pom.

       

      Alternatively you could also install the ENV.jar to your local maven repository (which I personally would prefer, but this was not in the scope of this blog).

      It should work like that:

      mvn install:installfile Dfile=<pathtoENV.jar> DgroupId=com.sap DartifactId=scco Dversion=2.0_FP06_PL02 Dpackaging=jar

      (change -Dversion to the version of your ENV.jar)

      After this you can add your ENV.jar to the maven dependencies like this:

      <dependencies>
      <dependency>
      <groupId>com.sap</groupId>
      <artifactId>scco</artifactId>
      <version>2.0_FP06_PL02</version>
      <scope>compile</scope>
      </dependency>
      </dependencies>

      (Change version in the <version> Tag to the version you set with the mvn install command)

      Then remove the the ENV.jar from your build path in eclipse. Maven should now automatically look for the ENV.jar in your local repository.

      With this process you could easily install several ENV.jars with different versions to test your plugin with different CCO Versions.

       

      Please let me know if this worked!

      Regards
      Robert

       

  • Hi Robert,

    Thank you very much for prompt reply. It is very helpful.

    Maven for CCO works for me.

     

    Only one thing, without  maven-compiler-plugin your example works, but my plugin shows errors:

     

    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project rnz_plugin: Compilation failure

    [ERROR] /…/Shared.java:[11,65] diamond operator is not supported in -source 1.5

    [ERROR]   (use -source 7 or higher to enable diamond operator)

     

    Which looks like Maven uses Java 1.5 in Eclipse for some reasons, at the same time installed Maven version shows:

     

    Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T07:41:47+13:00)

    Maven home: C:\dev\apache-maven-3.6.0\bin\..

    Java version: 1.8.0_121, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_121\jre

     

    The solution which works for me is adding code below in pom:

     

    <plugin>

    <artifactId>maven-compiler-plugin</artifactId>

    <version>3.6.0</version>

    <configuration>

    <source>1.8</source>

    <target>1.8</target>

    </configuration>

    </plugin>

     

    And after that it works perfectly.

    Please correct me if did something wrong.

    • Hello Sergei,

       

      many roads lead to rome. You did nothing wrong.

       

      You could try to remove the compiler plugin and set the compiler target and source in the properties (where you set the sap.scco.pluginClass).

      So it could look like this:

      <!– Properties –>
      <properties>
      <sap.scco.pluginClass>your.main.class.of.your.plugin</sap.scco.pluginClass>
      <sap.scco.POSVersions>n/a, 2.0 FP06</sap.scco.POSVersions>
      <maven.compiler.source>1.8</maven.compiler.source>
      <maven.compiler.target>1.8</maven.compiler.target>
      </properties>

      But I am happy, that this works for you. If you have any trouble do not hesitate to contact me.

      Regards

      Robert

       

      • Hi Robert,

        Thank you for advice. I’ve tried, it works and looks better than with additional plugin.

        I have just one major issue with plugin development for CCO. It is API documentation. There quite a few examples, some learning introduction PDF, which are very helpful. However, it takes time to find appropriate class and method and there is no guarantee, that right way without side effects has been chosen.

        For example, task1:
        CCO should show modal message to user if barcode is not found.

        Solution the task1:
        @PluginAt(pluginClass=IBarcodeManager.class, method=”findAllByCodeCached”, where=POSITION.AFTER)
        With
        UIEventDispatcher.INSTANCE.dispatchAction(“SHOW_MESSAGE_DIALOG”, null,
        dialogOptions);

        It works fine, but with API docs it would much faster to find this. Also, BarcodeManager contains methods:
        findAllByCodeCached(String)
        findByCode(String)
        findByCodeCached(String)
        I found appropriate for my simple scenario with debuger, but I am not fully sure and do not know for what others.

        Another task with weight barcodes (barcode contains item code and total amount), they are generated externaly, dynamically (depended on weight) and do not exist in database. I think in this case, MaterialEntity can be found manually using MaterialManager class. After that, I should add MaterialEntity and total to sale document…

        CCO plugin development looks powerful, but quite time-consuming without API docs. Probably, I miss something.

         

        Thanks a lot,

        Sergei