0

We are running a Advance Product Option Extension in EE 1.12. On top of the extension we modified it to use cookies so if customer has selected particular custom options, those are saved in the cookie and next time he visits the product page again the options are populated again from the cookie.

The problem is the Cookie values are Cache in Magento FPC. We tried using hole punching for by passing this but unfortunately it is not working as well.

(1) Is there any other way to counter this issue other than hole punching? (2) As this is a custom module, do we modify the module/etc/cache.xml or pagecache/cache.xml for hole punching.

Regards,

Steve

Below is the part of the code we have for cookie:

<?php
    $pres_saved_data = Mage::helper('customoptions')->isCookieExist();
    //$cookieModel = Mage::getModel('core/cookie');
    //$pres_saved_data =  $cookieModel->get('myprescription');
    $show_prefilled_data = false;
    $pres_data = array();
    $other_pres_data = array();
    if($pres_saved_data){
        $sql = "select * from customer_prescription where id = '".$pres_saved_data."'";
        $rowdata = $readConnection->fetchRow($sql);
        if($rowdata){
           $show_prefilled_data = true;
           $optionsdata = unserialize($rowdata['prescription_options']);
           $pres_data['options'] = unserialize($optionsdata['options']);
            /* store all the option data which is there in cookie*/
           $options_data = array(); $options_sku = array(); 
            foreach($pres_data['options'] as $_data){
                 $label = strtolower(str_replace(" ",'_',$_data['label']));
                 if($label == 'prescription_type' || $label == 'lens' || $label =='pd' || $label == 'anti_reflective_coating')  {
                      $options_data[] =  $_data['value']; $options_sku[] =  $_data['sku']; } else{
                      $other_pres_data[$label] = $_data['value']; 
                 }
            }

             $sql  = sprintf("SELECT v.option_type_id ,t.title,c.option_id,v.sku FROM catalog_product_option as c inner join 
                          `catalog_product_option_type_value` as v 
                          on c.option_id = v.option_id 
                          inner join catalog_product_option_type_title as t on v.option_type_id = t.option_type_id
                          and v.sku  in ('%s') and product_id  = %s and t.title in ( '%s') where store_id  in( 0,".Mage::app()->getStore()->getId().")",implode("', '",$options_sku),$current_product->getId(),implode("', '",$options_data));

               $option_cookie_data = $readConnection->fetchAll($sql);             
         }
    }
  ?>
<?php endif; ?>

The container we have is :

<?php
class MageWorx_Customoptions_Model_Container_cachetest
    extends Enterprise_PageCache_Model_Container_Abstract


{
protected function _getIdentifier()
{
return $this->_getCookieValue(Enterprise_PageCache_Model_Cookie::COOKIE_CUSTOMER, '');
}

protected function _getCacheId()
{
return 'customoptions' . md5($this->_placeholder->getAttribute('cache_id') . $this->_getIdentifier());
}

protected function _renderBlock()
{
$blockClass = $this->_placeholder->getAttribute('block');
$template = $this->_placeholder->getAttribute('template');

$block = new $blockClass;
$block->setTemplate($template);
return $block->toHtml();
}
}
user1538621
  • 137
  • 5
  • 16

1 Answers1

0

Full page caching can be tricky. Here's an answer to another question that should help you out:

How do I include a dynamic block in the product page with full page caching turned on?

From that answer, it looks like you could save the cache with an ID including the customers ID. This will make a unique cache entry for every customer. This might lead to more conflicts with FPC, though, like when a user changes an option, you'll need to delete their cache entry.

Hole punching/placeholder logic should be in the modules /etc/cache.xml

Community
  • 1
  • 1
Ryan
  • 331
  • 1
  • 4
  • I have just added the container code in the question. Please take a look and let me know if there is any correction needed. We are looking to completely bypass FPC. – user1538621 Jul 22 '12 at 23:08
  • Try adding this to your container class: `protected function _saveCache($data, $id, $tags = array(), $lifetime = null) { return false; }` That should prevent it from getting cached. – Ryan Jul 23 '12 at 02:27
  • It's still same. I have even tried using Javascript to get the values from cookies to populated custom options but the whole thing is cached by Full Page Cache. – user1538621 Jul 23 '12 at 17:50
  • Is there anyway to stop entire product page from being cached. I know this is not a good idea but I just want to test this. – user1538621 Jul 23 '12 at 19:12