示例#1
0
 /**
  * Retrieve clean select with joined index table
  * Joined table has index
  *
  * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter
  * @return Varien_Db_Select
  */
 protected function _getSelect($filter)
 {
     $collection = $filter->getLayer()->getProductCollection();
     // clone select from collection with filters
     $select = clone $collection->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $attributeId = $filter->getAttributeModel()->getId();
     $storeId = $collection->getStoreId();
     $select->join(array('decimal_index' => $this->getMainTable()), 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), array());
     $code = $filter->getAttributeModel()->getAttributeCode();
     $field = $code . "_idx.value";
     /*
      * Reset where condition of current filter
      */
     $oldWhere = $select->getPart(Varien_Db_Select::WHERE);
     $newWhere = array();
     foreach ($oldWhere as $cond) {
         if (false === strpos($cond, $field)) {
             $newWhere[] = $cond;
         }
     }
     if ($newWhere && substr($newWhere[0], 0, 3) == 'AND') {
         $newWhere[0] = substr($newWhere[0], 3);
     }
     $select->setPart(Varien_Db_Select::WHERE, $newWhere);
     return $select;
 }
示例#2
0
 /**
  * Retrieve clean select with joined index table
  * Joined table has index
  *
  * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter
  * @return Varien_Db_Select
  */
 protected function _getSelect($filter)
 {
     $collection = $filter->getLayer()->getProductCollection();
     // clone select from collection with filters
     $select = clone $collection->getSelect();
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $attributeId = $filter->getAttributeModel()->getId();
     $storeId = $collection->getStoreId();
     $select->join(array('decimal_index' => $this->getMainTable()), 'e.entity_id = decimal_index.entity_id' . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.attribute_id = ?', $attributeId) . ' AND ' . $this->_getReadAdapter()->quoteInto('decimal_index.store_id = ?', $storeId), array());
     return $select;
 }
示例#3
0
 /**
  * Renders the decimal ranges.
  *
  * @param int $range
  * @param float $value
  * @return string
  */
 protected function _renderDecimalRanges($range, $value)
 {
     /** @var $attributes Mage_Catalog_Model_Resource_Eav_Attribute */
     $attributes = $this->getAttributeModel();
     if ($attributes->getFrontendInput() == 'price') {
         return parent::_renderDecimalRanges($range, $value);
     }
     $from = ($value - 1) * $range;
     $to = $value * $range;
     if ($from != $to) {
         $to -= 0.01;
     }
     $to = Zend_Locale_Format::toFloat($to, array('locale' => Mage::helper('nanowebg_elasticsearch')->getLocale()));
     return Mage::helper('catalog')->__('%s - %s', $from, $to);
 }
示例#4
0
 /**
  * @dataProvider getRangeItemCountsDataProvider
  */
 public function testGetRangeItemCounts($inputRange, $expectedItemCounts)
 {
     $this->assertEquals($expectedItemCounts, $this->_model->getRangeItemCounts($inputRange));
 }
示例#5
0
 /**
  * Retrieve clean select with joined index table
  *
  * Joined table has index
  *
  * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter
  * @return Varien_Db_Select
  */
 protected function _getSelect($filter)
 {
     $_select = $filter->getLayer()->getSelectWithoutFilter($filter->getRequestVar());
     if ($_select) {
         $select = clone $_select;
     } else {
         $collection = $filter->getLayer()->getProductCollection();
         $select = clone $collection->getSelect();
     }
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $attributeId = $filter->getAttributeModel()->getId();
     $storeId = Mage::app()->getStore()->getId();
     $select->join(array('decimal_index' => $this->getMainTable()), "e.entity_id=decimal_index.entity_id AND decimal_index.attribute_id={$attributeId}" . " AND decimal_index.store_id={$storeId}", array());
     return $select;
 }
示例#6
0
 /**
  * Retrieve clean select with joined index table
  *
  * Joined table has index
  *
  * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter
  * @return Varien_Db_Select
  */
 protected function _getSelect($filter)
 {
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select[$filter->getRequestVar()])) {
         $select = $base_select[$filter->getRequestVar()];
     } else {
         $collection = $filter->getLayer()->getProductCollection();
         $select = clone $collection->getSelect();
     }
     // reset columns, order and limitation conditions
     $select->reset(Zend_Db_Select::COLUMNS);
     $select->reset(Zend_Db_Select::ORDER);
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $select->reset(Zend_Db_Select::GROUP);
     $select->reset(Zend_Db_Select::WHERE);
     $attributeId = $filter->getAttributeModel()->getId();
     $storeId = Mage::app()->getStore()->getId();
     $select->join(array('decimal_index' => $this->getMainTable()), "e.entity_id=decimal_index.entity_id AND decimal_index.attribute_id={$attributeId}" . " AND decimal_index.store_id={$storeId}", array());
     $_collection = clone $filter->getLayer()->getProductCollection();
     $searched_entity_ids = $_collection->load()->getSearchedEntityIds();
     if ($searched_entity_ids && is_array($searched_entity_ids) && count($searched_entity_ids)) {
         $select->where('e.entity_id IN (?)', $searched_entity_ids);
     }
     return $select;
 }
示例#7
0
 /**
  * Apply attribute filter to product collection
  *
  * @param Mage_Catalog_Model_Layer_Filter_Decimal $filter
  * @param float $range
  * @param int $index
  * @return Mage_Catalog_Model_Resource_Layer_Filter_Decimal
  */
 public function applyFilterToCollection($filter, $ranges, $index)
 {
     $collection = $filter->getLayer()->getProductCollection();
     $attribute = $filter->getAttributeModel();
     $connection = $this->_getReadAdapter();
     $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $collection->getStoreId()));
     $collection->getSelect()->join(array($tableAlias => $this->getMainTable()), implode(' AND ', $conditions), array());
     $_conditions = array();
     foreach ($ranges as $_interval) {
         $index = (int) $_interval[0];
         $range = (int) $_interval[1];
         $_condition = " ( {$tableAlias}.value >= " . $range * ($index - 1) . " AND  {$tableAlias}.value < " . $range * $index . " ) ";
         /* $collection->getSelect()
             ->where("{$tableAlias}.value >= ?", ($range * ($index - 1)))
             ->where("{$tableAlias}.value < ?", ($range * $index));
            */
         $_conditions[] = $_condition;
     }
     if (count($_conditions)) {
         $_att_condition = join(" OR ", $_conditions);
         $collection->getSelect()->where(" ( " . $_att_condition . " ) ");
     }
     return $this;
 }
示例#8
0
 public function getRange()
 {
     $settings = $this->getSettings();
     if (!empty($settings['range'])) {
         return $settings['range'];
     }
     return parent::getRange();
 }
示例#9
0
 /**
  * Retrieve range for building filter steps
  *
  * @return int
  */
 public function getRange()
 {
     if ($range = intval(Mage::helper('ecommerceteam_sln')->getConfigData('pricerange'))) {
         if ($range > 0) {
             return $range;
         }
     }
     return parent::getRange();
 }