KonaKart Community Forum

Installation / Configuration => Programming of KonaKart => Topic started by: Manu on October 27, 2011, 02:10:14 pm

Title: Get CurrentCustomer
Post by: Manu on October 27, 2011, 02:10:14 pm
Hi, I try to access to current customer cart in a portlet.

I use code provided in java_api_examples. I create a new Object which extends BaseApiExample and then i  get an engine instance.

But if i use KKEngIf eng = getKKEngByName("com.konakart.app.KKEng", engConf);, I can't access to getCustomerMgr().getCurrentCustomer() method.

And of I use eng = getKKEngByName("com.konakart.al.KKAppEng", engConf);, I can access to the method but eng is null.

I tried with a MgrFactory but i just have access to getCustMgr() method which does'nt have a getCurrentCustomer() method.

I don't know if I'm clear  :-X

What's the good way to get the current customer baskets ?

Thanks !  :-*

Title: Re: Get CurrentCustomer
Post by: ryan on October 28, 2011, 09:19:23 pm
You should always use the KKEngIf APIs.

getBasketItemsPerCustomerWithOptions(String sessionId, int customerId, int languageId, AddToBasketOptionsIf options)  returns the basket items for the customer using sessionId if he's logged in or the negative customerId if he isn't.

How you send or share  the customer session or id from between the portlets is a question for a portal guru.
Title: Re: Get CurrentCustomer
Post by: Manu on November 02, 2011, 10:57:45 am
Hi,

It works with hardcoded  login and password  :) In fact, the problem is now to make the single sign on works and share the sessionId between portlets.

Thanks for your help !
Title: Re: Get CurrentCustomer
Post by: Manu on November 02, 2011, 02:40:41 pm
For the single sign on,

I use the com.konakart.bl.LogIntegrationManager and specified it in konakart admin. The checkCredentials() method returns 1 :
    public int checkCredentials(String emailAddr, String password) throws KKException
    {
        return 1;
    }



And in my Liferay hook, I have a method which call konakart login() method :
public String loginKonaKartUser(String emailAddr, String password) {
try {
setSessionId(eng.login(emailAddr, password));
            int custId = eng.checkSession(sessionId);
            System.out.println("KK CUSTOMER_ID = " + custId);
} catch (Exception e) {
e.printStackTrace();
}
return sessionId;
}



In the database, I have a product in my basket. When I log into Liferay, the konakart login() method returns a sessionId and the system.out() returns the good customerId, but in the konakart portlet the user still not connected, and my cart is always empty.

And if i try to add a new product in my cart, in the database there is a new line in customers_basket but for an user with a negative customers_id.


Do you have an idea ?

Thanks  ;)
Title: Re: Get CurrentCustomer
Post by: kate on November 02, 2011, 03:04:14 pm
So it would appear that in one place you are logged in and another you are not.  Are you still not sharing the sessionId?

Perhaps by running with some debug flags on you can figure out what's happening for you:

set flags such as:

# Torque/Village Persistence layer - Set both to DEBUG to see the SQL
log4j.logger.org.apache.torque.util.BasePeer  = DEBUG
log4j.logger.com.workingdogs.village          = DEBUG

# Konakart classes
log4j.logger.com.konakart                     = DEBUG

Title: Re: Get CurrentCustomer
Post by: Manu on November 02, 2011, 04:57:49 pm
I can't access to logs when konakart is used as a portletin Liferay.

I tried to run my kkeclipse project and i have all log messages in the Eclipse console  but nothing when it runs in  Liferay.

I'm looking for how access to them  :(
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 08:27:35 am
I don't know if it's the cause of the problem but when my liferay hook runs I get some errors for all modules like these :
08:23:12,106 ERROR [OrderTotalMgr:182] Could not instantiate the OrderTotal Module com.konakart.bl.modules.ordertotal.subtotal.Subtotalin order to refresh its configuration.
java.lang.ClassNotFoundException: com.konakart.bl.modules.ordertotal.subtotal.Subtotal


