0

This is the class I want to get preferenced : Amasty\Shopby\Block\Navigation\Top\Navigation

I've put some dump inside each files....only the test 3 is appearing when it shouldn't as ovverrided by the proference. Compilation is done. What am I missing there ?

This is the class content

class Navigation extends \Magento\LayeredNavigation\Block\Navigation
{
    const PRODUCT_LISTING_SEARCH_BLOCK = 'search.result';
    const PRODUCT_LISTING_TOOLBAR_BLOCK = 'product_list_toolbar';

    /**
     * @return \Magento\LayeredNavigation\Block\Navigation
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    protected function _beforeToHtml()
    {
        var_dump("test 3"); die();
        $productListingBlock = $this->getLayout()->getBlock(self::PRODUCT_LISTING_SEARCH_BLOCK);
        if ($productListingBlock) {
            $toolbarBlock = $this->getLayout()->getBlock(self::PRODUCT_LISTING_TOOLBAR_BLOCK);
            if ($toolbarBlock) {

                $toolbarBlock->setData('_current_grid_order', null);
                $toolbarBlock->setData('_current_grid_direction', null);

                $orders = $toolbarBlock->getAvailableOrders();
                unset($orders['position']);
                $orders['relevance'] = __('Relevance');
                $toolbarBlock->setAvailableOrders(
                    $orders
                )->setDefaultDirection(
                    'desc'
                )->setDefaultOrder(
                    'relevance'
                );
            }
        }

        return parent::_beforeToHtml();
    }
}

Now I want to make a preference on that class

<preference for = "Amasty\Shopby\Block\Navigation\Top\Navigation" type="Cpy\Category\Block\Navigation\Top\Navigation" />

And this is my custom class

<?php


namespace Cpy\Category\Block\Navigation\Top;


use Amasty\Shopby\Block\Navigation\Top\Navigation as AmastyNavigation;
use Magento\Catalog\Model\Layer\AvailabilityFlagInterface;
use Magento\Catalog\Model\Layer\FilterList;
use Magento\Catalog\Model\Layer\Resolver;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\View\Element\Template\Context;

/**
 * Class Navigation
 * @package Cpy\Category\Block\Navigation\Top
 */
class Navigation extends AmastyNavigation
{

    public function __construct(Context $context, Resolver $layerResolver, FilterList $filterList,
                                AvailabilityFlagInterface $visibilityFlag, array $data = [])
    {
        var_dump("test 1");
        die();
        parent::__construct($context, $layerResolver, $filterList, $visibilityFlag, $data);
    }


    protected function _beforeToHtml()
    {
        var_dump("test 2");
        die();

    }

}
1
  • what is the location of your di.xml? Aug 13, 2021 at 12:10

1 Answer 1

1
  1. confirm your di.xml file location is this one.

app\code\Vendor\Extension\etc\di.xml

  1. Add the following into your module.xml

    <sequence>
         <module name="Amasty_Shopby"/>  
    </sequence>
    
2
  • I didn't had Amasty_Shopby in the dependence, it mus be it. Actually, what i'm really intenting to do is to remove the relevance sort to get the same sort in the search process than in the listing. But looks like there is much more in stake here. I will continue digging. Thanks !
    – Claims
    Aug 13, 2021 at 12:27
  • If answer help please upvote and accept as solutions. so it will help other in community. Aug 13, 2021 at 12:29

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.