Example #1
0
 /**
  * Get all layer filters
  *
  * @return array
  */
 public function getFilters()
 {
     $filters = parent::getFilters();
     if ($this->_isStockFilter()) {
         $filters[] = $this->_getStockFilter();
     }
     return $filters;
 }
Example #2
0
 public function getFilters()
 {
     $filters = parent::getFilters();
     if ($saleFilter = $this->_getSaleFilter()) {
         // Insert sale filter to the self::SALE_FILTER_POSITION position
         $filters = array_merge(array_slice($filters, 0, self::SALE_FILTER_POSITION - 1), array($saleFilter), array_slice($filters, self::SALE_FILTER_POSITION - 1, count($filters) - 1));
     }
     return $filters;
 }
 /**
  * Get all layer filters
  *
  * @return array
  */
 public function getFilters()
 {
     $filters = parent::getFilters();
     foreach ($this->_layeredCategories as $layeredCatConfig) {
         $categoryId = $layeredCatConfig['category'];
         $position = $layeredCatConfig['position'];
         if ($categoryFilter = $this->_getLayeredCategoryFilter($categoryId)) {
             $filters = array_merge(array_slice($filters, 0, $position), array($categoryFilter), array_slice($filters, $position, count($filters)));
         }
     }
     return $filters;
 }
Example #4
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;
 }
 public function getFilters()
 {
     if (!is_null($this->_filterBlocks)) {
         return $this->_filterBlocks;
     }
     //attributes ids
     $attrIds = array();
     // option ids
     $ids = array();
     $filters = parent::getFilters();
     // remove some filtes for the home page
     $exclude = Mage::getStoreConfig('amshopby/general/exclude');
     if ('/' == Mage::app()->getRequest()->getRequestString() && $exclude) {
         $exclude = explode(',', preg_replace('/[^a-zA-Z0-9_\\-,]+/', '', $exclude));
         $filters = $this->excludeFilters($filters, $exclude);
     }
     foreach ($filters as $f) {
         if ($f->getItemsCount() && $f instanceof Mage_Catalog_Block_Layer_Filter_Attribute) {
             $items = $f->getItems();
             foreach ($items as $item) {
                 $vals = explode(',', $item->getValue() ? $item->getValue() : $item->getOptionId());
                 foreach ($vals as $v) {
                     $ids[] = $v;
                 }
             }
             $attrIds[] = $items[0]->getFilter()->getAttributeModel()->getId();
         }
     }
     //additional filter properties
     $attrCollection = Mage::getResourceModel('amshopby/filter_collection')->addFieldToFilter('attribute_id', array('in' => $attrIds))->load();
     $attributes = array();
     foreach ($attrCollection as $row) {
         $attributes[$row->getAttributeId()] = $row;
     }
     // images of filter values
     $optionsCollection = Mage::getResourceModel('amshopby/value_collection')->addFieldToFilter('option_id', array('in' => $ids))->load();
     $options = array();
     foreach ($optionsCollection as $row) {
         $options[$row->getOptionId()] = array('img' => $row->getImgSmall(), 'descr' => $row->getDescr());
     }
     $catId = $this->getLayer()->getCurrentCategory()->getId();
     $exclude = array();
     // update filters with new properties
     foreach ($filters as $f) {
         if ($f->getItemsCount() && $f instanceof Mage_Catalog_Block_Layer_Filter_Attribute) {
             $items = $f->getItems();
             //add selected and image properties for all items
             $attributeCode = $items[0]->getFilter()->getAttributeModel()->getAttributeCode();
             $selectedValues = Mage::app()->getRequest()->getParam($attributeCode);
             if ($selectedValues) {
                 $selectedValues = explode(',', $selectedValues);
                 $f->setHasSelection(true);
             } else {
                 $selectedValues = array();
             }
             foreach ($items as $item) {
                 $optId = $item->getOptionId();
                 if (!empty($options[$optId]['img'])) {
                     $item->setImage($options[$optId]['img']);
                 }
                 if (!empty($options[$optId]['descr'])) {
                     $item->setDescr($options[$optId]['descr']);
                 }
                 $item->setIsSelected(in_array($optId, $selectedValues));
             }
             $attributeId = $items[0]->getFilter()->getAttributeModel()->getId();
             if (isset($attributes[$attributeId])) {
                 $a = $attributes[$attributeId];
                 $f->setMaxOptions($a->getMaxOptions());
                 $f->setHideCounts($a->getHideCounts());
                 $f->setSortBy($a->getSortBy());
                 $f->setDisplayType($a->getDisplayType());
                 $f->setSingleChoice($a->getSingleChoice());
                 if (Mage::getStoreConfig('amshopby/general/enable_collapsing')) {
                     $f->setCollapsed($a->getCollapsed());
                 }
                 $cats = trim($a->getExcludeFrom());
                 if ($cats) {
                     if (in_array($catId, explode(',', $cats))) {
                         $exclude[] = $attributeCode;
                     }
                 }
             }
             //if attibute
         } elseif ($f instanceof Mage_Catalog_Block_Layer_Filter_Category) {
             $f->setDisplayType(Mage::getStoreConfig('amshopby/general/categories_type'));
             $f->setTemplate('amshopby/category.phtml');
             $f->setHasSelection($catId != $this->getLayer()->getCurrentStore()->getRootCategoryId());
             if (Mage::getStoreConfig('amshopby/general/enable_collapsing')) {
                 $f->setCollapsed(Mage::getStoreConfig('amshopby/general/categories_collapsed'));
             }
         } elseif ($f instanceof Mage_Catalog_Block_Layer_Filter_Price) {
             $f->setDisplayType(Mage::getStoreConfig('amshopby/general/price_type'));
             $f->setTemplate('amshopby/price.phtml');
             $f->setHasSelection(isset($_GET['price']));
             //$f->setHasSelection(Mage::app()->getRequest()->getParam('price'));
             if (Mage::getStoreConfig('amshopby/general/enable_collapsing')) {
                 $f->setCollapsed(Mage::getStoreConfig('amshopby/general/price_collapsed'));
             }
         }
     }
     // 1.2.7 exclude some filters from the selected categories
     $filters = $this->excludeFilters($filters, $exclude);
     $this->_filterBlocks = $filters;
     return $filters;
 }
