Skip to content

Instantly share code, notes, and snippets.

@SchumacherFM
Created December 19, 2013 01:05
Show Gist options
  • Save SchumacherFM/8032623 to your computer and use it in GitHub Desktop.
Save SchumacherFM/8032623 to your computer and use it in GitHub Desktop.
Adding a simple block cache per customer to MageMonkey will improve the load of the Magento Checkout OnePage Review section after the first hit. Maybe the cache keys are not that optimal. As I have seen the code in line 41-48 I've started immediately to cry :-( License: GPL https://twitter.com/centerax/status/413285266996989952
<?php
/**
* Checkout subscribe checkbox block renderer
*
* @category Ebizmarts
* @package Ebizmarts_MageMonkey
* @author Ebizmarts Team <[email protected]>
*/
class Ebizmarts_MageMonkey_Block_Checkout_Subscribe extends Ebizmarts_MageMonkey_Block_Lists
{
protected function _construct()
{
parent::_construct();
$key = array(
'EbizMageMonkeyCheckoutSubscribe',
(int)Mage::app()->getStore()->isCurrentlySecure(),
Mage::getSingleton('customer/session')->isLoggedIn(),
$this->getQuote()->getCustomer()->getId()
);
$this->addData(array(
'cache_lifetime' => 60 * 60 * 1,
'cache_tags' => array('EbizMageMonkey_Checkout_Subscribe'),
'cache_key' => implode('_', $key),
));
}
/**
* Render block HTML
*
* @return string
*/
protected function _toHtml()
{
$alreadySubscribed = Mage::getModel('newsletter/subscriber')
->loadByEmail($this->getQuote()->getCustomerEmail())
->isSubscribed();
/**
* If you don't want to show the lists in the checkout when the user it's already subscribed.
* Replace the code below for the condition below
*
* if ( !$this->helper('monkey')->canCheckoutSubscribe() OR $alreadySubscribed ) {
*
*
* **/
if ( !$this->helper('monkey')->canCheckoutSubscribe() ) {
return '';
}
return parent::_toHtml();
}
/**
* Retrieve current quote object from session
*
* @return Mage_Sales_Model_Quote
*/
public function getQuote()
{
return Mage::getSingleton('checkout/session')
->getQuote();
}
/**
* Retrieve from config the status of the checkbox
*
* @see Ebizmarts_MageMonkey_Model_System_Config_Source_Checkoutsubscribe
* @return integer Config value possible values are 0,1,2,3
*/
public function checkStatus()
{
return (int)$this->helper('monkey')->config('checkout_subscribe');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment