0

I am trying to filter products with price. But getting some issue with my requirement. Like in default magento price filter is working with range. When we need with fixed price filter.

1. $0.00 - $10.00
2. $100.00 - $200.00
3. $300.00 - $400.00

Above is how it comes in default magento. When i click on 2nd filter i can see url like ?price=2-10 and it is filtering products between $10 to $20.

Now in our case we have only three fixed product price in store. So we dont need range filter but instead should be with fixed price filter.

1. $10
2. $25
3. $45

and when i click on 2nd filter, url should be like ?price=25

Thanks,

4
  • for that you have to give range 0-25 then it will work otherwise you have to rewrite the layer/filter/price model to do your logic. Commented Jun 21, 2016 at 6:02
  • If i will give range 0-25 it will filter from $0 to $25. But i dont want range anymore.
    – Hardik
    Commented Jun 21, 2016 at 6:03
  • what you want to achieve here only product that have price 25? Commented Jun 21, 2016 at 6:04
  • Yes only products with price $25
    – Hardik
    Commented Jun 21, 2016 at 6:06

2 Answers 2

0

@Hardik If you can have filter like ?price=25-25 instead of ?price=25 then it will filter products having price 25.

4
  • Thanks Nalin, but i have already tried. And it if i am using ?price=25-25 it is filtering with price between 600,00 - 625,00
    – Hardik
    Commented Jun 21, 2016 at 6:06
  • @Hardik It's working for me, are you using any extension for it? Commented Jun 21, 2016 at 6:18
  • Yes i am using EcommerceTeam SLN using. But already tried in default fresh magento.
    – Hardik
    Commented Jun 21, 2016 at 6:25
  • So, you need to check whether this module overrides Mage_Catalog_Model_Layer_Filter_Price or not? If yes, then please look into methods getMaxPriceInt and getPriceRange logic Commented Jun 21, 2016 at 6:32
0

simply rewrite the model Mage/Catalog/Model/Layer/Filter/Price.php

in this apply function add this code

    public function apply(Zend_Controller_Request_Abstract $request, $filterBlock)
{

    $filter = $request->getParam($this->getRequestVar());
    if (!$filter) {
        return $this;
    }
     $select =  $this->getLayer()->getProductCollection();
                 $select->addAttributeToFilter('price', array('eq' => $filter));
  $state = $this->_createItem(
        $stateLabel, $filter
    )->setVar($this->_requestVar);
    /* @var $state Mage_Catalog_Model_Layer_Filter_Item */

    $this->getLayer()->getState()->addFilter($state);
    return $this;
}
11
  • This is working. But issue is. I can not see custom price filter is selected on left column.
    – Hardik
    Commented Jun 21, 2016 at 6:55
  • Also when i am trying with multiple filter, it is only working with the 1st one.
    – Hardik
    Commented Jun 21, 2016 at 6:59
  • then you have more customize on that because default magento selected filter in state Commented Jun 21, 2016 at 7:07
  • Do you have idea how i can add custom price filter list, that will work with above code?
    – Hardik
    Commented Jun 21, 2016 at 7:34
  • follow this tutorial techytalk.info/create-custom-layered-navigation-filter-magento/… at the end add this code in apply function Commented Jun 21, 2016 at 7:37

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.