I want to get the currently logged in account details.
I know it is possible to get this information using:

  1. Mage::getSingleton('customer/session')->getCustomer();
  2. Mage::helper('customer')->getCurrentCustomer();

But what is the difference between these two ways?

What is the best approach?


They are basically the same thing.
For consistency I would use option 1. Getting it from the session.
The second approach actually calls the first one at one point.
So theoretically the first one is faster, but there is no real difference.

|improve this answer|||||
  • 1
    @Marius - would it not be best practice to use the helper method instead, thus ensuring forward going compatibility with magento changes? – ProxiBlue Mar 26 '15 at 13:03
  • 1
    @ProxiBlue. You think using Mage::getSingleton('customer/session')->getCustomer(); will not ensure compatibility ? can you explain why? – Marius Mar 26 '15 at 13:06
  • 2
    @marius, most likely, but, anything is essentially possible. What if the models change going forward? I would have thought that the helper methods exist as an abstraction against such a possibility, allowing 3rd party code better chance of working going forward. I myself use the code as suggested directly, but was just wondering (since reading this), if the helper methods would not be considered 'best practice' - why do they exist then, if not? – ProxiBlue Mar 26 '15 at 13:16
  • 1
    Ask yourself this: "What's the different between a model an a helper?" I honestly think that the helpers should not exist at all. From my point of view they are there just because someone did not know where to put some methods. not a very OOP style from my point of view. But your question is a valid one. Got me thinking (damn it). But I still rather use the session approach. It has been there since 1.0 and it's there now. I don't really think it will change. And I didn't find any call in the core code to the getCurrentCustomer method from the customer helper. – Marius Mar 26 '15 at 13:27
  • @Marius - I mirror your thoughts in regards to the helpers. In my own modules, I have helpers with methods, because they did not really fit anywhere else. Sorry I made you think ;) I tried hard to let the thoughts go, but it bugged me....now I can sleep restful :) – ProxiBlue Mar 26 '15 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.