How get values of choosen "Sort by" options. enter image description here

  • What kind of values? – Sumit Sep 19 '19 at 11:44
  • For example, i need get "Product Name" string, its value of SortBy dropdown – Mikel Sep 19 '19 at 11:45

You can get current sort order using method getOrder() from class Magento\Catalog\Model\Product\ProductList\Toolbar

Usage example:

class YourClassName
    protected $productListToolbar;

    // inject the Toolbar model here
    public function __construct(Magento\Catalog\Model\Product\ProductList\Toolbar $productListToolbar)
        $this->productListToolbar = $productListToolbar;

    public function execute()
        // use the injected Toolbar model here
        // to get current sort by
        $productOrder = $this->productListToolbar->getOrder();
        // to get current sort direction
        $productOrderDirection = $this->productListToolbar->getDirection();

Other available methods are: getMode(), getLimit(), getCurrentPage().

| improve this answer | |
  • Thank you, its work fine. – Mikel Sep 19 '19 at 12:13
  • so how can i get value Sort By "Relevance" in search product by tag page? – Mikel Feb 19 at 17:31

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.