I want to sort product collection by Custom Price attribute.
here is my code
Here is my code, what is the problem here, i dont understand?
<?php
namespace Vendor\Module\Model\VisualMerchandiser\Sorting;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\VisualMerchandiser\Model\Sorting\SortAbstract;
use Magento\VisualMerchandiser\Model\Sorting\SortInterface;
class CustomPriceBottom extends SortAbstract implements SortInterface
{
/**
* @param Collection $collection
* @return Collection
*/
public function sort(
Collection $collection
): Collection {
$collection->addAttributeToSelect('*')
->setOrder('custom_price', 'DESC');
// $collection->getSelect()
// ->distinct('entity_id')
// ->reset(Zend_Db_Select::ORDER)
// ->order('custom_price ' . CollectionAlias::SORT_ORDER_ASC);
return $collection;
}
/**
* @return string
*/
public function getLabel(): string
{
return __("Custom Price Bottom");
}
}