Undefined or null CommerceService when Geometrixx is not installed


When trying to adapt the resource resolver to a CommerceService object, for example in the code below, then it returns null or "undefined":

var commerceService = resource. getResourceResolver(). adaptTo( com. adobe. cq. commerce. api.CommerceService); 

In this case, the class com.adobe.cq.commerce.api.CommerceService is available in the OSGi Class Loader. To confirm this, refer to the OSGi console using the http://aem-host:port/system/console/depfinder tool. 



This issue is by design.


Implement your own versions of the services provided in the cq-geometrixx-commons-core bundle provided under /apps/geometrixx-commons, when implementing an application using the AEM Commerce APls.

The Geometrixx ones are just samples, and it is not recommended to install Geometrixx in production, for security reasons. If you do not implement your own version of the CommerceServiceFactory, then you would run into the issue described above if Geometrixx is not installed. 

See the sample source code that ships with AEM under these paths: