Product alphabet filter option in magento 2
ref video : https://www.loom.com/share/0b1de140088d41279ae2ec1d4222f3b2
Product alphabet filter option in magento 2
ref video : https://www.loom.com/share/0b1de140088d41279ae2ec1d4222f3b2
if ($this->getCurrentOrder()) {
// Get String Name To Filter
$postdata = Mage::app()->getRequest()->getParam('alpha');
// if postdata is not empty and not equal to all then ....
if( $postdata != '' && $postdata != 'all' )
{
// Custom Set Attribute To Filter Using Name
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection())->addAttributeToFilter(array(array('attribute'=>'name', 'like'=>$postdata.'%')));
}
else
{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}```
$collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToFilter('name', array('like' => 'h%'));
Commented
Nov 18, 2020 at 10:30
public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
{
$filter = $request->getParam($this->_requestVar);
if (is_array($filter)) {
return $this;
}
// MP customized
$filter = explode(',', $filter);
if (count($filter) < 1) {
return $this;
} else if ($filter == '') {
return $this;
}
if (count($filter) == 1) {
$filter = $filter[0];
}
if ($filter == '') {
return $this;
}
if ($filter) {
$this->_initItems();
$this->_getResource()->applyFilterToCollection($this, $filter);
$text = '';
foreach ($filter as $att) {
($text == '') ? $text = $this->_getOptionText($att) : $text .= ', '.$this->_getOptionText($att);
}
if (count($filter) == 1) {
$text = $this->_getOptionText($filter);
}
$this->getLayer()->getState()->addFilter($this->_createItem($text, $filter));
}
// End MP customized
return $this;
}```