10

I have implemented holepunching of header in magento, and even though I have got it working on a per customer basis, I need the ability to take this one level deeper by making it work on diff cart item counts too.

Here is my code.

    class AD_PageCache_Model_Container_Header extends Enterprise_PageCache_Model_Container_Abstract {

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

    // public function getCacheKeyInfo() {
    //  $info = parent::getCacheKeyInfo();
    //  die('boo');
    //  $info['cart_count'] = Mage::helper( 'checkout/cart' )->getCart()->getItemsCount();

    //  return $info;
    // }

    protected function _getCacheId() {
        //return 'CONTAINER_HEADER_' . md5($this->_placeholder->getAttribute('cache_id') . $this->_placeholder->getAttribute('cart_count') ) . '_' . $this->_getIdentifier();
        return 'CONTAINER_HEADER_' . 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();
    }

}

My understanding from what I have been reading from holepunching threads on Magento is that Mage app is not initialized when FPC cache is serving the request, so basically the method of adding a placeholder attribute can't work, since

Mage::helper( 'checkout/cart' )->getCart()->getItemsCount();

won't work, right?

And even though how is that it should be, but it didn't seem to run at all, like I placed a die() call in there but nothing happened.

So what I am missing? And how can I retrieve the cart items count so that it can be used to build the cache ID?

Progress: I found

Enterprise_PageCache_Model_Cookie::COOKIE_CART

but this changes only once upon cart updation. After that it stays same. This is weird, this feels like the solution but its behavior says otherwise.

I couldn't find cart items count in session either. So the only way I currently see to do this would be to save the cart quantity in session whenever it updates and then use that in _getIdentifier().

I found that observers are inconsistent for cart. For addition, updation the events are dispatched but for removal, it doesn't. So I guess I can add my observer to price updation of the quote somehow, if that is consistent in having observers?

Also, I did read Full Page Cache invalidation on cart (quote) change but itt handles using

Enterprise_PageCache_Model_Cookie::COOKIE_CART

which doesn't work well in my case, although I think the problem lies inside it. What/How? I am not sure.

Also the current version of EE we have running doesn't even have Advanced folder under Model/Container. I am using EE 1.10.1.1

Any suggestions?

  • Not sure, but I think that this question is more related to Stack Overflow, but not this site... – Sergei Guk Jan 22 '13 at 22:27
  • 2
    Holepunching seems to be used here in a non traditional sense, can you explain the feature you're trying to implement without using jargon? – Ralph Tice Jan 22 '13 at 22:40
  • 1
    Why not append the customers cart id to _getIdentifier so the block is unique to customers cart, or even the number of items in their cart? – B00MER Jan 23 '13 at 19:59
  • @SergeiGuk Well it's heavily related to Magento – j0k Jan 25 '13 at 10:24
  • @RalphTice I'm trying to implement a cart value indicator in the header which shows the user how many items they have in their cart. Since that value is different per user, I don't want it to be cached. – Nirav Sheth Jan 27 '13 at 16:38
3

Using Enterprise_PageCache_Model_Cookie::COOKIE_CART is the right way to go, but you may need to do some changes.

Enterprise_PageCache_Model_Observer::registerQuoteChange is called on every quote save (item number change included) and it is also called in the context on Mage::app() so you can access all session data. Overwrite this observer and add more data in $this->_getCookie()->setObscure so the value changes whenever you need to.

| improve this answer | |
  • Any examples you might be willing to share on doing this? – Nirav Sheth Feb 4 '13 at 16:01

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.