Skip to content

Mageto2:How to Sort products by regular price?

I want to sort products by regular not final price or special price.
any idea how to do that
Here you can see special price and regualr price.
enter image description here

and this is my code.

VendormoduleModelVisualMerchandiserSortingOriginalPriceTop.php

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

namespace VendormoduleModelVisualMerchandiserSorting;

use MagentoCatalogModelResourceModelProductCollection;
use MagentoFrameworkDataCollection as CollectionAlias;
use MagentoVisualMerchandiserModelSortingSortAbstract;
use MagentoVisualMerchandiserModelSortingSortInterface;
use Zend_Db_Select;

class OriginalPriceTop extends SortAbstract implements SortInterface
{
    /**
     * @param Collection $collection
     * @return Collection
     */
    public function sort(
        Collection $collection
    ): Collection {
        $this->addPriceData($collection);
        $collection->getSelect()
            ->distinct('entity_id')
            ->reset(Zend_Db_Select::ORDER)
            ->order('price ' . CollectionAlias::SORT_ORDER_DESC);

        return $collection;
    }

    /**
     * @return string
     */
    public function getLabel(): string
    {
        return __("Original Price Top");
    }
}

Is this code good or its needs to change?