コード例 #1
0
 public function testGetItems()
 {
     $items = $this->_model->getItems();
     $this->assertInternalType('array', $items);
     $this->assertEquals(1, count($items));
     /** @var $item \Magento\Catalog\Model\Layer\Filter\Item */
     $item = $items[0];
     $this->assertInstanceOf('Magento\\Catalog\\Model\\Layer\\Filter\\Item', $item);
     $this->assertSame($this->_model, $item->getFilter());
     $this->assertEquals('Option Label', $item->getLabel());
     $this->assertEquals($this->_attributeOptionId, $item->getValue());
     $this->assertEquals(1, $item->getCount());
 }
コード例 #2
0
ファイル: Attribute.php プロジェクト: aiesh/magento2
 /**
  * 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);
 }
コード例 #3
0
 public function testGetItems()
 {
     $attributeCode = 'attributeCode';
     $attributeValue = 'attributeValue';
     $attributeLabel = 'attributeLabel';
     $this->attribute->expects($this->once())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->request->expects($this->once())->method('getParam')->with($attributeCode)->will($this->returnValue($attributeValue));
     $this->frontend->expects($this->once())->method('getOption')->with($attributeValue)->will($this->returnValue($attributeLabel));
     $filterItem = $this->createFilterItem(0, $attributeLabel, $attributeValue, 0);
     $this->state->expects($this->once())->method('addFilter')->with($filterItem)->will($this->returnSelf());
     $expectedFilterItems = [];
     $result = $this->target->apply($this->request)->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }
コード例 #4
0
 /**
  * @param string $label
  * @param mixed $value
  * @param int $count
  * @param null $selected
  * @param null $type
  * @return \Magento\Catalog\Model\Layer\Filter\Item
  */
 public function _createItem($label, $value, $count = 0, $selected = null, $type = null)
 {
     if ($this->bxDataHelper->isFilterLayoutEnabled($this->_layer)) {
         return $this->_filterItemFactory->create()->setFilter($this)->setLabel($label)->setValue($value)->setCount($count)->setSelected($selected)->setType($type);
     }
     return parent::_createItem($label, $value, $count);
 }