示例#1
0
 /**
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->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);
     // Redefining join type to allow multiple attribute values on currently filtered attribute
     $fromPart = $select->getPart(Zend_Db_Select::FROM);
     foreach ($fromPart as $key => &$part) {
         if ($key == $filter->getAttributeModel()->getAttributeCode() . '_idx') {
             $part['joinType'] = Zend_Db_Select::LEFT_JOIN;
         }
     }
     unset($part);
     $select->reset(Zend_Db_Select::FROM);
     $select->setPart(Zend_Db_Select::FROM, $fromPart);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_index', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT(DISTINCT {$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
示例#2
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select[$attribute->getAttributeCode()])) {
         $select = $base_select[$attribute->getAttributeCode()];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->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);
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => "COUNT(DISTINCT {$tableAlias}.entity_id)"))->group("{$tableAlias}.value");
     $_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 $connection->fetchPairs($select);
 }
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter Filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->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);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $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 = ?", $filter->getStoreId()));
     $conditions = join(' AND ', $conditions);
     $fromParts = $select->getPart(Zend_Db_Select::FROM);
     if (isset($fromParts[$tableAlias])) {
         $conditionArray = explode(' AND ', $fromParts[$tableAlias]['joinCondition']);
         unset($conditionArray[count($conditionArray) - 1]);
         $conditions = implode(' AND ', $conditionArray);
         unset($fromParts[$tableAlias]);
         $select->setPart(Zend_Db_Select::FROM, $fromParts);
     }
     $select->join(array($tableAlias => $this->getMainTable()), $conditions, array('value', 'count' => new Zend_Db_Expr("COUNT(distinct {$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->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);
     // Removed below as this was causing wrong counts
     // Not sure if this will break other functionality
     // $select->reset(Zend_Db_Select::WHERE);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $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 = ?", $filter->getStoreId()));
     $from = $select->getPart('from');
     if (array_key_exists($tableAlias, $from)) {
         $select->reset(Zend_Db_Select::FROM);
         unset($from[$tableAlias]);
         $select->setPart(Zend_Db_Select::FROM, $from);
     }
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
示例#5
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->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);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = $attribute->getAttributeCode() . '_idx';
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => "COUNT({$tableAlias}.entity_id)"))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter, $requestVar = null)
 {
     // clone select from collection with filters
     $select = clone $filter->getLayer()->getProductCollection()->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);
     $connection = $this->_getReadAdapter();
     $attribute = $filter->getAttributeModel();
     $tableAlias = sprintf('%s_idxcount', $attribute->getAttributeCode());
     $conditions = array("{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId()));
     if (isset($requestVar)) {
         $options = $select->getPart('from');
         $select->reset(Zend_Db_Select::FROM);
         unset($options[$requestVar . '_idx']);
         $select->forFrom($options);
     }
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     return $connection->fetchPairs($select);
 }