Exemplo n.º 1
0
 protected function _initBlocks()
 {
     parent::_initBlocks();
     $this->_categoryBlockName = 'merlinsearch/layer_filter_category';
     $this->_priceFilterBlockName = 'merlinsearch/layer_filter_price';
     $this->_attributeFilterBlockName = 'merlinsearch/layer_filter_attribute';
 }
Exemplo n.º 2
0
 /**
  * Set custom template for filter
  *
  * @return string
  */
 protected function _toHtml()
 {
     $filterableAttributes = $this->_getFilterableAttributes();
     foreach ($filterableAttributes as $attribute) {
         $this->getChild($attribute->getAttributeCode() . '_filter')->setTemplate($this->_getFilterTemplate($attribute->getAttributeCode()));
     }
     return parent::_toHtml();
 }
Exemplo n.º 3
0
 protected function _initBlocks()
 {
     parent::_initBlocks();
     $this->_stateBlockName = 'catalog/layer_state';
     $this->_categoryBlockName = 'solr/layer_filter_category';
     $this->_attributeFilterBlockName = 'solr/layer_filter_attribute';
     $this->_priceFilterBlockName = 'solr/layer_filter_price';
     $this->_decimalFilterBlockName = 'solr/layer_filter_decimal';
 }
Exemplo n.º 4
0
 public function getCacheTags()
 {
     if (!$this->_isCacheActive()) {
         return parent::getCacheTags();
     }
     $cacheTags = array(Mage_Catalog_Model_Category::CACHE_TAG, Mage_Catalog_Model_Category::CACHE_TAG . '_' . $this->_category->getId());
     /*
     foreach($this->_getProductCollection() as $_product) {
         $cacheTags[] = Mage_Catalog_Model_Product::CACHE_TAG."_".$_product->getId();
     }
     */
     return $cacheTags;
 }
Exemplo n.º 5
0
 /**
  * Get all layer filters
  *
  * @return array
  */
 public function getFilters()
 {
     $options = $this->_getCustomOptions();
     $filters = parent::getFilters();
     $params = Mage::app()->getRequest()->getParams();
     foreach ($options as $option) {
         $option_code = $option->getOptionCode();
         $option_filter = $this->getChild('option_' . $option_code . '_filter');
         if (isset($option_filter) && !array_key_exists($option_code, $params)) {
             $filters[] = $option_filter;
         }
     }
     return $filters;
 }
 /**
  * Prepare child blocks
  *
  * @return Mage_Catalog_Block_Layer_View
  */
 protected function _prepareLayout()
 {
     if (!$this->helper('elasticsearch')->isActiveEngine()) {
         return parent::_prepareLayout();
     }
     $stateBlock = $this->getLayout()->createBlock($this->_stateBlockName)->setLayer($this->getLayer());
     $categoryBlock = $this->getLayout()->createBlock($this->_categoryBlockName)->setLayer($this->getLayer())->init();
     $filterableAttributes = $this->_getFilterableAttributes();
     $filters = $this->_getFiltersArray($filterableAttributes);
     $this->setChild('layer_state', $stateBlock);
     $this->setChild('category_filter', $categoryBlock->addFacetCondition());
     $this->_addFacetConditionToFilters($filters);
     $this->getLayer()->apply();
     return $this;
 }
Exemplo n.º 7
0
 /**
  * Returns current catalog layer.
  *
  * @return JR_Search_Model_Catalogsearch_Layer|Mage_Catalog_Model_Layer
  */
 public function getLayer()
 {
     /** @var $helper JR_Search_Helper_Data */
     $helper = Mage::helper('jr_search');
     if ($helper->isActiveEngine()) {
         return Mage::getSingleton('jr_search/catalogsearch_layer');
     }
     return parent::getLayer();
 }
Exemplo n.º 8
0
 /**
  * Get layer object
  *
  * @return Mage_Catalog_Model_Layer
  */
 public function getLayer()
 {
     $helper = Mage::helper('enterprise_search');
     if ($helper->isThirdPartSearchEngine() && $helper->isActiveEngine()) {
         return Mage::getSingleton('enterprise_search/search_layer');
     }
     return parent::getLayer();
 }
