Author Topic: Get CurrentCustomer  (Read 685 times)

Manu

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Get CurrentCustomer
« on: October 27, 2011, 08:10:14 AM »
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

  • Administrator
  • Sr. Member
  • *****
  • Posts: 205
    • View Profile
    • KonaKart Website
Re: Get CurrentCustomer
« Reply #1 on: October 28, 2011, 03: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.

Manu

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #2 on: November 02, 2011, 05: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 !

Manu

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #3 on: November 02, 2011, 09:40:41 AM »
For the single sign on,

I use the com.konakart.bl.LogIntegrationManager and specified it in konakart admin. The checkCredentials() method returns 1 :
Code: [Select]
    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 :
Code: [Select]
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

  • Administrator
  • Sr. Member
  • *****
  • Posts: 227
    • View Profile
    • KonaKart Website
Re: Get CurrentCustomer
« Reply #4 on: November 02, 2011, 10:04:14 AM »
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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #5 on: November 02, 2011, 11:57:49 AM »
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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #6 on: November 03, 2011, 03: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 :
Code: [Select]
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

Code: [Select]
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

Code: [Select]
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

Code: [Select]
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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #7 on: November 03, 2011, 03:36:49 AM »
It's ok, i forgot some JARs  :-X ;D

But i still not connected on Konakart  :-\

Manu

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #8 on: November 03, 2011, 04:10:44 AM »
Are 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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #9 on: November 03, 2011, 04:50:41 AM »


I think this is the current behavior, is it ?

kate

  • Administrator
  • Sr. Member
  • *****
  • Posts: 227
    • View Profile
    • KonaKart Website
Re: Get CurrentCustomer
« Reply #10 on: November 03, 2011, 05:16:55 AM »
Yes, as far as I understand what you've done...... (nice picture!)

Manu

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #11 on: November 03, 2011, 06:07:56 AM »
And is it the good way to set up single sign on ?  ???

trevor

  • Administrator
  • Hero Member
  • *****
  • Posts: 495
    • View Profile
    • KonaKart
Re: Get CurrentCustomer
« Reply #12 on: November 03, 2011, 07:00:13 AM »
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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #13 on: November 03, 2011, 08:44:15 AM »
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

  • Jr. Member
  • **
  • Posts: 28
  • Logica, Lille Fr
    • View Profile
Re: Get CurrentCustomer
« Reply #14 on: November 03, 2011, 09:22:50 AM »
It looks that SecurityMgr.login() is always called.

Now i always get error because sessionId is null  :
Code: [Select]
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 ?