Example #6
0
 public function getFilters()
 {
     if (is_null($this->_filterBlocks)) {
         $this->_filterBlocks = parent::getFilters();
     }
     return $this->_filterBlocks;
 }
Example #7
0
 public function getFilters()
 {
     if (!is_null($this->_filterBlocks)) {
         return $this->_filterBlocks;
     }
     $filters = parent::getFilters();
     // remove some filtes for the home page
     $exclude = Mage::getStoreConfig('amshopby/general/exclude');
     if ('/' == Mage::app()->getRequest()->getRequestString() && $exclude) {
         $exclude = explode(',', preg_replace('/[^a-zA-Z0-9_\\-,]+/', '', $exclude));
         $filters = $this->excludeFilters($filters, $exclude);
     } else {
         $exclude = array();
     }
     $categoriesOrder = Mage::getStoreConfig('amshopby/general/categories_order');
     /*
      * Hide categories block from layered navigation
      */
     if ($categoriesOrder < 0) {
         $exclude[] = 'category';
     }
     // option ids
     $ids = array();
     foreach ($filters as $f) {
         //
         if ($f instanceof Mage_Catalog_Block_Layer_Filter_Category) {
             $f->setPosition($categoriesOrder);
         } else {
             if ($f->getItemsCount()) {
                 $items = $f->getItems();
                 if (isset($items[0])) {
                     $f->setPosition($items[0]->getFilter()->getAttributeModel()->getPosition());
                 }
             } else {
                 $f->setPosition(0);
             }
         }
         if ($f->getItemsCount() && $f instanceof Mage_Catalog_Block_Layer_Filter_Attribute) {
             $items = $f->getItems();
             foreach ($items as $item) {
                 $vals = array_merge(explode(',', $item->getValue()), array($item->getOptionId()));
                 foreach ($vals as $v) {
                     $ids[] = $v;
                 }
             }
         }
     }
     // images of filter values
     $optionsCollection = Mage::getResourceModel('amshopby/value_collection')->addFieldToFilter('option_id', array('in' => $ids))->load();
     $options = array();
     foreach ($optionsCollection as $row) {
         $options[$row->getOptionId()] = array('img' => $row->getImgSmall(), 'img_hover' => $row->getImgSmallHover(), 'descr' => $row->getDescr());
     }
     $catId = $this->getLayer()->getCurrentCategory()->getId();
     // update filters with new properties
     $allSelected = array();
     $attributes = $this->_getAttributesSettings();
     foreach ($filters as $f) {
         if ($f->getItemsCount() && $f instanceof Mage_Catalog_Block_Layer_Filter_Attribute) {
             $items = $f->getItems();
             //add selected and image properties for all items
             $attributeCode = $items[0]->getFilter()->getAttributeModel()->getAttributeCode();
             $selectedValues = Mage::app()->getRequest()->getParam($attributeCode);
             if ($selectedValues) {
                 $selectedValues = explode(',', $selectedValues);
                 $f->setHasSelection(true);
                 $allSelected = array_merge($allSelected, $selectedValues);
             } else {
                 $selectedValues = array();
             }
             foreach ($items as $item) {
                 $optId = $item->getOptionId();
                 if (!empty($options[$optId]['img'])) {
                     $item->setImage($options[$optId]['img']);
                 }
                 if (!empty($options[$optId]['img_hover'])) {
                     $item->setImageHover($options[$optId]['img_hover']);
                 }
                 if (!empty($options[$optId]['descr'])) {
                     $item->setDescr($options[$optId]['descr']);
                 }
                 $item->setIsSelected(in_array($optId, $selectedValues));
             }
             $attributeId = $items[0]->getFilter()->getAttributeModel()->getId();
             if (isset($attributes[$attributeId])) {
                 $a = $attributes[$attributeId];
                 $f->setMaxOptions($a->getMaxOptions());
                 $f->setHideCounts($a->getHideCounts());
                 $f->setSortBy($a->getSortBy());
                 $f->setDisplayType($a->getDisplayType());
                 $f->setSingleChoice($a->getSingleChoice());
                 $f->setSeoRel($a->getSeoRel());
                 // sinse version 1.4.7
                 $f->setDependOn($a->getDependOn());
                 $f->setDependOnAttribute($a->getDependOnAttribute());
                 $f->setAttributeCode($attributeCode);
                 // sinse version 2.0
                 $f->setCollapsed($a->getCollapsed());
                 $f->setComment($a->getComment());
                 $cats = trim(str_replace(' ', '', $a->getExcludeFrom()));
                 if ($cats) {
                     if (in_array($catId, explode(',', $cats))) {
                         $exclude[] = $attributeCode;
                     }
                 }
             }
             //if attibute
         } elseif ($f instanceof Mage_Catalog_Block_Layer_Filter_Category) {
             $f->setDisplayType(Mage::getStoreConfig('amshopby/general/categories_type'));
             $f->setTemplate('amshopby/category.phtml');
             $f->setHasSelection($catId != $this->getLayer()->getCurrentStore()->getRootCategoryId());
             $f->setCollapsed(Mage::getStoreConfig('amshopby/general/categories_collapsed'));
         } elseif ($f instanceof Mage_Catalog_Block_Layer_Filter_Price) {
             $attrCode = $f->getAttributeModel()->getAttributeCode();
             if ('price' == $attrCode) {
                 $f->setDisplayType(Mage::getStoreConfig('amshopby/general/price_type'));
                 $f->setTemplate('amshopby/price.phtml');
                 $f->setSliderType(Mage::getStoreConfig('amshopby/general/slider_type'));
                 $f->setHasSelection(Mage::app()->getRequest()->getParam($attrCode));
                 $currencySign = Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol();
                 $f->setValueLabel($currencySign);
                 $f->setValuePlacement('before');
                 $f->setFromToWidget(Mage::getStoreConfig('amshopby/general/price_from_to'));
                 $f->setAttributeCode($attrCode);
                 $f->setCollapsed(Mage::getStoreConfig('amshopby/general/price_collapsed'));
                 $f->setSeoRel(Mage::helper('amshopby')->getSeoPriceRelNofollow());
             }
         } elseif ($f instanceof Mage_Catalog_Block_Layer_Filter_Decimal) {
             if ($f->getItemsCount()) {
                 $items = $f->getItems();
                 $attributeId = $items[0]->getFilter()->getAttributeModel()->getId();
                 $attributeCode = $items[0]->getFilter()->getAttributeModel()->getAttributeCode();
                 if (isset($attributes[$attributeId])) {
                     $a = $attributes[$attributeId];
                     $cats = trim(str_replace(' ', '', $a->getExcludeFrom()));
                     $excluded = false;
                     if ($cats) {
                         if (in_array($catId, explode(',', $cats))) {
                             $exclude[] = $attributeCode;
                             $excluded = true;
                         }
                     }
                     if (!$excluded) {
                         $f->setHideCounts($a->getHideCounts());
                         $f->setDisplayType($a->getDisplayType());
                         $f->setSeoRel($a->getSeoRel());
                         // sinse version 1.4.7
                         $f->setDependOn($a->getDependOn());
                         $f->setDependOnAttribute($a->getDependOnAttribute());
                         // sinse version 2.0
                         $f->setCollapsed($a->getCollapsed());
                         $f->setComment($a->getComment());
                         $f->setFromToWidget($a->getFromToWidget());
                         $f->setSliderType($a->getSliderType());
                         $f->setValueLabel($a->getValueLabel());
                         $f->setValuePlacement($a->getValuePlacement());
                         $f->setAttributeCode($attributeCode);
                         $f->setHasSelection(Mage::app()->getRequest()->getParam($attributeCode));
                     }
                 }
             }
             $f->setTemplate('amshopby/price.phtml');
         }
     }
     //exclude dependant, sinse 1.4.7
     foreach ($filters as $f) {
         $ids = trim(str_replace(' ', '', $f->getDependOn()));
         $parentAttributes = trim(str_replace(' ', '', $f->getDependOnAttribute()));
         if (!$ids && !$parentAttributes) {
             continue;
         }
         if (!empty($ids)) {
             $ids = explode(',', $ids);
             if (!array_intersect($allSelected, $ids)) {
                 $exclude[] = $f->getAttributeCode();
             }
         }
         if (!empty($parentAttributes)) {
             $parentAttributes = explode(',', $parentAttributes);
             foreach ($parentAttributes as $parentAttribute) {
                 if (Mage::app()->getRequest()->getParam($parentAttribute)) {
                     $attributePresent = true;
                 }
             }
             if (!$attributePresent) {
                 $exclude[] = $f->getAttributeCode();
             }
         }
     }
     // 1.2.7 exclude some filters from the selected categories
     $filters = $this->excludeFilters($filters, $exclude);
     usort($filters, array($this, 'sortFiltersByOrder'));
     $this->_filterBlocks = $filters;
     return $filters;
 }
Example #8
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()) {
         //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($attribute->getStoreLabel());
                 //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();
 }