public function testApply() { $this->assertEmpty($this->_model->getLayer()->getState()->getFilters()); $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); $request = $objectManager->get('Magento\\TestFramework\\Request'); $request->setParam('attribute', $this->_attributeOptionId); $this->_model->apply($request); $this->assertNotEmpty($this->_model->getLayer()->getState()->getFilters()); }
/** * Retrieve array with products counts per attribute option * * @param \Magento\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"); return $connection->fetchPairs($select); }