Extending CQ native commerce provider API | Community
Skip to main content
New Participant
October 16, 2015
Solved

Extending CQ native commerce provider API

  • October 16, 2015
  • 16 replies
  • 5699 views

Hi there ,

 I have started exploring cq commerce and as part of it was trying to extend the CQ native API .  Referring the article from here    http://helpx.adobe.com/adobe-cq/using/creating-custom-cq-commerce-providers.html  i have deployed my extended CQ commerce classes in felix console as a OSGI bundle . My custom CQ commerce provider is 'training' .

  However in geometrixx / en pages when I change 'cq:commerceprovider' property to 'training' and start using the pages it throws Null pointer exceptions in the back end with no products getting displayed on the category pages .

 My debugger pointed out to getServiceContext   method   from   OOTB class 'AbstractJcrCommerceServiceFactory'  . It seems that   AbstractJcrCommerceServiceFactory has service dependencies via @ reference  to set of services like languagemanager , slingRepository etc which should normally gets injected  . The getServiceContext method basically gives handles to these set of injected references . 

These services are injecting as expected when I'm using the OOTB reference commerce provider implementation('geometrixx')  which by default ships in with CQ installation . However when I change the provider to 'training' these services are not getting  injected  and getserviceContext returns null,which eventually is throwing null pointer exception .  

I see the same behaviour when I deploy my bundle from 'crxde' or 'eclipse ' .  I was on java 1.7 and also tested it in java 1.6  . From felix console I can see the bundle properly registered . Any pointers why these services not getting injected ? 

 

@Component(componentAbstract = true, metatype = false) public abstract class AbstractJcrCommerceServiceFactory implements CommerceServiceFactory { @Reference protected LanguageManager languageManager; @Reference protected UserPropertiesService userPropertiesService; @Reference protected SlingSettingsService slingSettingsService; @Reference protected SlingRepository slingRepository; @Reference protected CommerceSearchProviderManager searchProviderManager;

 

 

 

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by ramm18660403

To Sandro - The issue that you have faced is because in the AbstractJcrCommerceSession, the languageManager is null. You have to put following code in you custom CommerceServiceFactory class. That will resolve your issue.

public class TrainingCommerceServiceFactory extends AbstractJcrCommerceServiceFactory implements CommerceServiceFactory{

      @Reference
      protected LanguageManager languageManager;
      @Reference
      protected UserPropertiesService userPropertiesService;
      @Reference
      protected SlingSettingsService slingSettingsService;
      @Reference
      protected SlingRepository slingRepository;
      @Reference
      protected CommerceSearchProviderManager searchProviderManager;

16 replies

smacdonald2008
New Participant
October 16, 2015

To sandro - what version of CQ are you using?  This code is for 5.6 or higher. When the article was written last Spring - it worked as shown in the video.

ramm18660403Accepted solution
New Participant
October 16, 2015

To Sandro - The issue that you have faced is because in the AbstractJcrCommerceSession, the languageManager is null. You have to put following code in you custom CommerceServiceFactory class. That will resolve your issue.

public class TrainingCommerceServiceFactory extends AbstractJcrCommerceServiceFactory implements CommerceServiceFactory{

      @Reference
      protected LanguageManager languageManager;
      @Reference
      protected UserPropertiesService userPropertiesService;
      @Reference
      protected SlingSettingsService slingSettingsService;
      @Reference
      protected SlingRepository slingRepository;
      @Reference
      protected CommerceSearchProviderManager searchProviderManager;

October 16, 2015

I tried the same. but still the exception remains..

any more suggestions?

smacdonald2008
New Participant
October 16, 2015

Here is the output you should see:

[img]product.png[/img]

krisgummAuthor
New Participant
October 16, 2015

Hi ,

   Did you get a chance to debug the code with CQ commerce API added as src .  That was how I was able to dig out the problem ,  I faced with 'AbstractJcrCommerceServiceFactory.getServiceContext ' . I was on AEM 5.6.1 and the code from GIT hub didn't work out straight for me . 

October 16, 2015

Hi krisgumm,

 

you have mentioned that 

I was on AEM 5.6.1 and the code from GIT hub didn't work out straight for me . 

can you specify me what are the changes you have done to make the code work?

Thanks,

vksptg