Pregunta

I have installed a free price slider from magento marketplace. It works list pages properly but catelog search pages it only show the filter attribute label and doesn't show the attribute values. How can I overcome this problem Extension developer not reply yet. Need help. Extension is

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

it override 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; ?>
¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a magento.stackexchange
scroll top