示例#1
1
 public function getFilterableAttributes()
 {
     $collection = parent::getFilterableAttributes();
     if ($collection instanceof Mage_Catalog_Model_Resource_Product_Attribute_Collection) {
         $attrUrlKeyModel = Mage::getResourceModel('sm_shopby/attribute_urlkey');
         $attrUrlKeyModel->preloadAttributesOptions($collection);
     }
     return $collection;
 }
 /**
  * Get collection of all filterable attributes for layer products set
  *
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection
  */
 public function getFilterableAttributes()
 {
     $collection = parent::getFilterableAttributes();
     if ($collection instanceof Mage_Catalog_Model_Resource_Product_Attribute_Collection) {
         // Pre-loads all needed attributes at once
         $attrUrlKeyModel = Mage::getResourceModel('catalin_seo/attribute_urlkey');
         $attrUrlKeyModel->preloadAttributesOptions($collection);
     }
     return $collection;
 }
 /**
  * @param Mage_Catalog_Model_Layer $layerModel
  * @return bool
  */
 protected function _isSliderApplied($layerModel)
 {
     if (!$layerModel->hasData('m_is_slider_applied')) {
         $result = false;
         foreach ($layerModel->getState()->getFilters() as $item) {
             /* @var $item Mana_Filters_Model_Item */
             if ($item->getFilter()->getFilterOptions() && in_array($item->getFilter()->getFilterOptions()->getDisplay(), array('slider', 'range', 'min_max_slider'))) {
                 $result = true;
                 break;
             }
         }
         $layerModel->setData('m_is_slider_applied', $result);
     }
     return $layerModel->getData('m_is_slider_applied');
 }
