First of all, thank you very much for all the help in advance. This is my first time posting a question and I'm sorry if there's any mistake at all. Now, Let me first try to explain what I'm trying to achieve.

I've tried to create a simple plugin that will add various logged in customer data into JS objects. I've managed to create a simple phtml file containing something like below.

$configValue = Mage::getStoreConfig( 'data_options/section_one/custom_field_one',Mage::app()->getStore());
$currency_code = Mage::app()->getStore()->getCurrentCurrencyCode();

if($configValue > 0):

if (Mage::getSingleton('customer/session')->isLoggedIn()) :
// Get the customer object from customer session
    $customer = Mage::getSingleton('customer/session')->getCustomer();  
    $custID = $customer->getID();//get customer id
    $custName = $customer->getName();//get customer full name
    $custEmail = $customer->getEmail();//get customer email

    var somethingData = {};
    somethingData.customer = {};
    somethingData.customer.id = '<?php echo $custID; ?>';
    somethingData.customer.name = '<?php echo $custName;?>';
    somethingData.customer.email = '<?php echo $custEmail;?>';
    somethingData.cart = {};
    somethingData.cart.currency = '<?php echo $currency_code; ?>';

<?php else: ?>
    var somethingData = {};
    somethingData.cart = {};
    somethingData.cart.currency = '<?php echo $currency_code; ?>';
<?php endif;?>
<?php endif;?>

And also a local.xml file containing something like below.

        <reference name="head">
            <block type="core/template" name="homepage" template="something/something.phtml"></block>

So far, with these 2 main files, I managed to get the plugin working and on the page source, it will show something like below.

Source Example

Now, for the issue, I've tried to install this exact same plugin into a Magento Enterprise website and the problem is the logged in customer data showing up is not always correct. Sometimes or perhaps most of the time, some other people's data will appear instead of my data when I login and it's happening for all the other people visiting the website too.

I've done some research about this and it seems that it has something to do with FPC (Full Page Cache) mechanism that exists in Magento Enterprise. I've tried some things like adding a cache cleaning function call on the phtml file and still the issue happens.

I've tried to look around again and it seems that it's an issue that some people have experienced also in the past but so far, I can't seem to find a working solution yet and so I decided to post a question regarding this here in hope that someone can help me. If anyone has an idea, please let me know what needs to be done or added into the plugin so that the logged in customer data will always show the correct information.

  • 2
    Is it working fine on your dev environment or after disabling the cache ? – Aman Srivastava Jun 22 '16 at 6:44
  • 1
    Welcome to Magento SE. Good, well-researched question. Before somebody can answer in detail: you are right, if the Enterprise FPC is turned on, you have to configure "hole punching" (that's the keyword you should search for) for dynamic blocks, using cache.xml and some additional classes. – Fabian Schmengler Jun 22 '16 at 6:55
  • @Aman, the issue is very difficult to reproduce on our dev environment perhaps due to the fact that only a few people ever logs into it. And I'm not sure if it's okay to disabled the "FPC" on the live website (and the website is not exactly mine also). But thanks for the suggestion, I'll try asking the owner. – Ricky Li Jun 22 '16 at 7:11
  • @fschmengler, thanks for the keyword. I'll try researching with that. – Ricky Li Jun 22 '16 at 7:13
  • This is highly likely to be a cache issue. You could use magerun to inspect your cache entries to see if your customer data (the wrong one) is cached. Customer data blocks should never be cached or should include the customer ID in the cache key – Robbie Averill Jun 22 '16 at 7:37

Your Answer

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

Browse other questions tagged or ask your own question.