Exemplo n.º 1
0
 public function getFilterOptionsCollection($allCategories = false)
 {
     $request = Mage::app()->getRequest();
     if ($request->getModuleName() == 'catalogsearch' && $request->getControllerName() == 'result' && $request->getActionName() == 'index' || $request->getModuleName() == 'manapro_filterajax' && $request->getControllerName() == 'search' && $request->getActionName() == 'index') {
         if (!$this->_filterSearchOptionsCollection) {
             $this->_filterSearchOptionsCollection = Mage::getResourceModel('mana_filters/filter2_store_collection')->addColumnToSelect('*')->addStoreFilter(Mage::app()->getStore())->setOrder('position', 'ASC');
         }
         Mage::dispatchEvent('m_before_load_filter_collection', array('collection' => $this->_filterSearchOptionsCollection));
         return $this->_filterSearchOptionsCollection;
     }
     if ($allCategories) {
         if (!$this->_filterAllOptionsCollection) {
             $this->_filterAllOptionsCollection = Mage::getResourceModel('mana_filters/filter2_store_collection')->addColumnToSelect('*')->addStoreFilter(Mage::app()->getStore())->setOrder('position', 'ASC');
         }
         Mage::dispatchEvent('m_before_load_filter_collection', array('collection' => $this->_filterAllOptionsCollection));
         return $this->_filterAllOptionsCollection;
     } else {
         if (!$this->_filterOptionsCollection) {
             Mana_Core_Profiler::start('mln' . '::' . __CLASS__ . '::' . __METHOD__ . '::' . '$productCollection->getSetIds()');
             $setIds = Mage::getSingleton('catalog/layer')->getProductCollection()->getSetIds();
             Mana_Core_Profiler::stop('mln' . '::' . __CLASS__ . '::' . __METHOD__ . '::' . '$productCollection->getSetIds()');
             $this->_filterOptionsCollection = Mage::getResourceModel('mana_filters/filter2_store_collection')->addFieldToSelect('*')->addCodeFilter($this->_getAttributeCodes($setIds))->addStoreFilter(Mage::app()->getStore())->setOrder('position', 'ASC');
         }
         Mage::dispatchEvent('m_before_load_filter_collection', array('collection' => $this->_filterOptionsCollection));
         return $this->_filterOptionsCollection;
     }
 }
 public function getFilterValue($model, $name, $candidates)
 {
     /* @var $core Mana_Core_Helper_Data */
     $core = Mage::helper(strtolower('Mana_Core'));
     /* @var $helper Mana_Filters_Helper_Data */
     $helper = Mage::helper(strtolower('Mana_Filters'));
     if (!($filter = $core->collectionFind($helper->getFilterOptionsCollection(true), 'code', $name))) {
         return $candidates[0];
     }
     $attribute = $filter->getAttribute();
     ///* @var $select Varien_Db_Select */ $select = $this->_getReadAdapter()->select();
     //$select
     //	->from(array('a' => $this->_resources->getTableName('eav_attribute')), array('attribute_id', 'backend_model', 'source_model', 'backend_type', 'frontend_input'))
     //	->join(array('t' => $this->_resources->getTableName('eav_entity_type')), 't.entity_type_id = a.entity_type_id', null)
     //	->where('a.attribute_code = ?', $name)
     //	->where('t.entity_type_code = ?', 'catalog_product');
     //$attribute = $this->_getReadAdapter()->fetchRow($select);
     /* @var $select Varien_Db_Select */
     $select = $this->_getReadAdapter()->select();
     if ($attribute->getData('backend_model') == 'eav/entity_attribute_backend_array' || $attribute->getData('source_model') == 'eav/entity_attribute_source_table' || $attribute->getData('frontend_input') == 'select' && !$attribute->getData('source_model') || $attribute->getData('frontend_input') == 'multiselect' && !$attribute->getData('source_model')) {
         Mana_Core_Profiler::start('mln' . '::' . __CLASS__ . '::' . __METHOD__ . '::' . 'select');
         $select->from(array('o' => $this->_resources->getTableName('eav_attribute_option')), 'option_id')->joinLeft(array('vg' => $this->_resources->getTableName('eav_attribute_option_value')), 'o.option_id = vg.option_id AND vg.store_id = 0', null)->joinLeft(array('vs' => $this->_resources->getTableName('eav_attribute_option_value')), 'o.option_id = vs.option_id AND vs.store_id = ' . Mage::app()->getStore()->getId(), null)->where('LOWER(COALESCE(vs.value, vg.value)) IN (?)', $candidates)->where('o.attribute_id = ?', $attribute->getId());
         $result = $this->_getReadAdapter()->fetchOne($select);
         Mana_Core_Profiler::stop('mln' . '::' . __CLASS__ . '::' . __METHOD__ . '::' . 'select');
         return $result;
     } else {
         return $candidates[0];
     }
 }
