ezramorse / Zoom-Magento-FPC

The Zoom Full-Page Cache for Magento (by Ezra Morse of EZAPPS)
http://www.ezapps.ca/zoom-magento-full-page-cache.html
53 stars 34 forks source link

Hole punching does not load on product pages #2

Open bslinger opened 12 years ago

bslinger commented 12 years ago

Magento 1.6.2.0

There is an issue loading the hole punched data on product pages which seems to be due to this code in HoleController.php:

 if (array_key_exists('pid', $data)) {

        $product_index = Mage::getModel('reports/product_index_viewed')->getCollection()
                    ->addFieldToFilter('store_id',   array('eq' => Mage::app()->getStore()->getId()))
                    ->addFieldToFilter('product_id', array('eq' => $data['pid']));

        if ($session->isLoggedIn()) {

            $product_index->addFieldToFilter('customer_id', array('eq' => $session->getCustomerId()));

            if (count($product_index) < 1)
                            Mage::getModel('reports/product_index_viewed')
                                        ->setCustomerId($session->getCustomerId())
                                        ->setProductId($data['pid'])
                                        ->setStoreId(Mage::app()->getStore()->getId())
                                        ->save()
                                        ->calculate();

        } else {

            $product_index->addFieldToFilter('visitor_id', array('eq' => Mage::getSingleton('log/visitor')->getId()));

            if (count($product_index) < 1)
            Mage::getModel('reports/product_index_viewed')
                    ->setVisitorId(Mage::getSingleton('log/visitor')->getId())
                    ->setCustomerId(null)
                        ->setProductId($data['pid'])            
                    ->setStoreId(Mage::app()->getStore()->getId())
                        ->save()
                        ->calculate(); 
        }

    }

It seems to stem from the fact that the reports/product_index_viewed table extends from the catalog/product collection and so the addFieldToFilter functions don't work as expected. The error I am receiving is as follows:

Call to a member function getBackend() on a non-object in /home/sites/magento.directshop.com.au/docs/app/code/core/Mage/Eav/Model/Entity/Abstract.php on line 822

For now I've commented out the code as it just seems to relate to counting product views for cached products, but it would be nice to have a solution. I noticed somebody else was having the same problem here: http://www.magentocommerce.com/boards/viewthread/275766/P30/#t391771

sloth456 commented 12 years ago

Thanks for this fix! Works like a charm