/**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     $categories = $filter->getLayer()->getCurrentCategory()->getAllChildren(true);
     $connection = $this->_getReadAdapter();
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select['cat'])) {
         $select = $base_select['cat'];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $where = array();
     $catIds = array();
     foreach ($categories as $category) {
         $catIds[] = $category;
     }
     $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->join(array('child_cat_index' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')), 'child_cat_index.category_id IN (' . implode(',', $catIds) . ') AND child_cat_index.product_id = e.entity_id', array('value' => 'category_id'));
     $fields = array('count' => 'COUNT(DISTINCT child_cat_index.product_id)');
     $select->columns($fields);
     $select->group('child_cat_index.category_id');
     return $connection->fetchPairs($select);
 }
Beispiel #2
0
 /**
  * Retrieve array with products counts per attribute option
  *
  * @param Mage_Catalog_Model_Layer_Filter_Attribute $filter
  * @return array
  */
 public function getCount($filter)
 {
     /** @var $layer EcommerceTeam_Sln_Model_Layer */
     $layer = $filter->getLayer();
     $connection = $this->_getReadAdapter();
     $select = $layer->getSelectWithoutFilter('cat');
     if (!$select) {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $where = array();
     $catIds = array();
     if ($this->_categories) {
         $catIds = $this->_categories;
     } else {
         $categories = $layer->getCurrentCategory()->getChildrenCategories();
         foreach ($categories as $category) {
             $catIds[] = $category->getEntityId();
         }
     }
     $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->join(array('child_cat_index' => Mage::getSingleton('core/resource')->getTableName('catalog/category_product_index')), 'child_cat_index.category_id IN (' . implode(',', $catIds) . ') AND child_cat_index.product_id = e.entity_id', array('value' => 'category_id'));
     $fields = array('count' => 'COUNT(DISTINCT child_cat_index.product_id)');
     $select->columns($fields);
     $select->group('child_cat_index.category_id');
     return $connection->fetchPairs($select);
 }
Beispiel #3
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();
     $base_select = $filter->getLayer()->getBaseSelect();
     if (isset($base_select['stock_status'])) {
         $select = $base_select['stock_status'];
     } else {
         $select = clone $filter->getLayer()->getProductCollection()->getSelect();
     }
     $select->reset(Zend_Db_Select::LIMIT_COUNT);
     $select->reset(Zend_Db_Select::LIMIT_OFFSET);
     $sql = $connection->fetchAll($select);
     $productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
     $product_ids = array();
     foreach ($sql as $item) {
         $product_ids[] = $item['entity_id'];
     }
     $collection = $productCollection->addAttributeToFilter('entity_id', array('in' => $product_ids));
     $collection->joinField('is_in_stock', 'cataloginventory/stock_item', 'is_in_stock', 'product_id=entity_id');
     $stockCount = array('instock' => 0, 'outofstock' => 0);
     foreach ($collection as $product) {
         if ((int) $product->getIsInStock() > 0) {
             $stockCount['instock']++;
         } else {
             $stockCount['outofstock']++;
         }
     }
     return $stockCount;
 }
Beispiel #4
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);
 }
Beispiel #5
0
 public function testApply()
 {
     $this->assertEmpty($this->_model->getLayer()->getState()->getFilters());
     $request = new Magento_Test_Request();
     $request->setParam('attribute', $this->_attributeOptionId);
     $this->_model->apply($request, new Mage_Core_Block_Text());
     $this->assertNotEmpty($this->_model->getLayer()->getState()->getFilters());
 }
Beispiel #6
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);
 }
 /**
  * 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);
 }
Beispiel #9
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';
     $select = $filter->getLayer()->getSelectWithoutFilter($attribute->getAttributeCode());
     if (!$select) {
         $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::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");
     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);
     $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()));
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => new Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")))->group("{$tableAlias}.value");
     echo $select;
     return $connection->fetchPairs($select);
 }
Beispiel #11
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
     //
     $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);
     //
     $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()));
     $select->join(array($tableAlias => $this->textfieldTable), 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)
 {
     // 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() . '_idy';
     $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(Zend_Db_Select::FROM);
     $_all_conditions = $this->getConditions();
     foreach ($_from as $index => $condition) {
         if ($index == $attribute->getAttributeCode() . "_idx") {
             unset($_from[$attribute->getAttributeCode() . "_idx"]);
         }
     }
     $select->setPart(Zend_Db_Select::FROM, $_from);
     $select->join(array($tableAlias => $this->getMainTable()), join(' AND ', $conditions), array('value', 'count' => "COUNT( distinct({$tableAlias}.entity_id))"))->group("{$tableAlias}.value");
     $select->distinct();
     return $connection->fetchPairs($select);
 }