Solución:
crear un archivo llamado Rating.php a partir de ahora lo hice en el módulo principal solo que se puede implementar en su módulo personalizado vendor magento module-catalog Model Layer Filter Rating.php
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagentoCatalogModelLayerFilter;
use MagentoCatalogModelCategory as CategoryModel;
use MagentoCatalogModelCategoryFactory as CategoryModelFactory;
use MagentoCatalogModelLayer;
use MagentoFrameworkRegistry;
/**
* Layer category filter
*
* @author Magento Core Team <[email protected]>
*/
class Rating extends MagentoCatalogModelLayerFilterAbstractFilter
{
/**
* Active Category Id
*
* @var int
*/
protected $_categoryId;
/**
* Applied Category
*
* @var MagentoCatalogModelCategory
*/
protected $_appliedCategory;
/**
* Core data
*
* @var MagentoFrameworkEscaper
*/
protected $_escaper;
/**
* Core registry
*
* @var MagentoFrameworkRegistry
*/
protected $_coreRegistry;
/**
* @var CategoryDataProvider
*/
private $dataProvider;
/**
* Construct
*
* @param MagentoCatalogModelLayerFilterItemFactory $filterItemFactory
* @param MagentoStoreModelStoreManagerInterface $storeManager
* @param MagentoCatalogModelLayer $layer
* @param MagentoCatalogModelLayerFilterItemDataBuilder $itemDataBuilder
* @param MagentoFrameworkEscaper $escaper
* @param CategoryFactory $categoryDataProviderFactory
* @param array $data
*/
public function __construct(
MagentoCatalogModelLayerFilterItemFactory $filterItemFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoCatalogModelLayer $layer,
MagentoCatalogModelLayerFilterItemDataBuilder $itemDataBuilder,
MagentoFrameworkEscaper $escaper,
array $data = []
) {
parent::__construct($filterItemFactory, $storeManager, $layer, $itemDataBuilder, $data);
$this->_escaper = $escaper;
$this->_requestVar="rat";
}
/**
* Get filter value for reset current filter state
*
* @return mixed|null
*/
public function getResetValue()
{
return $this->dataProvider->getResetValue();
}
/**
* Apply category filter to layer
*
* @param MagentoFrameworkAppRequestInterface $request
* @return $this
*/
public function apply(MagentoFrameworkAppRequestInterface $request)
{
/**
* Filter must be string: $fromPrice-$toPrice
*/
$filter = $request->getParam($this->getRequestVar());
if (!$filter) {
return $this;
}
$filter = explode('-', $filter);
list($from, $to) = $filter;
$collection = $this->getLayer()->getProductCollection();
$collection->getSelect()->joinLeft(array('rova'=> 'rating_option_vote_aggregated'),'e.entity_id =rova.entity_pk_value',array("percent"))
->where("rova.percent between ".$from." and ".$to)
->group('e.entity_id');
//$this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
//$collection->printlogquery(true);
return $this;
}
/**
* Get filter name
*
* @return MagentoFrameworkPhrase
*/
public function getName()
{
return __('Rating');
}
/**
* Get data array for building attribute filter items
*
* @throws MagentoFrameworkExceptionLocalizedException
* @return array
*/
protected function _getItemsData()
{
$facets = array(
'0-20'=>'1 Start',
'21-40'=>'2 Start',
'41-60'=>'3 Start',
'61-80'=>'4 Start',
'81-100'=>'5 Start'
);
$collection = $this->getLayer()->getProductCollection();
$data = [];
if (count($facets) > 1) { // two range minimum
$i=1;
foreach ($facets as $key => $label) {
$count=$this->prepareData($key,$collection,$i);
$i++;
$this->itemDataBuilder->addItemData(
$this->_escaper->escapeHtml($label),
$key,
$count
);
}
}
return $this->itemDataBuilder->build();
/* $this->itemDataBuilder->addItemData(
$this->tagFilter->filter('5 star'),
'80-100',
1
);
return $this->itemDataBuilder->build(); */
}
/**
* @param string $key
* @param int $count
* @return array
*/
private function prepareData($filter,$collection,$i)
{
$filter = explode('-', $filter);
list($from, $to) = $filter;
/** @var MagentoCatalogSearchModelResourceModelFulltextCollection $productCollection */
$collection->getSelect()->joinLeft(array('rova'.$i=> 'rating_option_vote_aggregated'),'e.entity_id =rova'.$i.'.entity_pk_value',array("percent"))
->where("rova".$i.".percent between ".$from." and ".$to)
->group('e.entity_id');
//$collection->printlogquery(true); echo '<br>............................<br>';
return $collection->getSize();
}
}
y en vendor magento module-catalog Model Layer FilterList.php agregue la opción de filtro de calificación si escribió un módulo personalizado agregue esta opción por complemento
public function getFilters(MagentoCatalogModelLayer $layer)
{
if (!count($this->filters)) {
$this->filters = [
$this->objectManager->create($this->filterTypes[self::CATEGORY_FILTER], ['layer' => $layer]),
$this->objectManager->create($this->filterTypes['MagentoCatalogModelLayerFilterRating'], ['layer' => $layer]),
];
foreach ($this->filterableAttributes->getList() as $attribute) {
$this->filters[] = $this->createAttributeFilter($attribute, $layer);
}
}
return $this->filters;
}
Traerá un filtro de calificación y un filtro con la colección de productos, pero aún así el recuento de productos y agregará al estado que no he terminado si alguien lo hizo, por favor, colóquelo.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)