/**
  * Add factfinder navigation on search page
  *
  * @param Varien_Object $observer
  *
  * @return void
  */
 public function addLayerFiltersToSearch($observer)
 {
     $block = $observer->getBlock();
     if (!$block instanceof Mage_CatalogSearch_Block_Layer || !Mage::helper('factfinder')->isEnabled('asn')) {
         return;
     }
     $this->_addLayeredNavigation($block);
 }
Example #2
0
 /**
  * add new column, additional attributes and joins are stored on the configuration singleton to add them at the event observer
  *
  * @param Varien_Object $params
  */
 protected function _addAction($params)
 {
     $columnConfig = array();
     $blockId = $params->getBlock()->getId();
     /**
      * @var FireGento_GridControl_Model_Config $config
      */
     $config = Mage::getSingleton('firegento_gridcontrol/config');
     foreach ($params->getAction()->children() as $attribute) {
         // 4 special cases
         if ($attribute->getName() == 'index') {
             $config->addCollectionUpdate(FireGento_GridControl_Model_Config::TYPE_ADD_ATTRIBUTE, $blockId, (string) $attribute);
         } else {
             if ($attribute->getName() == 'joinAttribute') {
                 $config->addCollectionUpdate(FireGento_GridControl_Model_Config::TYPE_JOIN_ATTRIBUTE, $blockId, (string) $attribute);
                 continue;
             } else {
                 if ($attribute->getName() == 'joinField') {
                     $config->addCollectionUpdate(FireGento_GridControl_Model_Config::TYPE_JOIN_FIELD, $blockId, (string) $attribute);
                     continue;
                 } else {
                     if ($attribute->getName() == 'join') {
                         $config->addCollectionUpdate(FireGento_GridControl_Model_Config::TYPE_JOIN, $blockId, array('table' => (string) $attribute['table'], 'condition' => (string) $attribute['condition'], 'field' => (string) $attribute['field'], 'column' => $params->getColumn()->getName()));
                         continue;
                     } else {
                         if ($attribute->getName() == 'options') {
                             if (strpos((string) $attribute, '::') !== false) {
                                 list($_module, $_method) = explode('::', (string) $attribute);
                                 $_module = Mage::getSingleton($_module);
                                 $_call = array($_module, $_method);
                                 if (is_callable($_call)) {
                                     $columnConfig['options'] = call_user_func($_call);
                                     continue;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (count($attribute->children())) {
             // in case of arrays as attribute values
             $optionArray = array();
             foreach ($attribute->children() as $option) {
                 $optionArray[(string) $option->key] = (string) $option->value;
             }
             $columnConfig[$attribute->getName()] = $optionArray;
         } else {
             // standard string attribute
             $columnConfig[$attribute->getName()] = (string) $attribute;
         }
     }
     if (isset($columnConfig['header'])) {
         $columnConfig['header'] = $params->getBlock()->__($columnConfig['header']);
     }
     // add column to grid block
     $params->getBlock()->addColumn($params->getColumn()->getName(), $columnConfig);
 }
Example #3
0
 /**
  * Encode block data in URL then replace with ESI template
  *
  * @link https://github.com/nexcess/magento-turpentine/wiki/ESI_Cache_Policy
  *
  * Events: core_block_abstract_to_html_before
  *
  * @param  Varien_Object $eventObject
  * @return null
  */
 public function injectEsi($eventObject)
 {
     $blockObject = $eventObject->getBlock();
     $dataHelper = Mage::helper('turpentine/data');
     $esiHelper = Mage::helper('turpentine/esi');
     $debugHelper = Mage::helper('turpentine/debug');
     if ($esiHelper->getEsiBlockLogEnabled()) {
         $debugHelper->logInfo('Checking ESI block candidate: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName());
     }
     if ($esiHelper->shouldResponseUseEsi() && $blockObject instanceof Mage_Core_Block_Template && ($esiOptions = $blockObject->getEsiOptions())) {
         if (Mage::app()->getStore()->getCode() == 'admin') {
             // admin blocks are not allowed to be cached for now
             $debugHelper->logWarn('Ignoring attempt to inject adminhtml block: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName());
             return;
         } elseif ($esiHelper->getEsiBlockLogEnabled()) {
             $debugHelper->logInfo('Block check passed, injecting block: %s', $blockObject->getNameInLayout() ? $blockObject->getNameInLayout() : $blockObject->getModuleName());
         }
         Varien_Profiler::start('turpentine::observer::esi::injectEsi');
         $ttlParam = $esiHelper->getEsiTtlParam();
         $cacheTypeParam = $esiHelper->getEsiCacheTypeParam();
         $dataParam = $esiHelper->getEsiDataParam();
         $methodParam = $esiHelper->getEsiMethodParam();
         $hmacParam = $esiHelper->getEsiHmacParam();
         $scopeParam = $esiHelper->getEsiScopeParam();
         $referrerParam = $esiHelper->getEsiReferrerParam();
         $esiOptions = $this->_getDefaultEsiOptions($esiOptions);
         // change the block's template to the stripped down ESI template
         switch ($esiOptions[$methodParam]) {
             case 'ajax':
                 $blockObject->setTemplate('turpentine/ajax.phtml');
                 break;
             case 'esi':
             default:
                 $blockObject->setTemplate('turpentine/esi.phtml');
                 // flag request for ESI processing
                 Mage::register('turpentine_esi_flag', true, true);
         }
         // esi data is the data needed to regenerate the ESI'd block
         $esiData = $this->_getEsiData($blockObject, $esiOptions)->toArray();
         ksort($esiData);
         $frozenData = $dataHelper->freeze($esiData);
         $urlOptions = array($methodParam => $esiOptions[$methodParam], $cacheTypeParam => $esiOptions[$cacheTypeParam], $ttlParam => $esiOptions[$ttlParam], $hmacParam => $dataHelper->getHmac($frozenData), $dataParam => $frozenData);
         if ($esiOptions[$methodParam] == 'ajax') {
             $urlOptions['_secure'] = Mage::app()->getStore()->isCurrentlySecure();
         }
         if ($esiOptions[$scopeParam] == 'page') {
             $urlOptions[$referrerParam] = Mage::helper('core')->urlEncode(Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_current' => true)));
         }
         $esiUrl = Mage::getUrl('turpentine/esi/getBlock', $urlOptions);
         if ($esiOptions[$methodParam] == 'esi') {
             // setting [web/unsecure/base_url] can be https://... but ESI can never be HTTPS
             $esiUrl = preg_replace('|^https://|i', 'http://', $esiUrl);
         }
         $blockObject->setEsiUrl($esiUrl);
         // avoid caching the ESI template output to prevent the double-esi-
         // include/"ESI processing not enabled" bug
         foreach (array('lifetime', 'tags', 'key') as $dataKey) {
             $blockObject->unsetData('cache_' . $dataKey);
         }
         if (strlen($esiUrl) > 2047) {
             Mage::helper('turpentine/debug')->logWarn('ESI url is probably too long (%d > 2047 characters): %s', strlen($esiUrl), $esiUrl);
         }
         Varien_Profiler::stop('turpentine::observer::esi::injectEsi');
     }
     // else handle the block like normal and cache it inline with the page
 }
 /**
  * Remove all layered navigation filters on search page
  *
  * @param Varien_Object $observer
  *
  * @return void
  */
 public function removeLayerFilters($observer)
 {
     if (!Mage::helper('factfinder')->isEnabled()) {
         return;
     }
     $block = $observer->getBlock();
     if (!$block instanceof Mage_CatalogSearch_Block_Layer) {
         return;
     }
     $block->unsetChildren();
     $block->setData('_filterable_attributes', array());
     if (Mage::helper('core')->isModuleEnabled('Mage_ConfigurableSwatches')) {
         $this->_disableConfigurableSwatchesEvent();
     }
 }