0

Product alphabet filter option in magento 2

ref video : https://www.loom.com/share/0b1de140088d41279ae2ec1d4222f3b2

2 Answers 2

0
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());
}
}```
8
  • bro try this code lines put it into your block code where you your setCollection(). may this help you Commented Nov 18, 2020 at 10:17
  • bro i ask product you give order list ?
    – SNS
    Commented Nov 18, 2020 at 10:23
  • $collection = Mage::getModel('catalog/product')->getCollection(); $collection->addAttributeToFilter('name', array('like' => 'h%')); Commented Nov 18, 2020 at 10:30
  • i need every product list page
    – SNS
    Commented Nov 18, 2020 at 10:33
  • Stores > Configuration > Catalog > Catalog > Store Front > Product Listing Sort by Commented Nov 18, 2020 at 10:36
0
 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;
      }```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.