Exemplo n.º 1
0
 public function getItemsAsArray()
 {
     $items = array();
     foreach (parent::getItems() as $itemObject) {
         $item = array();
         $item['url'] = $this->htmlEscape($itemObject->getUrl());
         if ($this->getSingleChoice()) {
             /** sinse @version 1.3.0 */
             $query = array($this->getRequestValue() => $itemObject->getIsSelected() ? null : $itemObject->getOptionId(), Mage::getBlockSingleton('page/html_pager')->getPageVarName() => null);
             $item['url'] = Mage::helper('amshopby/url')->getFullUrl($query);
         }
         $item['label'] = $itemObject->getLabel();
         $item['descr'] = $itemObject->getDescr();
         $item['count'] = '';
         $item['countValue'] = $itemObject->getCount();
         if (!$this->getHideCounts()) {
             $item['count'] = ' (' . $itemObject->getCount() . ')';
         }
         $item['image'] = '';
         if ($itemObject->getImage()) {
             $item['image'] = Mage::getBaseUrl('media') . 'amshopby/' . $itemObject->getImage();
         }
         if ($itemObject->getImageHover()) {
             $item['image_hover'] = Mage::getBaseUrl('media') . 'amshopby/' . $itemObject->getImageHover();
         }
         $item['css'] = 'amshopby-attr';
         if (in_array($this->getDisplayType(), array(1, 3))) {
             //dropdown and images
             $item['css'] = '';
         }
         if ($itemObject->getIsSelected()) {
             $item['css'] .= '-selected';
             if (3 == $this->getDisplayType()) {
                 //dropdown
                 $item['css'] = 'selected';
             }
         }
         if ($this->getSeoRel()) {
             $item['css'] .= '" rel="nofollow';
         }
         $items[] = $item;
     }
     $sortBy = $this->getSortBy();
     $functions = array(1 => '_sortByName', 2 => '_sortByCounts');
     if (isset($functions[$sortBy])) {
         usort($items, array($this, $functions[$sortBy]));
     }
     // add less/more
     $max = $this->getMaxOptions();
     $i = 0;
     foreach ($items as $k => $item) {
         $style = '';
         if ($max && ++$i > $max) {
             $style = 'style="display:none" class="amshopby-attr-' . $this->getRequestValue() . '"';
         }
         $items[$k]['style'] = $style;
     }
     $this->setShowLessMore($max && $i > $max);
     return $items;
 }
Exemplo n.º 2
0
 public function getTheItems()
 {
     $items = array();
     foreach (parent::getItems() as $_item) {
         $attributeCode = $_item->getFilter()->getAttributeModel()->getAttributeCode();
         $optionId = $_item->getValueString();
         $attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter($attributeCode)->getFirstItem();
         $attributeId = $attributeInfo->getAttributeId();
         $_collection = Mage::getResourceModel('eav/entity_attribute_option_collection')->setPositionOrder('asc')->setAttributeFilter($attributeId)->setStoreFilter(0)->load();
         foreach ($_collection->toOptionArray() as $_cur_option) {
             if ($_cur_option['value'] == $optionId) {
                 $theLabel = $_cur_option['label'];
             }
         }
         preg_match_all('/((#?[A-Za-z0-9]+))/', $theLabel, $matches);
         if (count($matches[0]) > 0) {
             $color_value = $matches[1][count($matches[0]) - 1];
             $findme = '#';
             $pos = strpos($color_value, $findme);
         } else {
             $pos = false;
         }
         $item = array();
         $item['url'] = $this->htmlEscape($_item->getUrl());
         $item['label'] = $_item->getLabel();
         $item['code'] = $attributeCode;
         $item['count'] = '';
         if (!$this->getHideCounts()) {
             $item['count'] = ' (' . $_item->getCount() . ')';
         }
         $item['image'] = '';
         $item['bgcolor'] = '';
         if (Mage::helper('colorselectorplus')->getSwatchUrl($optionId)) {
             $item['image'] = Mage::helper('colorselectorplus')->getSwatchUrl($optionId);
         } elseif ($pos !== false) {
             $item['bgcolor'] = $color_value;
         } else {
             $item['image'] = Mage::helper('colorselectorplus')->getSwatchUrl('empty');
         }
         if ($_item->isSelected()) {
             $item['is_selected'] = 1;
         } else {
             $item['is_selected'] = 0;
         }
         $items[] = $item;
     }
     return $items;
 }
Exemplo n.º 3
0
 /** Implement custom sorting for items if configured
  * 
  * @see Mage_Catalog_Model_Layer_Filter_Abstract::getItems()
  * @author ksenevich@aitoc.com
  */
 public function getItems()
 {
     $items = parent::getItems();
     $featuredLimit = Mage::helper('adjnav/featured')->getFeaturedValuesLimit();
     $featuredLimitDisabled = $featuredLimit == 0;
     if (!Mage::helper('adjnav/featured')->isRangeValues()) {
         return $items;
     }
     $usesRanges = array();
     $names = array();
     $attributeId = $this->getAttributeModel()->getId();
     $optionUses = Mage::getModel('adjnav/eav_entity_attribute_option_stat')->getSortedOptions($attributeId);
     foreach ($items as $k => $item) {
         $item->setSortRange(0);
         if (isset($optionUses[$item->getValueString()])) {
             $item->setSortRange($optionUses[$item->getValueString()]);
         }
     }
     //usort($items, array($this, 'sortItems'));
     $featuredIndex = array();
     $names = array();
     foreach ($items as $k => $item) {
         $item->setSortRange(0);
         if ($k < $featuredLimit || $featuredLimitDisabled) {
             if ($featuredLimitDisabled) {
                 $item->setSortRange(1000000 - $k);
             } else {
                 $item->setSortRange($featuredLimit - $k);
             }
         }
     }
     //usort($items, array($this, 'sortItems'));
     return $items;
 }