/** * @param FilterInterface $filter * @return string */ public function render(FilterInterface $filter) { $this->assign('filterItems', $filter->getItems()); $html = $this->_toHtml(); $this->assign('filterItems', []); return $html; }
/** * @SuppressWarnings(PHPMD.UnusedFormalParameter) * @param \Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject * @param \Closure $proceed * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @return mixed * @throws \Magento\Framework\Exception\LocalizedException */ public function aroundRender(\Magento\LayeredNavigation\Block\Navigation\FilterRenderer $subject, \Closure $proceed, \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter) { if ($filter->hasAttributeModel()) { if ($this->swatchHelper->isSwatchAttribute($filter->getAttributeModel())) { return $this->layout->createBlock($this->block)->setSwatchFilter($filter)->toHtml(); } } return $proceed($filter); }
/** * {@inheritDoc} */ public function render(FilterInterface $filter) { $html = ''; $this->filter = $filter; if ($this->canRenderFilter()) { $this->assign('filterItems', $filter->getItems()); $html = $this->_toHtml(); $this->assign('filterItems', []); } return $html; }
/** * @param FilterItem $subject * @param \Closure $proceed * @return string * @throws \Magento\Framework\Exception\LocalizedException * * @see \Magento\Catalog\Model\Layer\Filter\Item::getUrl() */ public function aroundGetUrl(FilterItem $subject, \Closure $proceed) { $this->filter = $subject->getFilter(); $this->eavAttribute = $this->filter->getAttributeModel(); if ($this->canBeSubstituted()) { $result = $this->urlHelper->getOptionUrl($this->eavAttribute, $subject->getValue()); } else { $result = $proceed(); } return $result; }
/** * Retrieve clean select with joined index table * Joined table has index * * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\Framework\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(['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), []); return $select; }
/** * Retrieve array with products counts per attribute option * * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @throws \Magento\Framework\Exception\LocalizedException * @return array */ public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter) { // clone select from collection with filters $select = clone $filter->getLayer()->getProductCollection()->getSelect(); // reset columns, order and limitation conditions $select->reset(\Magento\Framework\DB\Select::COLUMNS); $select->reset(\Magento\Framework\DB\Select::ORDER); $select->reset(\Magento\Framework\DB\Select::LIMIT_COUNT); $select->reset(\Magento\Framework\DB\Select::LIMIT_OFFSET); $connection = $this->getConnection(); $attribute = $filter->getAttributeModel(); $tableAlias = sprintf('%s_idx', $attribute->getAttributeCode()); $conditions = ["{$tableAlias}.entity_id = e.entity_id", $connection->quoteInto("{$tableAlias}.attribute_id = ?", $attribute->getAttributeId()), $connection->quoteInto("{$tableAlias}.store_id = ?", $filter->getStoreId())]; $select->join([$tableAlias => $this->getMainTable()], join(' AND ', $conditions), ['value', 'count' => new \Zend_Db_Expr("COUNT({$tableAlias}.entity_id)")])->group("{$tableAlias}.value"); return $connection->fetchPairs($select); }
/** * Apply price range filter to product collection * * @param \Magento\Catalog\Model\Layer\Filter\FilterInterface $filter * @param mixed $interval * @return $this */ public function applyPriceRange(\Magento\Catalog\Model\Layer\Filter\FilterInterface $filter, $interval) { if (!$interval) { return $this; } list($from, $to) = $interval; if ($from === '' && $to === '') { return $this; } $select = $filter->getLayer()->getProductCollection()->getSelect(); $priceExpr = $this->_getPriceExpression($select, false); if ($to !== '') { $to = (double) $to; if ($from == $to) { $to += self::MIN_POSSIBLE_PRICE; } } if ($from !== '') { $select->where($priceExpr . ' >= ' . $this->_getComparingValue($from)); } if ($to !== '') { $select->where($priceExpr . ' < ' . $this->_getComparingValue($to)); } return $this; }