Exemplo n.º 3
0
 /**
  * @param Mage_Core_Controller_Varien_Action $action
  * @param Mage_Core_Model_Layout $layout
  */
 public function processFiles($action, $layout)
 {
     // TODO: refactor phases, find positions, then insert all, then delete all
     Mana_Core_Profiler::start(__METHOD__);
     $layoutXml = $layout->getNode();
     $layoutDom = new DOMDocument('1.0');
     $layoutNode = $layoutDom->importNode(dom_import_simplexml($layoutXml), true);
     $layoutDom->appendChild($layoutNode);
     $layoutXPath = new DOMXPath($layoutDom);
     $layoutModified = false;
     $headBlock = $this->_findHeadBlock($layoutXPath);
     $prototypeAction = $this->_findPrototypeAction($layoutXPath);
     $insertOnDemand = array();
     $insertEverywhere = array();
     $delete = array();
     $onDemandInsertPlace = null;
     $xpath = '';
     foreach ($this->_getFileConfig() as $name => $fileConfig) {
         /* @var $config array */
         /* @var $options array */
         extract($fileConfig);
         if ($xpath) {
             $xpath .= ' | ';
         }
         $xpath .= $this->_getActionsXPath($config);
     }
     foreach ($layoutXPath->query($xpath) as $element) {
         $onDemandInsertPlace = $element;
         break;
     }
     // handle javascript minification, merging and inclusion on all pages
     foreach ($this->_getFileConfig() as $name => $fileConfig) {
         /* @var $config array */
         /* @var $options array */
         extract($fileConfig);
         if (in_array('skip', $options)) {
             continue;
         }
         // find all statically defined actions of including a given script
         $fileActions = $this->_findDomActions($layoutXPath, $config);
         // prepare layout XML action depending on script parameters
         $action = $this->_createConfigurableAction($layoutDom, $config, $options);
         // insert script where and if appropriate
         if (in_array('ondemand', $options)) {
             if ($fileAction = $this->_getFirstElement($fileActions)) {
                 $insertOnDemand[] = array($action, $onDemandInsertPlace);
             }
             $delete[] = $fileActions;
         } elseif (in_array('everywhere', $options)) {
             $insertEverywhere[] = $action;
             foreach (array_reverse($insertOnDemand) as $insertOptions) {
                 list($action, $fileAction) = $insertOptions;
                 array_unshift($insertEverywhere, $action);
             }
             $insertOnDemand = array();
             $delete[] = $fileActions;
         } elseif (in_array('unload', $options)) {
             $delete[] = $fileActions;
         }
     }
     // insert configurable on demand js files
     foreach ($insertOnDemand as $insertOptions) {
         list($action, $fileAction) = $insertOptions;
         /* @var $fileAction DOMElement */
         $fileAction->parentNode->insertBefore($action, $fileAction);
         $layoutModified = true;
     }
     // insert configurable global js files
     if ($prototypeAction) {
         foreach (array_reverse($insertEverywhere) as $action) {
             $prototypeAction->parentNode->insertBefore($action, $prototypeAction->nextSibling);
             $layoutModified = true;
         }
     } elseif ($headBlock) {
         foreach (array_reverse($insertEverywhere) as $action) {
             $headBlock->insertBefore($action, $headBlock->firstChild);
             $layoutModified = true;
         }
     }
     // delete js files includes via layout XML instructions
     foreach ($delete as $fileActions) {
         foreach ($fileActions as $firstFileAction) {
             /* @var $firstFileAction DOMElement */
             $firstFileAction->parentNode->removeChild($firstFileAction);
             $layoutModified = true;
         }
     }
     if ($layoutModified) {
         $layout->loadDom($layoutNode);
     }
     Mana_Core_Profiler::stop(__METHOD__);
 }
Exemplo n.º 4
0
 protected function _getItemsData()
 {
     $key = $this->getLayer()->getStateKey() . '_SUBCATEGORIES';
     $data = $this->getLayer()->getAggregator()->getCacheData($key);
     if ($data === null) {
         $categoty = $this->getCategory();
         /** @var $categoty Mage_Catalog_Model_Categeory */
         Mana_Core_Profiler::start('mln', __CLASS__, __METHOD__, '$categoty->getChildrenCategories()');
         $categories = $categoty->getChildrenCategories();
         Mana_Core_Profiler::stop('mln', __CLASS__, __METHOD__, '$categoty->getChildrenCategories()');
         $this->getLayer()->getProductCollection()->addCountToCategories($categories);
         $data = array();
         foreach ($categories as $category) {
             if ($category->getIsActive() && $category->getProductCount()) {
                 $data[] = array('label' => Mage::helper('core')->htmlEscape($category->getName()), 'value' => $category->getId(), 'count' => $category->getProductCount());
             }
         }
         $data = $this->_getCategoryItemsData($this->getCategory(), $this->getLayer()->getProductCollection(), $categories);
         //if (!count($data)) { // no child categories having products
         //	$category = $this->getCategory()->getParentCategory();
         //	$products = clone ($this->getLayer()->getProductCollection());
         //	$products->addCategoryFilter($category);
         //	$data = $this->_getCategoryItemsData($category, $products);
         //}
         $tags = $this->getLayer()->getStateTags();
         $this->getLayer()->getAggregator()->saveCacheData($data, $key, $tags);
     }
     return $data;
 }