示例#4
0
 /**
  * Get default tags for current layer state
  *
  * @param   array $additionalTags
  * @return  array
  *
  * @todo find out why this is necessary.
  */
 public function getStateTags(array $additionalTags = array())
 {
     if (Mage::helper('conversionpro')->getIsEngineAvailableForNavigation()) {
         $additionalTags = array_merge($additionalTags, array(Mage_Catalog_Model_Category::CACHE_TAG . $this->getCurrentCategory()->getId() . '_SEARCH'));
     }
     return parent::getStateTags($additionalTags);
 }
 /**
  * Stop the splash page attribute from dsplaying in the filter options
  *
  * @param   Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection $collection
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection
  */
 protected function _prepareAttributeCollection($collection)
 {
     parent::_prepareAttributeCollection($collection);
     if ($splash = $this->getSplashPage()) {
         $collection->addFieldToFilter('attribute_code', array('neq' => $splash->getAttributeCode()));
     }
     return $collection;
 }
 /**
  * Prepare price filter model
  *
  * @param Magento_Test_Request|null $request
  * @return void
  */
 protected function _prepareFilter($request = null)
 {
     $layer = new Mage_Catalog_Model_Layer();
     $layer->setCurrentCategory(4);
     $layer->setState(new Mage_Catalog_Model_Layer_State());
     $filter = new Mage_Catalog_Model_Layer_Filter_Price();
     $filter->setLayer($layer)->setAttributeModel(new Varien_Object(array('attribute_code' => 'price')));
     if (!is_null($request)) {
         $filter->apply($request, new Mage_Core_Block_Text());
         $interval = $filter->getInterval();
         if ($interval) {
             $this->_model->setLimits($interval[0], $interval[1]);
         }
     }
     $collection = $layer->getProductCollection();
     $this->_model->setPricesModel($filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
 }
示例#7
0
 public function testGetState()
 {
     $state = $this->_model->getState();
     $this->assertInstanceOf('Mage_Catalog_Model_Layer_State', $state);
     $this->assertSame($state, $this->_model->getState());
     $state = new Mage_Catalog_Model_Layer_State();
     $this->_model->setState($state);
     // $this->_model->setData('state', state);
     $this->assertSame($state, $this->_model->getState());
 }
示例#8
0
 /**
  * @dataProvider pricesSegmentationDataProvider
  */
 public function testPricesSegmentation($categoryId, $intervalsNumber, $intervalItems)
 {
     $this->_layer->setCurrentCategory($categoryId);
     $collection = $this->_layer->getProductCollection();
     $memoryUsedBefore = memory_get_usage();
     $this->_model->setPricesModel($this->_filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize());
     if (!is_null($intervalsNumber)) {
         $this->assertEquals($intervalsNumber, $this->_model->getIntervalsNumber());
     }
     $items = $this->_model->calculateSeparators();
     $this->assertEquals(array_keys($intervalItems), array_keys($items));
     for ($i = 0; $i < count($intervalItems); ++$i) {
         $this->assertInternalType('array', $items[$i]);
         $this->assertEquals($intervalItems[$i]['from'], $items[$i]['from']);
         $this->assertEquals($intervalItems[$i]['to'], $items[$i]['to']);
         $this->assertEquals($intervalItems[$i]['count'], $items[$i]['count']);
     }
     // Algorythm should use less than 10M
     $this->assertLessThan(10 * 1024 * 1024, memory_get_usage() - $memoryUsedBefore);
 }
示例#9
0
 public function prepareProductCollection($collection)
 {
     parent::prepareProductCollection($collection);
     if (!Mage::helper('rayfox_catalog')->isSortOutOfStockProductsAtBottomEnabled()) {
         return $this;
     }
     $websiteId = Mage::app()->getStore()->getWebsiteId();
     if (Mage::helper('catalog')->isModuleEnabled('Mage_CatalogInventory')) {
         $collection->joinTable(array('cisi' => 'cataloginventory/stock_status'), 'product_id=entity_id', 'stock_status', array('website_id' => $websiteId), 'left');
     }
     $collection->getSelect()->order('stock_status desc');
     return $this;
 }
 /**
  * Initialize product collection
  *
  * @param Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Collection $collection Product collection.
  *
  * @return Mage_Catalog_Model_Layer
  */
 public function prepareProductCollection($collection)
 {
     $query = $collection->getSearchEngineQuery();
     $allowedVisibilities = Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds();
     $query->addFilter('terms', array('visibility' => $allowedVisibilities));
     $allowedStatuses = Mage::getSingleton('catalog/product_status')->getVisibleStatusIds();
     $query->addFilter('terms', array('status' => $allowedStatuses));
     if (Mage::helper('cataloginventory')->isShowOutOfStock() == false) {
         $query->addFilter('terms', array('in_stock' => 1));
     }
     $query->setQueryType('category_products_layer');
     return parent::prepareProductCollection($collection);
 }
示例#11
0
 public function apply()
 {
     parent::apply();
     $filters = $this->getState()->getFilters();
     if (!empty($filters)) {
         $select = $this->getProductCollection()->getSelect();
         $fromPart = $select->getPart(Zend_Db_Select::FROM);
         if (!empty($fromPart['cat_index']['joinCondition'])) {
             $fromPart['cat_index']['joinCondition'] = str_replace('cat_index.visibility IN(2, 4)', 'cat_index.visibility IN(2, 3, 4)', $fromPart['cat_index']['joinCondition']);
         }
         $select->setPart(Zend_Db_Select::FROM, $fromPart);
     }
     return $this;
 }
示例#12
0
 /**
  * Prepare product collection
  *
  * @param Mage_Catalog_Model_Resource_Eav_Resource_Product_Collection $collection
  * @return Mage_Catalog_Model_Layer
  */
 public function prepareProductCollection($collection)
 {
     if (!Mage::helper('searchanise/ApiSe')->checkSearchaniseResult(true)) {
         return parent::prepareProductCollection($collection);
     }
     if (method_exists($collection, 'setSearchaniseRequest')) {
         $collection->setSearchaniseRequest(Mage::helper('searchanise')->getSearchaniseRequest());
     }
     if (!method_exists($collection, 'checkSearchaniseResult') || !$collection->checkSearchaniseResult()) {
         return parent::prepareProductCollection($collection);
     }
     $collection->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())->addSearchaniseFilter()->addMinimalPrice()->addFinalPrice()->addTaxPercents()->addUrlRewrite($this->getCurrentCategory()->getId());
     Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
     Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
     return $this;
 }
示例#13
0
 /**
  * Stop the splash page attribute from dsplaying in the filter options
  *
  * @param   Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection $collection
  * @return  Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection
  */
 protected function _prepareAttributeCollection($collection)
 {
     parent::_prepareAttributeCollection($collection);
     if (($page = $this->getPage()) !== false) {
         $optionFilters = $page->getOptionFilters();
         if ($optionFilters && is_array($optionFilters)) {
             foreach ($optionFilters as $attributeCode => $filter) {
                 if (isset($filter['include_in_layered_nav']) && (int) $filter['include_in_layered_nav'] === 1) {
                     unset($optionFilters[$attributeCode]);
                 }
             }
             $attributeCodes = array_keys($optionFilters);
             if (count($attributeCodes) > 0) {
                 $collection->addFieldToFilter('attribute_code', array('nin' => array_keys($optionFilters)));
             }
         }
     }
     return $collection;
 }