Exemplo n.º 9
0
 /**
  * Get all layer filters
  *
  * We're getting the list of filters from Quiser's questions instead of Magento's data.
  *
  * @return array
  */
 public function getFilters()
 {
     $helper = Mage::helper('conversionpro');
     if ($helper->getIsEngineAvailableForNavigation(false)) {
         //At first, we create a filter block for each returned question from the XML.
         $filterableAttributes = $helper->getQuestions();
         foreach ($filterableAttributes as $attribute) {
             if ($attribute->Id == 'PriceQuestion') {
                 if (!array_key_exists('price_filter', $this->_loadedFilters)) {
                     $this->_loadedFilters['price_filter'] = $this->_createFilterBlock($helper->getSearchEngine()->getPriceFieldName());
                     $this->setChild('price_filter', $this->_loadedFilters['price_filter']);
                 }
             } else {
                 $code = strtolower($attribute->Text);
                 if (!array_key_exists($code . '_filter', $this->_loadedFilters)) {
                     $this->_loadedFilters[$code . '_filter'] = $this->_createFilterBlock($attribute->Text);
                     $this->setChild($code . '_filter', $this->_loadedFilters[$code . '_filter']);
                 }
             }
         }
         //Now, we go over the filters we've defined in the products collection.
         $searchParams = $helper->getCurrentLayer()->getProductCollection()->getExtendedSearchParams();
         unset($searchParams['query_text']);
         unset($searchParams['visibility']);
         foreach ($searchParams as $filter => $values) {
             //If one of these filters wasn't in the returned questions, create a block for it.
             if (!array_key_exists(strtolower($filter) . '_filter', $this->_loadedFilters)) {
                 if ($filter == 'price') {
                     $this->_loadedFilters['price_filter'] = $this->_createFilterBlock($helper->getSearchEngine()->getPriceFieldName());
                     $this->setChild('price_filter', $this->_loadedFilters['price_filter']);
                 } else {
                     $this->_loadedFilters[strtolower($filter) . '_filter'] = $this->_createFilterBlock($filter);
                     $this->setChild(strtolower($filter) . '_filter', $this->_loadedFilters[strtolower($filter) . '_filter']);
                 }
             }
             //Create state tags for every active filter except for price and category, which we cover somewhere else.
             if ($filter != 'category' && $filter != 'price') {
                 //Creating an attribute model for use in the state tag we'll be creating soon.
                 $attribute = Mage::getResourceModel('catalog/product_attribute_collection')->addFieldToFilter('attribute_code', $filter)->getFirstItem();
                 //These two lines simulate what would have happened had I just reinstantiated the block and assigned the
                 // model to it, as is done in the commented section above.
                 $attribute->setRequestVar($attribute->getAttributeCode());
                 $attribute->setName($helper->getSearchEngine()->getCelebrosSearchEngineFieldName($attribute));
                 //Do this for each filter value (to cover multiselect filters)
                 foreach ($values as $value) {
                     //Get answer text according to the answer id.
                     $answerText = $helper->getAnswerTextByAnswerId($filter, $value);
                     //Only create a new state tag in case it wasn't already created.
                     if (!array_key_exists($value, $this->_stateTags)) {
                         //Create the state tag for this answer with all the info we've just gathered.
                         $this->_stateTags[$value] = $helper->getCurrentLayer()->getState()->addFilter(Mage::getModel('conversionpro/catalog_layer_filter_item')->setFilter($attribute)->setLabel($answerText)->setValue($value)->setCount(0));
                     }
                 }
             }
         }
         //Now we start anew, and create a list of filters from the questions returned from the XML (to maintain the original order).
         $filters = array();
         $filterableAttributes = Mage::helper('conversionpro')->getQuestions();
         foreach ($filterableAttributes as $attribute) {
             if ($attribute->Id == 'PriceQuestion') {
                 $filters['price'] = $this->getChild('price_filter');
             } elseif ($attribute->Text == 'Category') {
                 $filters['category'] = $this->_getCategoryFilter();
             } else {
                 $filters[strtolower($attribute->Text)] = $this->getChild(strtolower($attribute->Text) . '_filter');
             }
         }
         //Adding the selected questions that don't appear in the XML (because they don't have multiselect enabled).
         // These items won't appear, but we want to consider them in the filters count.
         foreach ($searchParams as $filter => $values) {
             if (!array_key_exists($filter, $filters)) {
                 $filters[$filter] = $this->getChild(strtolower($filter) . '_filter');
             }
         }
         return $filters;
     }
     return parent::getFilters();
 }
Exemplo n.º 10
0
 /**
  * Returns the current catalog layer.
  *
  * @return NanoWebG_ElasticSearch_Model_Catalogsearch_Layer|Mage_Catalog_Model_Layer
  */
 public function getLayer()
 {
     /** @var $helper NanoWebG_ElasticSearch_Helper_Data */
     $helper = Mage::helper('nanowebg_elasticsearch');
     if ($helper->useElasticSearch()) {
         return Mage::getSingleton('nanowebg_elasticsearch/catalogsearch_layer');
     }
     return parent::getLayer();
 }
Exemplo n.º 11
0
 /**
  * Get layer object
  *
  * @return Mage_Catalog_Model_Layer
  */
 public function getLayer()
 {
     if (Mage::helper('enterprise_search')->getIsEngineAvailableForNavigation(false)) {
         return Mage::getSingleton('enterprise_search/search_layer');
     }
     return parent::getLayer();
 }
Exemplo n.º 12
0
 /**
  * Custom template handling for children blocks (filters) before to display theme
  *
  * @return Smile_ElasticSearch_Model_Catalog_Layer Self reference
  */
 protected function _beforeToHtml()
 {
     if (Mage::helper('smile_elasticsearch')->isActiveEngine()) {
         foreach ($this->_filterTemplates as $filterName => $template) {
             $block = $this->getChild($filterName . '_filter');
             if ($block) {
                 $block->setTemplate($template);
             }
         }
     }
     return parent::_beforeToHtml();
 }