• Welcome to KonaKart Community Forum. Please login or sign up.
 

Get CurrentCustomer

Started by Manu, October 27, 2011, 02:10:14 pm

Previous topic - Next topic

Manu

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 !  :-*


ryan

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.

Manu

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 !

Manu

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  ;)

kate

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


Manu

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  :(

Manu

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.

Manu

It's ok, i forgot some JARs  :-X ;D

But i still not connected on Konakart  :-\

Manu

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 ?

Manu



I think this is the current behavior, is it ?

kate

Yes, as far as I understand what you've done...... (nice picture!)

Manu

And is it the good way to set up single sign on ?  ???

trevor

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.

Manu

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 ?

Manu

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 ?