示例#14
0
 protected function _prepareAttributeCollection($collection)
 {
     $collection = parent::_prepareAttributeCollection($collection);
     $collection->addIsFilterableFilter();
     $tableAlias = 'gomage_nav_attr';
     $collection->getSelect()->joinLeft(array($tableAlias => Mage::getSingleton('core/resource')->getTableName('gomage_navigation_attribute')), "`main_table`.`attribute_id` = `{$tableAlias}`.`attribute_id`", array('filter_type', 'image_align', 'image_width', 'image_height', 'show_minimized', 'show_image_name', 'show_help', 'show_checkbox', 'popup_text', 'popup_width', 'popup_height', 'filter_reset', 'is_ajax', 'inblock_height', 'filter_button'));
     $connection = Mage::getSingleton('core/resource')->getConnection('read');
     $table = Mage::getSingleton('core/resource')->getTableName('gomage_navigation_attribute_option');
     foreach ($collection as $attribute) {
         $option_images = array();
         $attribute_id = $attribute->getId();
         $_option_images = $connection->fetchAll("SELECT `option_id`, `filename` FROM {$table} WHERE `attribute_id` = {$attribute_id};");
         foreach ($_option_images as $imageInfo) {
             $option_images[$imageInfo['option_id']] = $imageInfo['filename'];
         }
         $attribute->setOptionImages($option_images);
     }
     return $collection;
 }
示例#15
0
 public function getFilterableAttributes()
 {
     if (Mage::helper('itoris_layerednavigation')->isEnabledThirdEngineSearch()) {
         $setIds = $this->_getSetIds();
         if (!$setIds) {
             return array();
         }
         /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Collection */
         $collection = Mage::getResourceModel('catalog/product_attribute_collection')->setItemObjectClass('catalog/resource_eav_attribute');
         if (Mage::helper('enterprise_search')->getTaxInfluence()) {
             $collection->removePriceFilter();
         }
         $collection->setAttributeSetFilter($setIds)->addStoreLabel(Mage::app()->getStore()->getId())->setOrder('position', 'ASC');
         $collection = $this->_prepareAttributeCollection($collection);
         $collection->addIsFilterableInSearchFilter();
         $collection->load();
         return $collection;
     } else {
         return parent::getFilterableAttributes();
     }
 }
示例#16
0
 public function prepareProductCollection($collection)
 {
     parent::prepareProductCollection($collection);
     $collection->getSelect()->where('price_index.final_price < price_index.price');
     return $this;
 }
 /**
  * Get default tags for current layer state
  *
  * @param   array $additionalTags
  * @return  array
  */
 public function getStateTags(array $additionalTags = array())
 {
     $additionalTags = array_merge($additionalTags, array(Mage_Catalog_Model_Category::CACHE_TAG . $this->getCurrentCategory()->getId() . '_SEARCH'));
     return parent::getStateTags($additionalTags);
 }
示例#18
0
 /**
  * Add advanced data to collection
  *
  * @param  $collection
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Attribute_Collection
  */
 protected function _prepareAttributeCollection($collection)
 {
     $dataTable = 'ecommerceteam_sln_data';
     $collection = parent::_prepareAttributeCollection($collection);
     $collection->addIsFilterableFilter();
     $collection->getSelect()->joinLeft(array($dataTable => Mage::getSingleton('core/resource')->getTableName('ecommerceteam_sln_attribute_data')), "`main_table`.`attribute_id` = `{$dataTable}`.`attribute_id`", array('frontend_type' => 'frontend_type', 'navigation_group' => 'group_id', 'comment' => 'comment', 'options_limit' => 'options_limit'));
     return $collection;
 }
示例#19
0
 /**
  * Prepare attribute for use in layered navigation
  *
  * @param   Mage_Eav_Model_Entity_Attribute $attribute
  * @return  Mage_Eav_Model_Entity_Attribute
  */
 protected function _prepareAttribute($attribute)
 {
     $attribute = parent::_prepareAttribute($attribute);
     $attribute->setIsFilterable(Mage_Catalog_Model_Layer_Filter_Attribute::OPTIONS_ONLY_WITH_RESULTS);
     return $attribute;
 }
示例#20
0
 public function apply()
 {
     $this->udApplied = true;
     return parent::apply();
 }