3

i'm struggling on that simple point. How can I order my catalog search by categories ?

i want to order my catalog search result like this :

Categorie 1 / Category 2 / Category 3

enter image description here

I tried changing order in back and in code, but it doesn't sort by categories... I've override the SearchResult file like this :

    public function setListOrders()
{
    $category = $this->catalogLayer->getCurrentCategory();
    /* @var $category \Magento\Catalog\Model\Category */
    $category->setAvailableSortBy("id");
    $availableOrders = $category->getAvailableSortByOptions();
    unset($availableOrders['position']);
    $availableOrders['relevance'] = __('Relevance');
    $this->getListBlock()->
        setAvailableOrders(
        $availableOrders
    )->setDefaultDirection(
        'asc'
    )->setDefaultSortBy(
        'category'
    );


    return $this;
}
  • where are you want this? – Amit Bera Mar 20 at 14:19
  • When a user submit a research, he goes to the result page. I want the result page in that order. – Morgan Tartreau Mar 20 at 14:21
0

For those of you who wants to know, this is what I ended up with :

  1. Create a custom attribute for each products (the products with the value 0 will be displayed first, the value 10 will be displayed after etc).
  2. Allow the attribute to be available in the search
  3. In the Configuration of Catalog, sort the product by the created attribute
  4. In the categorie section, select the order by the created attribute.

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.