1

I have installed a free price slider from Magento marketplace. It works list pages properly but catalog search pages only show the filter attribute label and don't show the attribute values. How can I overcome this problem Extension developer has not replied yet. Need help. Extension is

https://marketplace.magento.com/prashant1990-priceslider.html

it overrides the

\Magento\LayeredNavigation\Block\Navigation\FilterRenderer

code is - block file FilterRenderer.php

namespace Prashant\Priceslider\Block;

use Magento\Catalog\Model\Layer\Filter\FilterInterface;

class FilterRenderer extends \Magento\LayeredNavigation\Block\Navigation\FilterRenderer {

    /**
     * @param FilterInterface $filter
     * @return string
     */
    public function render(FilterInterface $filter) {
        $this->assign('filterItems', $filter->getItems());
        $this->assign('filter', $filter);
        $html = $this->_toHtml();
        $this->assign('filterItems', []);
        return $html;
    }

    public function getPriceRange($filter) {
        $filterprice = array('min' => 0, 'max' => 0);
        $priceArr = $filter->getResource()->loadPrices(10000000000);
        $filterprice['min'] = reset($priceArr);
        $filterprice['max'] = end($priceArr);
        return $filterprice;
    }

    public function getFilterUrl($filter) {
        $query = ['price' => ''];
        return $this->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true, '_query' => $query]);
    }

}

Filter phtml - filter.phtml

<?php
/**
 * Template for filter items block
 *
 * @var $block \Magento\LayeredNavigation\Block\Navigation\FilterRenderer
 */
?>
<?php if ($filter instanceof Magento\CatalogSearch\Model\Layer\Filter\Price): ?>
    <?php $range = $this->getPriceRange($filter); ?>
    <?php $url = $this->getFilterUrl($filter); ?>  
    <script>
        var price_url = "<?= $url; ?>";
        require([
            'jquery',
            "jquery/ui",
            'domReady!'
        ], function ($) {
    //     `use strict`;
            console.log("Price Slider..!");
    //require(["jquery" , "jquery/jquery-ui"], function($){
            // ...
            $("div#price-slider").slider({
                range: true,
                min: <?= $range['min'] ?>,
                max: <?= $range['max'] ?>,
                values: [<?= $range['min'] ?>, <?= $range['max'] ?>],
                slide: function (event, ui) {
                    $("#amount").val("$" + ui.values[ 0 ] + " - $" + ui.values[ 1 ]);
                },
                change: function (event, ui) {
                    window.location.href = price_url + ui.values[0] + "-" + ui.values[1];
                }
            });
            $("#amount").val("$" + $("#price-slider").slider("values", 0) +
                    " - $" + $("#price-slider").slider("values", 1));
        });
    </script>
    <?php ?>      
    <p>
        <label for="amount">Price range:</label>
        <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
    </p>
    <div id="price-slider"></div>

<?php else: ?>
    <div class="radio-custom">
        <?php foreach ($filterItems as $filterItem): ?>
            <div class="radio-col">
                <?php if ($filterItem->getCount() > 0): ?>
                    <a href="<?php echo $block->escapeUrl($filterItem->getUrl()) ?>">
                        <input type="radio" name="pro-size" id="<?php /* @escapeNotVerified */ echo $filterItem->getId() ?>">
                        <label for="<?php /* @escapeNotVerified */ echo $filterItem->getLabel() ?>"> <?php /* @escapeNotVerified */ echo $filterItem->getLabel() ?></label>
                    </a>
                <?php else: ?>
                    <label for="<?php /* @escapeNotVerified */ echo $filterItem->getLabel() ?>"> <?php /* @escapeNotVerified */ echo $filterItem->getLabel() ?></label>
                <?php endif; ?>
            </div>
        <?php endforeach ?>
    </div>
<?php endif; ?>

1 Answer 1

1

Create Prashant/Priceslider/view/frontend/layout/catalogsearch_result_index.xml


<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="catalogsearch.navigation.renderer">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Prashant_Priceslider::filter.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>

Clear cache.

8
  • it didn't work.I think it blocks render functionality :(
    – Lasantha
    Jun 3, 2018 at 8:33
  • @Lasantha what is your module location?
    – Sohel Rana
    Jun 3, 2018 at 9:03
  • I have tested M2.4, working fine for me.
    – Sohel Rana
    Jun 3, 2018 at 9:03
  • is it only working with CE ? my version is 2.1.7 EE . normal category pages are working fine but problem is search result page.
    – Lasantha
    Jun 3, 2018 at 9:06
  • Yes, when you added this view/frontend/layout/catalogsearch_result_index.xml. its working for search as well.
    – Sohel Rana
    Jun 3, 2018 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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