Exemplo n.º 1
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;
 }
Exemplo n.º 2
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();
 }