/** * @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; }
/** * @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); }
/** * 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); }