08:23:12,106 ERROR [OrderTotalMgr:182] Could not instantiate the OrderTotal Module com.konakart.bl.modules.ordertotal.total.Totalin order to refresh its configuration.
java.lang.ClassNotFoundException: com.konakart.bl.modules.ordertotal.total.Total


08:23:12,106 ERROR [OrderTotalMgr:182] Could not instantiate the OrderTotal Module com.konakart.bl.modules.ordertotal.tax.Taxin order to refresh its configuration.
java.lang.ClassNotFoundException: com.konakart.bl.modules.ordertotal.tax.Tax


08:23:12,075 ERROR [PaymentMgr:176] Could not instantiate the Payment Module com.konakart.bl.modules.payment.cod.Cod in order to refresh its configuration.
java.lang.ClassNotFoundException: com.konakart.bl.modules.payment.cod.Cod


I tried to import konakart JARs but I still get errors.
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 08:36:49 am
It's ok, i forgot some JARs  :-X ;D

But i still not connected on Konakart  :-\
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 09:10:44 am
Quote from: kate on November 02, 2011, 03:04:14 pmAre you still not sharing the sessionId?


I think it's the reason of the problem.  My Liferay hook calls login() method and get a sessionId. And I think I have to tell to my KonaKart portlet that it has to use this same sessionId, no ?
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 09:50:41 am
(http://www.liferay.com/c/message_boards/get_message_attachment?messageId=11301462&attachment=konakart_singlesignon.png)

I think this is the current behavior, is it ?
Title: Re: Get CurrentCustomer
Post by: kate on November 03, 2011, 10:16:55 am
Yes, as far as I understand what you've done...... (nice picture!)
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 11:07:56 am
And is it the good way to set up single sign on ?  ???
Title: Re: Get CurrentCustomer
Post by: trevor on November 03, 2011, 12:00:13 pm
When you install the EE version of KK, in the KonaKart\java_api_examples\src\com\konakart\apiexamples directory there is a file called MySecurityMgr.java which includes an example of how you can use SSO with KK.

Normally you would pass an identifier or token to the KK portlet inside the login() method. The KK portlet should be able to get the token (which could even be the user id) from LR by calling LR APIs. The specialised SecurityMgr of the KK portlet within the login() method, should use the token to communicate back to Liferay to determine whether the user is logged into LR before completing the KK login and generating a KK session id.
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 01:44:15 pm
Ok, thanks !

And in my Liferay hook i have to call the login from eng.login() or i have to instantiate my custom SecurityManager an call its login() method ?
Title: Re: Get CurrentCustomer
Post by: Manu on November 03, 2011, 02:22:50 pm
It looks that SecurityMgr.login() is always called.

Now i always get error because sessionId is null  :
String userId = null;
// userId = callSSO(token); //This is the external call to the SSO system
if (userId == null)
{
return null;
}


I'm confused. Do i have to use an third party application to manage the SSO ? Or it's not necesary ?


Title: Re: Get CurrentCustomer
Post by: ryan on November 03, 2011, 08:53:36 pm
In this case you don't really need a third party application. What you need is for the KK Mgr to be able to call some Liferay service to check to see whether the user's session is still active or whether he has logged out from Liferay.
Title: Re: Get CurrentCustomer
Post by: Manu on November 04, 2011, 04:25:05 pm
I'm totally lost  :'(

For the moment,  when my hook detects a login event, it calls my UserService class which call the eng.login() method and I get the sessionId. Like this :
(http://data.imagup.com/12/1135088751.png)

I use all provided code (no SecurityManager and no LoginIntegration)


I don't know what I have to do with the sessionId to share it with KonaKart portlet. I've tried to put it in the HttpSession but i don't know where use it with the konakart portlet.

Every precise help will be appreciate. Do I have to use differents SecurityManager and LoginIntegration in my Liferay Hook and my KonaKart portlet (and so differents konakart_custom.jar) ? How to log in customer in the konakart portlet from the event in the hook ?

Sorry for all my posts  :-[